Define Annotation Behavior with Flags on iOS

Every Annotation in a document can specify flags that further define its behavior and capabilities. With PSPDFKit, you can access these flags directly on your annotation objects using the flags property.

Capabilities of Flags

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


Check out the Annotation.Flag 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 modified by your users:

// Create a new annotation.
let annotation = StampAnnotation(stampType: .confidential)

// Update the annotation flags.
annotation.flags.update(with: [.locked, .lockedContents])

// Add the newly created annotation to the document.
document.add(annotations: [annotation])

// To add an additional flag, use `update`.
annotation.flags.update(with: .hidden)

// To remove a flag, use `remove`.
// Create a new annotation.
PSPDFAnnotation *annotation = [[PSPDFStampAnnotation alloc] initWithStampType:PSPDFStampTypeConfidential];

// Update the annotation flags.
annotation.flags |= PSPDFAnnotationFlagLocked | PSPDFAnnotationFlagLockedContents;

// Add the newly created annotation to the document.
[document addAnnotations:@[annotation] options:nil];

// To add an additional flag, use bitwise OR with the flag value.
annotation.flags |= PSPDFAnnotationFlagHidden;

// To remove a flag, use bitwise AND with the reverse flag value.
annotation.flags &= ~PSPDFAnnotationFlagHidden;