Define annotation behavior with flags in Flutter
Every Annotation(opens in a new tab) in a document can specify AnnotationFlag(opens in a new tab) values that define its behavior and capabilities. Access these flags directly on annotation objects with Annotation.flags.
Capabilities of flags
Annotation flags are part of the PDF specification. They define an annotation’s behavior, its appearance onscreen and on paper, and the editing actions available to your users. You can use flags to control these behaviors:
- Mark an annotation as
hiddenso it won’t be displayed or printed. - Set
printto include the annotation in print output while keeping it hidden onscreen. - Set the
lockedandlockedContentsflags to prevent users from editing an annotation.
For a complete list of available flags, refer to the AnnotationFlag(opens in a new tab) API reference.
Example
The following example creates a locked annotation that users can’t edit:
import 'package:nutrient_flutter/bindings.dart';
void createReadOnlyAnnotation() { // Create a new text annotation. final annotation = FreeTextAnnotation( pageIndex: 0, bbox: [50.0, 650.0, 200.0, 50.0], text: TextContent( format: TextFormat.plain, value: 'This is a free text annotation', ), // Set the `readOnly` flag to prevent editing. flags: [AnnotationFlag.readOnly, AnnotationFlag.print], ... // Other annotation properties. ); // Add the annotation to the document. controller.document.annotations.addAnnotation(annotation);}