Skip to main content
beatag10657794
Participating Frequently
March 21, 2019
Answered

Comment count - JavaScript

  • March 21, 2019
  • 2 replies
  • 3077 views

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.

Correct answer try67

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));

2 replies

JR Boulay
Community Expert
Community Expert
August 28, 2025

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
March 21, 2019

Sure, it's possible. Use this code:

this.syncAnnotScan();

var annots = this.getAnnots();

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

beatag10657794
Participating Frequently
March 21, 2019

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.

try67
Community Expert
Community Expert
March 21, 2019

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...