Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Comment count - JavaScript

New Here ,
Mar 21, 2019 Mar 21, 2019

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.

TOPICS
Acrobat SDK and JavaScript , Windows
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 21, 2019 Mar 21, 2019

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

Translate
Community Expert ,
Mar 21, 2019 Mar 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2019 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2019 Mar 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2019 Mar 21, 2019

Great, this code works. Do You think it is possible to create a script that counts the comments in many pdf's without opening them and exports number of comments of each file to a text file? It would save a time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2019 Mar 21, 2019

Yes, that's certainly possible, using Acrobat Pro.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2019 Mar 21, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2019 Mar 21, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2019 Mar 27, 2019

Hello again,

try67​ Your code works! But there is something wrong with it - I have opened 3 pdfs with different number of comments (eg. 9, 20 and 21). The console shows the correct number only for 2 of the documents, it always shows bigger by one number in one of the documents (eg. 9, 20 and 22). This action repeats every time, no matter what type of comments I put to the document.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 27, 2019 Mar 27, 2019

Some comments are composed of two annotations. For example, the "Add Note To Replace Text" comment is a Strikethrough and a Caret. So in the final count it will count as two comments, not one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2019 Mar 27, 2019
LATEST

OK, thank You very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines