Copy link to clipboard
Copied
How to create a dynamic stamp with an incremental number every time I stamp in the PDF. This will be used by only one person and installed on a single computer. Thanks for your help in advance.
Copy link to clipboard
Copied
You would need to set up a persistent global variable that keeps track of how many times the stamp was applied and increments its value after each time.
Copy link to clipboard
Copied
Take a look here for some more information about this subject: Auto Increment Exhibit Stamps - saving metadata to Stamp file (JavaScript)
Copy link to clipboard
Copied
I just made a github of an auto-incrementing stamp set that should work:
GitHub - q335r49/AcrobatIncrementStamp: Auto-incrementing stamp for Acrobat
Copy link to clipboard
Copied
That works perfect if I use always the sane pdf file.
Is it possible that the stamp keeps in mind the last Number and when I open another pdf file it counts the "reminded" number and increments 1.
Thanks
Gerhard
Copy link to clipboard
Copied
Use a global variable for the number.
Copy link to clipboard
Copied
I can imagine how it should work. Starting with 001 it writes the 001 in a global variable and takes than the global"stored variable" to increase to 002 and so on, but I can't code it. I think a have too less basics in Java.. I am 72 years old and try always to learn something new. I can live with the solutution of linangl. Iam using it uncommercial as (meine eigene fortlaufende Nummer für gescannte Arztrechnungen und Rezepte für Beihilfe). Thats not important and can give the stamp by hand, but the idea is it should work automatic.
Gruß Gerhard
Copy link to clipboard
Copied
Unfortunately the "Global" object is protected, making it essentially document level unless your stamp script it executed from the privileged context, which I'm sure it isn't.
Another alternative for global-like storage is to put the increment value into an already defined application level variable, such as the color object. This technique does not provide persistence across sesssions, but it does provide access across documents.
if (event.source && event.source.forReal && event.source.stampName == "XXX")
{
if(typeof(color.increment) == "undefined")
color.increment = 1;
even.value = color.increment++;
}
If you need persistence, then you'll to create a folder level script with a trusted function to maintain the increment value.
Copy link to clipboard
Copied
You will need a global variable, set to be persistent, to do that.
Copy link to clipboard
Copied
Does this still work on the current Acrobat Document Cloud (DC) version? This post worked perfectly two years ago. However, I just upgraded to Acrobat DC and it no longer works. Either this method does not work for Acrobat DC or I am simply failing to implement it like I did two years ago.
In any case, I'm grateful to the community for giving me those two years of nearly effortless numbering of bubbled design drawings.
Copy link to clipboard
Copied
What did you use as a storage location for the increment value? Storage location is almost certainly the source of the issue. Were any errors reported in the console widow?
The security preferences for the global object are automatically set to restrict access when Acrobat is installed (updated). Check this settings in the JavaScript preferences if you are using it.
The color object is generic, but could also have been setup to be restricted. Security is getting tighter all the time.
Copy link to clipboard
Copied
A global variable works, but I think a better option is to store the number value in "doc.info", so that last increment is persistent with the document. Meaning the stamp will always start off at the last increment, even when Acrobat is closed and reopened. It also makes it easy for you to set/change the increment by simply editing the values on the "Custom" tab of the Document Properties dialog.
The stamp script should be something like this:
event.value = ++event.source.source.info.myInc;
Copy link to clipboard
Copied
That seems to almost work. My problem is,that the stamp increases its value not only when stamping, but every time I even just hover the mouse over the stamp tool. Any way to prevent that? I need to only increment when actually stamping.
Copy link to clipboard
Copied
What script does you use? Where does you use the script?
Copy link to clipboard
Copied
I use the script of Thom Parker as given in the post I replied to. I use it in a form field inside a dynamic stamp. Every time I hover the mouse over the stamp (as in screenshot below), the counter increases. The workaround is to open the stamps palette and select the stamp from there: This avoids parasitic counter increases. I use Adobe Acrobat Pro DC Version 2020.013.20074.
Copy link to clipboard
Copied
OK
Copy link to clipboard
Copied
Add this line before the current code instead:
if (event.source && event.source.forReal && event.source.stampName == "XXX")
Replace XXX with the stamp's AP value, which you can find by applying it to the page, selecting it with the mouse and then running this code from the JS Console:
this.selectedAnnots[0].AP
Copy link to clipboard
Copied
Brilliant! Works like a charm.
Copy link to clipboard
Copied
I'd like to share one more improvement: Using source.info does not work in Adobe Reader (Reader cannot write document properties). This is avoided by simply counting the stamps that are already in the document like this:
stampCount = 0;
annots = event.source.source.getAnnots();
if (annots == null) {
event.value = 1;
} else {
for (i=0; i<annots.length; i++) {
if (annots[i].type == 'Stamp' && annots[i].AP == '<place correct .AP string here>')
stampCount++;
};
event.value = stampCount + 1;
}
Copy link to clipboard
Copied
It sounds great! It is exactly what i want to annoate the drawing. But i am not yet having idea to write the java myself.
Copy link to clipboard
Copied
Do you want to learn JavaScript? or hire someone else to do it for you?
Copy link to clipboard
Copied
Hello Adrian5CDA,
i search since weeks for a soulution and now i see you have it. Can you share your Dynamic Stamp with Auto Inc?
Greats
Frank
Copy link to clipboard
Copied
Please note that the code provided in my previous post is all the code that is needed for an auto-increment stamp.
You'll also find everything you ever wanted to know about stamps here:
https://www.pdfscripting.com/public/All_About_PDF_Stamps.cfm