PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Bates numbering adds sequential identifiers to document collections such as legal and audit records. Starting with 3.2.0, ComPDF React Native SDK supports reading, setting, and clearing Bates numbers, with configurable prefixes, digit counts, positions, and text styles.
The example accepts a reader whose document has finished loading and adds a five-digit number with a prefix to the first page.
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
async function setBates(reader: CPDFReaderView) {
const success = await reader._pdfDocument.updateBates({
pages: [0],
margin: { left: 24, top: 24, right: 24, bottom: 24 },
pageOffset: 0,
rule: 'v2',
slots: [{ position: 'footer_right', text: 'CASE-<<#5#1#>>',
fontName: 'Helvetica', fontSize: 12, textColor: '#000000' }],
});
if (!success) throw new Error('Failed to update Bates numbering');
if (!await reader.save()) throw new Error('Failed to save the document');
}<<#5#1#>> specifies five digits starting at 1, for example CASE-00001. pages uses zero-based page indexes. Margins and font sizes use PDF points. Positions are the same as for Headers and Footers.
updateBates() replaces the complete configuration, so include every position you want to keep. Cross-platform examples use pageOffset: 0 and rule: 'v2'. iOS does not apply custom values for these parameters; Android supports a page offset and the v1 and v2 rules.
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
async function clearBates(reader: CPDFReaderView) {
const document = reader._pdfDocument;
const current = await document.getBates();
if (current === null) return;
if (!await document.clearBates()) throw new Error('Failed to clear Bates numbering');
if (!await reader.save()) throw new Error('Failed to save the document');
}getBates() returns null when no Bates numbering exists. clearBates() clears Bates numbers from the document. Handle both false results and rejected Promises.