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

Comment count - JavaScript

New Here ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

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

Views

1.8K

Translate

Translate

Report

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

Votes

Translate

Translate
Community Expert ,
Mar 21, 2019 Mar 21, 2019

Copy link to clipboard

Copied

Sure, it's possible. Use this code:

this.syncAnnotScan();

var annots = this.getAnnots();

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

OK, thank You very much!

Votes

Translate

Translate

Report

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