Skip to main content
beatag10657794
Participating Frequently
Mar 21, 2019 8:37 AM UTC
Answered

Comment count - JavaScript

Hello,

I'm not experienced in Adobe JavaScript but recently I've faced a problem: is there a way to automatically count all types of comments in one document opened with Adobe Acrobat Reader Pro? ​I even found a JavaScript on the internet. Unfortunately it counts only one type of the comments: ​​

 

var counter = 0;
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++) {
  
if (annots[i].type == "Text") {
  counter
++;
  
}
}
app
.alert("Total comments count: " + counter);

 

Thank You in advance for help.

try67
try67Correct answer
Community Expert
Mar 21, 2019 2:18 PM UTC

Is there any script that could run this solution? And how?


The easiest solution is to print out the number of comments to the console, and at the end of the process copy it from there.

You can use this code for that:

this.syncAnnotScan();

var annots = this.getAnnots();

console.println(this.documentFileName + ": " + ((annots==null) ? 0 : annots.length));

13 replies

JR Boulay
Community Expert
Community Expert
Aug 28, 2025 10:56 PM UTC

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
Mar 21, 2019 9:21 AM UTC

Sure, it's possible. Use this code:

this.syncAnnotScan();

var annots = this.getAnnots();

app.alert("Total comments count: " + (annots==null) ? 0 : annots.length);

Translate
beatag10657794
Participating Frequently
Mar 21, 2019 11:36 AM UTC

Hi try67, I'm a beginner in JavaScript, could You please give me a hint how to insert this code. If I do this my way Adobe Reader shows a Warning - picture below. I paste your code as it is with no additions in the "Document JavaScript" window.

Translate
try67
Community Expert
Community Expert
Mar 21, 2019 11:49 AM UTC

Change the last line to:

app.alert("Total comments count: " + ((annots==null) ? 0 : annots.length));

Where to place it depends on when you want to run it...

Translate