Skip to main content
tykez123
Participant
July 4, 2017
Question

Javascript Counter

  • July 4, 2017
  • 3 replies
  • 1083 views

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

This topic has been closed for replies.

3 replies

tykez123
tykez123Author
Participant
July 4, 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.

tykez123
tykez123Author
Participant
July 4, 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

try67
Community Expert
Community Expert
July 4, 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).

Participant
September 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 ☹

try67
Community Expert
Community Expert
July 4, 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.