Bates Numbering for Sequencing Sets
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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:
"textSize" is the property for the text size.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi Thom,
This is still rather confusing. All pages will be 8.5x11 inches, vertically positioned.
Copy link to clipboard
Copied
Copy the code I provided to the console window and run it as a test to add bates numbers to a single document.
The only thing you need to add is the rectangle coordinates. Use the method I outlined above.
Watch this video to learn about using the console window.
https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
When you run @Thom Parker 's script for the placement below, it might return numbers with large numbers of decimal places. These would be the exact coordinates of TestField but if you round them to 2 decimal places for simplicity it should be close enough (the numbers are points on the page, there are 72 points per inch). You can round them manually by removing the excess deciminal places, or run the following modified script in the console:
var rc=this.getField("TestField").rect;
[Math.round(rc[0]*100)/100,
Math.round(rc[1]*100)/100,
Math.round(rc[2]*100)/100,
Math.round(rc[3]*100)/100];

