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

Apply Dynamic Stamp to all PDF pages at one click

Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Hello Experts,

 

I'm working on a Dynamic Stamp, which has a automatic page numbering function, (ex: Page 1 of 3)

i want to apply this stamp on all pages with the same input data because it also has a One text field. but the tricky part is that when it's applied to all pdf pages at one click. it should update the page numbers. 

 

So, if someone can help me to create a script for applying dynamic stamp into all pdf with page numbering feature in one single click, I would greatly appreciate it.

 

 

this script i'm using for Updating Page numbers in Stamp.

event.value = "PAGE " + (event.source.source.pageNum + 1) + " OF " + event.source.source.numPages;

 

Thank You

TOPICS
JavaScript , PDF , PDF forms

Views

2.5K

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 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

You don't need stamps or scripts to add page numbers:

 

Capture_2309011539.png

Votes

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 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

How are you applying the stamp to all pages, exactly?

Votes

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
Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

EDITED

Thanks for your response,

I want to apply a stamp to all the pages of a document. When I apply the stamp, a data entry box should appear once to prompt the user to enter data and apply stamp to all pages in a document automatically at one click.

BUT keep updating "seiten" field for page numbering according to the page number of a document.

The stamp consists of two text fields:

- The first field is for entering data in a box.
- The second field, labeled 'Seiten,' should automatically display the current page number and keep track of the total number of pages in the document.

if ((event.source.forReal) && (event.source.stampName == "#Abrechnung")) {
    var cAsk = "Please enter Anlagen-Nr";
    var cTitle = "Abrechnung";
    var cMsg = app.response(cAsk, cTitle);
    event.value = cMsg;
}

 

Votes

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 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

The only way I can see that working is if you apply the stamp using a script, after the user applied it to the first page. The script will have to be adjusted to populate the page number automatically instead of using user input.

Votes

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
Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

btw i'm using this script for updating page number field automatically, which works fine.

event.value = "PAGE " + (event.source.source.pageNum + 1) + " OF " + event.source.source.numPages;

 

Votes

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 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Yes, when you apply it manually, but it won't work when you use a script.

Votes

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
Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Hmm, okay lets leave auto applying function in all pages.

 

If Manual way, is it possible to modify this script, like the prompt box will only appear the first time, and the entered data will be reused if user apply stamp again but of course page number should update.

if ((event.source.forReal) && (event.source.stampName == "#Abrechnung")) {
    var cAsk = "Please enter Anlagen-Nr";
    var cTitle = "Abrechnung";
    var cMsg = app.response(cAsk, cTitle);
    event.value = cMsg;
}

 

Votes

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 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

LATEST

Then only way to automatically apply the stamp to all pages in one go is to use a folder level script. Or an easier way to do the same thing is to create a "Command", which you'll find in the "Action Wizard" tools.

 

Since the command or folder level script is necessary, use the code in the command or folder level script to display the response dialog and collect the data. Then loop through  the pages and apply the stamp to each page. 

The data display on the stamp is setup in the loop.  The stamp script just needs to use this data to fill in the stamp fields. 

 

Here's an example stamp script:

Note that data is transfered through document variables on the document being stamped. 

 

 

 

if ((event.source.forReal) && (event.source.stampName == "#Abrechnung")) {
    
    event.value = event.source.source.strMessage;
    this.getField("PageNumber") = event.source.source.strPageNum
}

 

 

 

 

Here's an example automation script:

 

 

 

var rectStamp = [...Location where stamp is placed on each page...];

var cAsk = "Please enter Anlagen-Nr";
var cTitle = "Abrechnung";
this.strMessage = app.response(cAsk, cTitle);

if(this.strMessage)
{
   for(var nPg = 0;nPg<this.numPages;nPg++)
   {
      this.strPageNum = "PAGE " + (nPg + 1).toString() + " OF " + this.numPages;
      this.addAnnot({type:"Stamp", AP:"#Abrechnung", page:nPg, rect:rectStamp });
   }
}

 

 

 

 

It is also possible to create a stamp script that only displays the response box if data is not already defined. Using document variables is a good way to do that. 

Like this:

  if(!event.source.source.strMesssage)

  {  ... Display response dialog and set strMessage}

  event.value = event.source.source.strMesssage;

 

Find out more about dynamic stamps here:

https://www.pdfscripting.com/public/All_About_PDF_Stamps.cfm

 

 

 

 

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

Votes

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