This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/annotations/flatten.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Flatten PDF annotation on Android | Nutrient SDK

Use the PdfProcessor class to flatten annotations.

Initialize Nutrient before using the processor API, including before loading a document. Otherwise, processing fails. For details, refer to the initializing Nutrient guide.

Flattening removes the annotation object from the document but preserves its appearance as page content. Neither users nor your app can edit the flattened content as an annotation. By default, the processor keeps annotations unchanged.

Use one of these methods to control how the processor handles annotations:

The following examples flatten all annotations or only free text annotations:

// `processDocument()` blocks until processing finishes, so run it in the background.
lifecycleScope.launch(Dispatchers.IO) {
// Process all pages of the document, flattening all of its annotations.
val flattenAllTask = PdfProcessorTask.fromDocument(document)
.changeAllAnnotations(PdfProcessorTask.AnnotationProcessingMode.FLATTEN)
// Write to a new file. The output can't be the file the document was opened from.
PdfProcessor.processDocument(flattenAllTask, File(context.filesDir, "flattened.pdf"))
// Flatten only free text annotations, and copy everything else.
val flattenFreeTextTask = PdfProcessorTask.fromDocument(document)
.changeAllAnnotations(PdfProcessorTask.AnnotationProcessingMode.KEEP)
.changeAnnotationsOfType(AnnotationType.FREETEXT, PdfProcessorTask.AnnotationProcessingMode.FLATTEN)
PdfProcessor.processDocument(flattenFreeTextTask, File(context.filesDir, "free-text-flattened.pdf"))
}

Flattening for print

To prepare a document for printing, use the PRINT annotation processing mode. This mode flattens printable annotations and removes the others:

// Process all pages of the document, flattening only the annotations that can be printed.
val printTask = PdfProcessorTask.fromDocument(document)
.changeAllAnnotations(PdfProcessorTask.AnnotationProcessingMode.PRINT)
val outputFile = File(context.filesDir, "flattened-for-print.pdf")
lifecycleScope.launch(Dispatchers.IO) {
PdfProcessor.processDocument(printTask, outputFile)
}