Define annotation behavior with flags on iOS
Every Annotation in a document can specify flags that further define its behavior and capabilities. With Nutrient, 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.invisibleflag will ignore annotation appearance streams. - An annotation with a flag set to
Annotation.Flag.hiddenwon’t be displayed or printed. - An annotation with an
Annotation.Flag.printflag will be printed.Annotation.Flag.printis the default flag. - An annotation with a flag set to
Annotation.Flag.noViewwon’t be displayed onscreen, but printing might be allowed. - Annotations with an
Annotation.Flag.readOnlyflag don’t allow user interactions. The flag is ignored for widget annotations. - Annotations with an
Annotation.Flag.noZoomflag 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.lockedandAnnotation.Flag.lockedContentsflags.
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;