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

dynamic stamp with an incremental number

New Here ,
Mar 21, 2016 Mar 21, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

6.8K

Likes

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 22, 2016 Mar 22, 2016

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.

Likes

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 22, 2016 Mar 22, 2016

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)

Likes

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 Beginner ,
Dec 21, 2017 Dec 21, 2017

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

Likes

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 ,
Jun 13, 2022 Jun 13, 2022

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

Likes

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Use a global variable for the number.

Likes

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 ,
Jun 13, 2022 Jun 13, 2022

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

Likes

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

LATEST

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. 

 

 

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

Likes

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 ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

You will need a global variable, set to be persistent, to do that.

Likes

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 ,
Dec 21, 2017 Dec 21, 2017

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;

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

Likes

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 ,
Jan 21, 2021 Jan 21, 2021

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.

Likes

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 ,
Jan 21, 2021 Jan 21, 2021

Copy link to clipboard

Copied

What script does you use? Where does you use the script?

Likes

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 ,
Jan 22, 2021 Jan 22, 2021

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.

 

Adrian5CDA_0-1611303547233.png

 

Likes

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

OK

Likes

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 ,
Jan 22, 2021 Jan 22, 2021

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

Likes

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Brilliant! Works like a charm.

Likes

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 ,
Jan 25, 2021 Jan 25, 2021

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

Likes

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 ,
Sep 10, 2021 Sep 10, 2021

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.

Likes

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 ,
Sep 11, 2021 Sep 11, 2021

Copy link to clipboard

Copied

Do you want to learn JavaScript? or hire someone else to do it for you?

 

 

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

Likes

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