PDF Editing Issues

Delete Acrobat Comments by Page and Author with JavaScript

Steve KSteve K Nov 19, 2026 868 views

Question details

Delete PDF annotations authored by JonDoe only on the page containing the clicked button.

Delete Acrobat Comments by Page and Author with JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF button runs an Acrobat JavaScript action to remove a specific author's comments from its page.
Observed behavior
The annotation search needs to be restricted to the button's page and filtered by author.
Before you start

Open the PDF in Acrobat and confirm that it permits commenting and form editing. Check that the comments' author is spelled exactly JonDoe and that the button is on the page you want to target.

Solution 1Recommended

Filter Acrobat annotations by the button's page and author

Use the clicked button's page number to limit the annotation search, then delete only comments whose author matches JonDoe.

The author comparison is case-sensitive. This example assumes the button field is placed on a single page.

1
Open the button properties

In Acrobat, open Prepare a Form, select the button, and open its Properties dialog.

2
Add a JavaScript action

On the Actions tab, choose Mouse Up as the trigger and Run a JavaScript as the action, then select Add.

3
Enter the filter script

In the JavaScript editor, enter: var annots = this.getAnnots({nPage: event.target.page}) || []; for (var i = annots.length - 1; i >= 0; i--) { if (annots[i].author == "JonDoe") { annots[i].destroy(); } }

4
Test the button

Close the properties dialog, exit form editing, and click the button. Check the Comments panel to confirm that JonDoe's comments on that page were removed and other comments remain.

Filter Acrobat annotations by the button's page and author
Deletion permissions: PDF security settings, comment permissions, or restrictions on a signed document can prevent annotations from being deleted.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface and compatibility with common Microsoft Office formats for an easier move between applications. Use its PDF tools to review documents, but use Acrobat for this Acrobat-specific JavaScript action.

Open and review PDF comments in a familiar workspaceCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFree, lightweight suite for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

How does the script identify the button's page?

In the button's JavaScript action, event.target.page supplies its page number to this.getAnnots({nPage: event.target.page}).

Will this delete comments by other authors?

No. The script calls destroy() only when the annotation's author property exactly matches "JonDoe".

What happens if there are no annotations on the page?

The expression this.getAnnots({nPage: event.target.page}) || [] supplies an empty array if no annotations are returned, so the loop has nothing to delete.

Why might a matching comment remain after I click the button?

Check the author's exact spelling and capitalization in the comment properties. Also check whether the PDF's security settings or permissions allow comment deletion.