Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Flutter Guides Bates number

Bates Numbering ​

Starting with 3.2.0, ComPDF Flutter SDK supports sequential Bates numbering for workflows such as case files and contract archives.

In these examples, document is an opened CPDFDocument.

dart
import 'package:compdfkit_flutter/document/cpdf_bates.dart';
import 'package:compdfkit_flutter/document/cpdf_header_footer.dart';
import 'package:flutter/material.dart';

Add or Update Numbering ​

dart
final pageCount = await document.getPageCount();
final success = await document.updateBates(
  CPDFBates(
    pages: List<int>.generate(pageCount, (index) => index),
    margin: const EdgeInsets.all(36),
    pageOffset: 0,
    slots: const [
      CPDFHeaderFooterSlot(
        position: CPDFHeaderFooterPosition.footerRight,
        text: 'CASE-<<#5#1#>>',
        fontName: 'Helvetica',
        fontSize: 12,
        textColor: Colors.black,
      ),
    ],
  ),
);
if (success) {
  await document.save();
}

CASE-<<#5#1#>> combines the prefix CASE- with a numbering template: 5 specifies the number of digits, and 1 specifies the starting number. A suffix can also follow the template.

ParameterDescription
pagesTarget page indexes, starting at 0
marginDistance from page edges, in PDF points
slotsText and styles for six header and footer positions, as defined in Headers and Footers
pageOffsetPage-number offset on Android; use 0 in cross-platform examples
ruleNumbering rule on Android; cross-platform examples use the default CPDFBatesRule.v2

An update replaces the existing position configuration. When changing a template or style, include all settings you want to retain.

Read Numbering ​

dart
final bates = await document.getBates();
if (bates != null) {
  for (final slot in bates.slots) {
    debugPrint('${slot.position.name}: ${slot.text}');
  }
}

The result is null when no Bates numbering is set. On iOS, the returned pageOffset is 0 and rule is CPDFBatesRule.v2.

Clear Numbering ​

dart
final cleared = await document.clearBates();
if (cleared) {
  await document.save();
}

Save the document after adding, updating, or clearing numbering. To retain the original file, use saveAs() to write a copy.