Add Bates Numbering to PDF in Java
Contents
[
Hide
]
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.
- Open the source PDF Document and add any extra pages required by the sample.
- Create the BatesNArtifact configuration.
- 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.
- Open the source PDF Document and add the required pages.
- Create the BatesNArtifact and add it to a pagination artifact list.
- 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());
}
}
Delete Bates numbering
Use this approach when existing Bates numbering artifacts should be removed from the document.
- Open the source PDF Document.
- Call the page collection helper that deletes Bates numbering.
- Save the cleaned output file.
public static void deleteBatesNumbering(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
PageCollectionExtensions.deleteBatesNumbering(document.getPages());
document.save(outputFile.toString());
}
}