Skip to main content
Participant
February 21, 2025
Question

Bates Numbering for Sequencing Sets

  • February 21, 2025
  • 1 reply
  • 626 views

I am trying to create an Adobe Acrobat Action that sequentially numbers pages in a pdf. The pdf will have sets that will have repeating numbers 6 times. Once the sixth page has been reached, the numbering will move onto the next number in the sequence. For example, 1, 1, 1, 1, 1, 1 and 2, 2, 2, 2, 2, 2, and so forth. This will repeat until the end of the pdf. This PDF is around 13,000 pages. Can anyone assist me with the script needed to complete this action?

1 reply

Thom Parker
Community Expert
Community Expert
February 21, 2025

An easy way to add new text to a PDF is to use a text field.  Use the doc.addField() function

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#addfield

 

var nCnt = 0;

var nBatesNum = 1;

var rectPlacment = ... Calculate placement ...;

for(var nPg = 0;nPg<this.numPages;n++){

   var oFld = this.addField("BatesNum" + nBatesNum  , "text",  nPg, rectPlacment);

   oFld.value = nBatesNum;

   if(++nCnt >=6){

          nCnt = 0;

          nBatesNum++;

   }

}

this.flattenPages();

 

Determining the placment of the number is up to you. There are also some text field properties that will need to be set, and possibly some text formatting. Up to you. 

After the script is finished you should flatten the PDF. 

 

If you want to see some examples of more sophisticated Bates numbers scripts, then see these links;

There is a free one here (the Stamp and Number Document):

https://acrobatusers.com/actions-exchange/ 

This one is a hopped up version:

https://www.pdfscripting.com/public/File-Name-Stamper-Action-Description.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
February 22, 2025

Hello Thom,

 

Thank you for your assistance! I want these numbers to be placed .1875 inches from the top and .1875 inches from the left. I'd like these to be at 11pt font but the font itself is negligble. I read the OpenSource link but I was still confused. I am not familiar with Javascript's syntax so keeping up with the logic is difficult, Could you provide me with a new script with these parameters inputted. Thank you again.

Thom Parker
Community Expert
Community Expert
February 22, 2025

A simple way to get the page coordinates for placing the field is to place one manually, the get the coordinates from it by running this code in the console.

 

this.getField("TestField").rect

 

Then in the code the rect looks something like this:

 var rectPlacment = [1,2,3,4];

 

Please read this article:

https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm

 

Also look at this one:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

If the documents you are processing are all the same, then the placement rectangle will be the same, but if the pages are different sizes you'll need to write some code to find the correct coordinates. Everything you need is in the articles. 

 

Find a list of field properties here:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#field-properties

 

"textSize" is the property for the text size. 

 

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