Annotation Flags

Every Annotation in a document can specify AnnotationFlags that further define the annotation’s behavior and capabilities. With PSPDFKit, you can access these flags directly on your annotation objects using getFlags()[] and setFlags()[].

Capabilities of Flags

Annotation flags are part of the PDF specification and define the 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 that is marked HIDDEN won’t be displayed or printed.
  • By specifying PRINT as well, the annotation will be added to the print output while remaining hidden onscreen.
  • If you want to prevent your users from editing an annotation, you can set the LOCKED and LOCKEDCONTENTS flags.

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

Usage Example

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

Copy
1
2
3
4
5
6
7
8
9
10
11
// Create a new annotation.
val annotation: Annotation = ...

// Lock the annotation using flags.
annotation.flags = EnumSet.of(
    AnnotationFlags.LOCKED,
    AnnotationFlags.LOCKEDCONTENTS
)

// Add the newly created annotation to the document.
document.annotationProvider.addAnnotationToPage(annotation)
Copy
1
2
3
4
5
6
7
8
9
10
11
// Create a new annotation.
final Annotation annotation = ...

// Lock the annotation using flags.
annotation.setFlags(EnumSet.of(
    AnnotationFlags.LOCKED,
    AnnotationFlags.LOCKEDCONTENTS)
);

// Add the newly created annotation to the document.
document.getAnnotationProvider().addAnnotationToPage(annotation);