Skip to content
Guides

Bates Numbers

ComPDFKit provides a comprehensive API for adding, editing, and deleting Bates numbers in PDF documents, facilitating the management of user security information.

In a PDF document, only one Bates number can exist, and adding a new Bates number will overwrite the old Bates numbers.

Add Bates Numbers

The steps to add Bates numbers are as follows:

  1. Retrieve the Bates numbers object from the document.
  2. Set the properties for the Bates numbers to be added.
  3. Update the Bates numbers in the document.

This example shows how to add Bates numbers:

java
// Open document from file path.
CPDFDocument document = new CPDFDocument(context);
document.open(pdfPath, password);
CPDFBates bates = document.getBates();
int index = 0;
bates.setText(index, "<<#3#5#Prefix-#-Suffix>>");
bates.setTextColor(index, Color.RED);
bates.setFontSize(index, 14.0);
bates.setPages("0-" + (document.getPageCount() - 1));
bates.update();
kotlin
val document = CPDFDocument(context)
document.open(pdfPath, password)
document.bates.apply {
  val index = 0
  setText(index, "<<#3#5#Prefix-#-Suffix>>")
  setTextColor(index, Color.RED)
  setFontSize(index, 14.0F)
  pages = "0-${(document.pageCount - 1)}"
  update()
}

Bates Numbers Regular Expression Explanation

The regular expression for Bates numbers supports a specific format: <<#\d+#\d+#\w+#\w+>>

  • The first # is followed by the minimum number of digits to display for the page number. If the page number has fewer digits, leading zeros are added.
  • The second # is followed by the starting value of the page number.
  • The third # is followed by the prefix for the header/footer.
  • The fourth # is followed by the suffix for the header/footer.

For example: When the text is set to "<<#3#1#ab#cd>>," the text displayed on the first page will be "ab001cd."

Remove Bates Numbers

The steps to remove Bates numbers are as follows:

  1. Retrieve the Bates numbers object from the document.
  2. Remove the Bates numbers.

This example shows how to remove the Bates numbers:

java
CPDFBates bates = document.getBates();
bates.clear();
kotlin
document.bates.clear()