Flatten annotations in Flutter
Nutrient Flutter SDK enables you to create a new document with processed annotations using the static Nutrient.processAnnotations()(opens in a new tab) operation. You can embed, flatten, remove, or print annotations. The operation opens the PDF at sourcePath, writes the processed result to destinationPath, and releases the source internally. You don’t need to open a document or viewer.
Parameters
Use the Nutrient.processAnnotations() operation and its parameters to define how Nutrient processes annotations.
Processing mode
The AnnotationProcessingMode(opens in a new tab) parameter specifies how Nutrient includes annotations in the resulting document.
| Processing mode | Description |
|---|---|
flatten | Flattens the annotation. Nutrient keeps its visual representation, prevents further modification, and removes the annotation object. |
remove | Removes the annotation. |
embed | Embeds the annotation into the resulting document so users can still modify it. |
print | Processes the document for printing. Nutrient flattens printable annotations and removes the remaining ones. |
Annotation type
The AnnotationType(opens in a new tab) parameter specifies which annotation types Nutrient should process. For the complete list, refer to the supported annotation types guide. To process all annotations, use AnnotationType.all.
Source and destination paths
The sourcePath parameter is the path of the document to process. destinationPath specifies where Nutrient stores the processed file.
Save all annotations before processing the document. For more details, refer to the guide on manually saving.
Usage
The following example flattens all annotations and saves the output to PDFs/export.pdf:
await Nutrient.processAnnotations( sourcePath: 'PDFs/document.pdf', type: AnnotationType.all, mode: AnnotationProcessingMode.flatten, destinationPath: 'PDFs/export.pdf',);Nutrient supports processing on Android and iOS. On Web, it throws UnsupportedError.