How to Delete Only Empty PDF Comments Using JavaScript
Question details
The user wants to remove only empty annotations (like sticky notes, rectangles, and circles) from a PDF without deleting comments that contain text.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Cleaning up a PDF document that has numerous annotations, some of which are completely blank, without ruining the existing review notes.
- Observed behavior
- Standard deletion methods might remove all annotations at once. The goal state is to selectively delete only those missing text contents.
Before running any JavaScript on your PDF, make sure to save a backup copy of your document to prevent accidental loss of important annotations.
Use JavaScript to Delete Empty Annotations
Run a simple JavaScript code snippet to iterate through all annotations and delete only those with empty text content.
You can use the JavaScript console in advanced PDF editors to automate the deletion of blank comments. This method iterates through every annotation in the document and checks its content property before destroying it.
Open your PDF document in a PDF editor that supports JavaScript execution (like Adobe Acrobat Pro). Locate and open the JavaScript Debugger or Console from the tools menu.
Type or paste the following script into the console: var annots = this.getAnnots(); if (annots != null) { for (var i = 0; i < annots.length; i++) { if (annots[i].contents == '') annots[i].destroy(); } }
Run the script. The code will scan through all annotations in the document, such as sticky notes or shapes, and destroy only the ones where the text is completely blank.

Manage and Delete PDF Comments Easily with WPS Office
While JavaScript is a powerful way to manage files, WPS Office provides an intuitive Comment Pane that lets you visually review, filter, and delete blank annotations with just a few clicks, requiring no coding skills.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document containing the blank annotations.
- 2. Access the Comment Pane: Navigate to the 'Comment' tab at the top of the screen and click on the 'Comment Pane' icon to display a list of all document annotations.
- 3. Identify Blank Comments: Scroll through the comment list to quickly spot annotations (like rectangles or empty sticky notes) that have no text contents.
- 4. Delete Unwanted Annotations: Right-click the empty comments in the pane and select 'Delete' or simply press the Delete key to remove them while preserving your actual text notes.

Frequently Asked Questions
Can I delete all PDF comments at once instead of just the empty ones?
Yes, most PDF editors have a built-in option to 'Delete All Comments' in their Comment or Review tabs. In JavaScript, you can simply remove the IF condition and run annots[i].destroy(); directly inside the loop.
Why do empty annotations appear in my PDF in the first place?
Empty annotations often occur when users accidentally click the document with a markup tool selected, such as a sticky note or shape tool, without typing any text afterward. Over time, these can clutter the document.
Does this JavaScript code work in all PDF readers?
No, JavaScript execution for PDFs is primarily supported by advanced editors like Adobe Acrobat Pro. Standard PDF viewers or web browsers may not execute these scripts for security reasons.
Will this script delete my highlighted text if there is no pop-up note attached?
If a highlight annotation does not contain a pop-up text note, its 'contents' property might be evaluated as empty, causing it to be deleted by this script. You may need to add a check for the annotation type (e.g., if (annots[i].type != 'Highlight')) to preserve them.




