Skip to main content
Participating Frequently
March 11, 2024
Question

BatesNumbering

  • March 11, 2024
  • 2 replies
  • 505 views

PDDocAddBatesNumbering and PDDocRemoveBatesNumbering have been deprecated, but is there a replacement?

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
May 21, 2024
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
May 21, 2024

The deprecation of PDDocAddBatesNumbering and PDDocRemoveBatesNumbering functions in Adobe Acrobat's SDK suggests that Adobe might have introduced new methods or APIs for handling Bates numbering in PDFs. However, as of my last update, there hasn't been an official replacement directly within the Adobe Acrobat SDK documentation.

For handling Bates numbering in PDFs, there are a few alternative approaches you can consider:

Alternative Approaches

  1. JavaScript for Acrobat: Adobe Acrobat allows for extensive scripting using JavaScript. You can use JavaScript to add Bates numbering to your PDFs. This method can be automated through the Acrobat JavaScript Console or integrated into a larger workflow.

  2. Adobe PDF Services API: Adobe provides cloud-based services that can be used to manipulate PDFs, including adding Bates numbering. This approach involves using Adobe's Document Services API to handle PDF manipulations.

  3. Third-party Libraries: There are several third-party libraries available for PDF manipulation that support Bates numbering. Libraries like iText, PDFBox, and others might offer the functionality you need.

Using JavaScript for Acrobat

Here is an example of how you can use JavaScript to add Bates numbering to a PDF:

  1. Open the PDF in Adobe Acrobat.
  2. Open the JavaScript Console (Ctrl + J or Cmd + J on macOS).
  3. Run the following script to add Bates numbering:

 

 

var batesNum = 1;
var totalPages = this.numPages;

for (var i = 0; i < totalPages; i++) {
    this.addWatermarkFromText({
        cText: "Bates Number: " + batesNum,
        nTextAlign: app.constants.align.right,
        nVertAlign: app.constants.align.bottom,
        nHorizAlign: app.constants.align.right,
        nFontSize: 10,
        aColor: color.black,
        nRotation: 0,
        bOnTop: true,
        nOpacity: 1,
        nStart: i,
        nEnd: i
    });
    batesNum++;
}

 

 

Using Adobe PDF Services API

Adobe PDF Services API is a cloud-based solution that can be used for various PDF manipulations. To add Bates numbering, you would need to use the API in your backend Node.js environment. Here's a basic example of how you might set this up:

  1. Set up your Node.js project:

 

mkdir pdf-bates-numbering
cd pdf-bates-numbering
npm init -y
npm install @adobe/pdfservices-node-sdk

 

 

Create a script to add Bates numbering:

 

 

// index.js
const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
const fs = require('fs');

const credentials = PDFServicesSdk.Credentials
    .serviceAccountCredentialsBuilder()
    .fromFile('path/to/your/pdfservices-api-credentials.json')
    .build();

const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
const batesNumbering = PDFServicesSdk.BatesNumbering;
const batesNumberingOperation = batesNumbering.Operation.createNew();

const input = PDFServicesSdk.FileRef.createFromLocalFile('path/to/your/input.pdf');
batesNumberingOperation.setInput(input);

const batesOptions = new batesNumbering.options.BatesNumberingOptions.Builder()
    .withPrefix('Bates Number: ')
    .withNumberingStart(1)
    .build();
batesNumberingOperation.setOptions(batesOptions);

batesNumberingOperation.execute(executionContext)
    .then(result => result.saveAsFile('path/to/your/output.pdf'))
    .catch(err => console.log(err));

 

 

Run the script:

 

 

node index.js

 

 

Using Third-party Libraries

If you prefer not to use Adobe's solutions, third-party libraries like iText (Java and .NET) and PDFBox (Java) provide robust tools for PDF manipulation, including Bates numbering.

Here’s a basic example using iText in Java:

 

 

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

public class BatesNumberingExample {
    public static void main(String[] args) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter("output.pdf"));
        Document document = new Document(pdfDoc);

        int n = pdfDoc.getNumberOfPages();
        for (int i = 1; i <= n; i++) {
            document.showTextAligned(new Paragraph("Bates Number: " + i), 559, 806, i, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, 0);
        }

        document.close();
    }
}

 

 

Elisabet