Define annotation behavior with flags in Flutter

Every Annotation in a document can specify AnnotationFlags that further define an annotation’s behavior and capabilities. Access these flags directly on your annotation objects using Annotation.flags.

Capabilities of flags

Annotation flags are part of the PDF specification and define an annotation’s behavior, its presentation on the screen and on paper, and the available editing features given to your users. Here are a few examples of things you can do with flags:

  • An annotation marked hidden won’t be displayed or printed.

  • By specifying print, the annotation will be added to the print output while remaining hidden onscreen.

  • If you want to prevent your users from editing an annotation, set the locked and lockedContents flags.

Check out the AnnotationFlags API reference for a complete list of available flags.

Example

Here’s an example of how to create a locked annotation, i.e. an annotation that can’t be edited by your users:

import 'package:pspdfkit/pspdfkit.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`s flag to prevent editing.
	 flags: [AnnotationFlag.readOnly, AnnotationFlag.print],
	 ... // Other annotation properties.
  );
  // Add the annotation to the document.
  pdfDocument.addAnnotation(annotation);
}