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

Javascript Counter

New Here ,
Jul 04, 2017 Jul 04, 2017

Hello I am new to Javascript and specifically Javascript + Adobe. At my jobs I use a lot of stamps in my pdf. I want to create a script, button, or tool that when clicked will count all the specific stamps in the document. Is there a way to do this or is there an easier way to go about counting my things on the document. Thank you

TOPICS
Acrobat SDK and JavaScript
987
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 ,
Jul 04, 2017 Jul 04, 2017

What do you mean when you say that you want to count "specific" stamps? Do you mean only stamps of a certain kind, not all of them?

It's possible either way, but the former is more complicated as you would need to first find out the unique identifier of that stamp type and then use it in your code.

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 ,
Jul 04, 2017 Jul 04, 2017

So I have my document and as I am going through every so often I am stamping, but I  am using didn't stamps through out the process and at the end I want to hit a button or run a script and display text that would show the quantity of that certain stamp. Thank you for replaying

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 ,
Jul 04, 2017 Jul 04, 2017

You can do it using this code. You just need to select a stamp of the type that you want to count before running it:

(function () {

  

    if (this.selectedAnnots==null || this.selectedAnnots.length==0) {

        app.alert("You must select a stamp first.");

        return;

    }

    var selectedAnnot = this.selectedAnnots[0];

    this.syncAnnotScan();

    var annots = this.getAnnots();

    if (annots==null || annots.length==0) {

        app.alert("There are no comments in this file.");

        return;

    }

    var counter = 0;

    for (var i in annots) {

        if (annots.type=="Stamp" && annots.AP==selectedAnnot.AP) {

            counter++;

        }

    }

    app.alert("There are " + counter + " stamps of this type in this file.",3);

})();

The code can be executed from the Console, or even from an Action or a menu-item (the latter will require placing it in a folder-level script, though).

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 ,
Sep 17, 2024 Sep 17, 2024

A bit late to this
I've never used Javascript before, how do I select the stamp I want counted?

Everything I do just gives me the message that I need to select a stamp... Can't figure it out lol ☹️

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 ,
Sep 17, 2024 Sep 17, 2024
LATEST

Make sure the cursor is the "Hand" cursor. Place the cursor over a stamp and click on the left mouse button. You will know the stamp is selected because a highlighted border will appear around it. 

Then run the code without deselecting the stamp. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jul 04, 2017 Jul 04, 2017

Right on man. Thank you so much for your help! I manually do this task with projects all day long and it can become a pain in the butt day after day.

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