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:
-
An annotation with an
Annotation.Flag.invisible
flag will ignore annotation appearance streams. -
An annotation with a flag set to
Annotation.Flag.hidden
won’t be displayed or printed. -
An annotation with an
Annotation.Flag.print
flag will be printed.Annotation.Flag.print
is the default flag. -
An annotation with a flag set to
Annotation.Flag.noView
won’t be displayed onscreen, but printing might be allowed. -
Annotations with an
Annotation.Flag.readOnly
flag don’t allow user interactions. The flag is ignored for widget annotations. -
Annotations with an
Annotation.Flag.noZoom
flag won’t be zoomed when the page is zoomed, i.e. the size of the annotation on the page will remain the same, irrespective of the zoom level. This flag is currently only supported for stamp annotations. -
If you want to prevent your users from editing an annotation, you can set the
Annotation.Flag.locked
andAnnotation.Flag.lockedContents
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`. annotation.flags.remove(.hidden)
// 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;