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.
Annotation flattening refers to the process of converting editable annotations into non-editable, unmodifiable static images or plain text. When flattening annotations, all editable elements in the document (including annotations and form fields) are flattened, so annotation flattening is also known as document flattening.
Below is an example of how to flatten annotations:
Using CPDFReaderWidget:
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and obtain the controller in the onCreated callback
CPDFReaderWidget(
document: documentPath,
configuration: CPDFConfiguration(),
onCreated: (controller) {
setState(() {
this._controller = controller;
});
},
)
final savePath = 'file:///storage/emulated/0/Download/flatten.pdf';
// Or use a Uri on Android:
// final savePath = await ComPDFKit.createUri('flatten_test.pdf', 'ComPDF', 'application/pdf');
final fontSubset = true;
final result = await _controller.document.flattenAllPages(savePath, fontSubset);
await _controller.reloadPages();Using CPDFDocument:
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
final savePath = 'file:///storage/emulated/0/Download/flatten.pdf';
// Or use a Uri on Android:
// final savePath = await ComPDFKit.createUri('flatten_test.pdf', 'ComPDF', 'application/pdf');
final fontSubset = true;
final result = await document.flattenAllPages(savePath, fontSubset);
}What is Document Flattening
Document flattening refers to the process of converting editable elements, such as annotations, form fields, or layers, in a PDF document into non-editable, static images, or pure text. The purpose of this process is to lock the final state of the document, eliminating editable elements.
Document flattening is typically applied in the following contexts: