Add Bates Numbering to PDF in Java

Bates numbering artifacts are useful in legal, archival, and document-control workflows where each page needs a persistent page-level identifier.

Add Bates numbering with the dedicated helper

Use this example when you want to apply Bates numbering through the dedicated page collection helper.

  1. Open the source PDF Document and add any extra pages required by the sample.
  2. Create the BatesNArtifact configuration.
  3. Apply Bates numbering to the page collection and save the output file.
public static void addBatesNArtifact(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        for (int i = 0; i < 2; i++) {
            document.getPages().add();
        }

        BatesNArtifact batesArtifact = createBatesArtifact();
        PageCollectionExtensions.addBatesNumbering(document.getPages(), batesArtifact);
        document.save(outputFile.toString());
    }
}

Add Bates numbering through pagination artifacts

This example applies Bates numbering by passing the Bates artifact through the generic pagination API.

  1. Open the source PDF Document and add the required pages.
  2. Create the BatesNArtifact and add it to a pagination artifact list.
  3. Apply the pagination artifacts to the page collection and save the document.
public static void addBatesNArtifactPagination(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        for (int i = 0; i < 2; i++) {
            document.getPages().add();
        }

        BatesNArtifact batesArtifact = createBatesArtifact();
        List<PaginationArtifact> paginationArtifacts = new ArrayList<>();
        paginationArtifacts.add(batesArtifact);
        PageCollectionExtensions.addPagination(document.getPages(), paginationArtifacts);
        document.save(outputFile.toString());
    }
}