Javascript Counter
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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 ☹️
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.

