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 the Bates number:

C#
CPDFDocument document = CPDFDocument.InitWithFilePath("filePath");

CPDFBates bates = document.GetBates();
bates.SetText(0, @"<<#3#5#Prefix-#-Suffix>>");
byte[] color = { 255, 0, 0 };
bates.SetTextColor(0, color);
bates.SetFontSize(0,14);
bates.SetPages("0-" + (document.PageCount - 1));
bates.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:

C#
CPDFHeaderFooter headerFooter = document.GetHeaderFooter();
headerFooter.Clear();