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.
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.
import 'package:compdfkit_flutter/document/cpdf_bates.dart';
import 'package:compdfkit_flutter/document/cpdf_header_footer.dart';
import 'package:flutter/material.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.
| Parameter | Description |
|---|---|
pages | Target page indexes, starting at 0 |
margin | Distance from page edges, in PDF points |
slots | Text and styles for six header and footer positions, as defined in Headers and Footers |
pageOffset | Page-number offset on Android; use 0 in cross-platform examples |
rule | Numbering 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.
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.
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.