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 number.

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:

swift
let url = URL(fileURLWithPath: "File Path")
let document = CPDFDocument(url: url)

let bates = document?.bates()
bates?.setText("<<#3#5#Prefix-#-Suffix>>", at: 0)
bates?.setTextColor(UIColor.red, at: 0)
bates?.setFontSize(14.0, at: 0)
bates?.update()
objective-c
NSURL *url = [NSURL fileURLWithPath:@""];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];

CPDFBates *bates = document.bates;
[bates setText:@"<<#3#5#Prefix-#-Suffix>>" atIndex:0];
[bates setTextColor:[UIColor redColor] atIndex:0];
[bates setFontSize:14.0 atIndex:0];
[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 delete 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:

swift
let bates = document?.bates()
bates?.clear()
objective-c
CPDFBates *bates = document.bates;
[bates clear];