Delete Acrobat Comments by Page and Author with JavaScript
Question details
Delete PDF annotations authored by JonDoe only on the page containing the clicked button.

- 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.
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.
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.
In Acrobat, open Prepare a Form, select the button, and open its Properties dialog.
On the Actions tab, choose Mouse Up as the trigger and Run a JavaScript as the action, then select Add.
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(); } }
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.

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.

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.




