Flatten Annotations
Annotation flattening refers to converting editable annotations into non-editable, non-modifiable static images or plain text forms. When the annotations are flattened, all editable elements of the entire document (including comments and forms) will be flattened, so the annotation flattening is also known as document flattening.
This example shows how to flatten annotations:
// Open the document from the file path.
CPDFDocument document = new CPDFDocument(context);
document.open(pdfPath, passwod);
// Flatten all pages of the document.
boolean result = document.flattenAllPages(CPDFPage.PDFFlattenOption.FLAT_NORMALDISPLAY);
// Save the document.
if (result) {
document.save();
}
// Open the document from the file path.
val document = CPDFDocument(context)
document.open(pdfPath, passwod)
// Flatten all pages of the document.
val result = document.flattenAllPages(CPDFPage.PDFFlattenOption.FLAT_NORMALDISPLAY)
// Save the document.
if (result) {
document.save()
}
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:
Content Protection: Flattening can be used to protect document content, ensuring that the document remains unaltered during distribution or sharing. This is crucial for maintaining document integrity and confidentiality.
Form Submission: In form processing, flattening can convert user-filled form fields and annotations into static images for easy transmission, archiving, or printing, while preventing modifications to the form content in subsequent stages.
Compatibility and Display: Some PDF readers or browsers may encounter issues with displaying and interacting with PDF documents that contain numerous annotations or layers. Document flattening helps address these compatibility issues, enhancing the visual representation of documents in various environments.
File Size Reduction: Flattened documents typically have reduced file sizes since editable elements are converted into static images or text, eliminating the need to store additional data for editing information.