Configuring Editable/Visible Annotation Types

By default, PSPDFKit will render all known annotation types. See PSPDFAnnotation.h for a full list of the available types.

There are two main definition types used in PSPDFKit: Annotation.Kind as an integer bitmask with all PDF types as defined in the PDF spec (e.g. Annotation.Kind.ink), and a string variant that is better suited for arrays (Annotation.Tool.ink).

There are also some special annotation types that correspond to subtypes (e.g. Annotation.Tool.signature is actually of type Annotation.Kind.ink but is handled differently in the framework). Additionally, there are some features masked as annotation types, such as Annotation.Tool.eraser or Annotation.Tool.selectionTool. (See PSPDFAnnotationStateManager.h for all definitions).

Hiding Specific Annotation Types

The renderAnnotationTypes property controls which annotations are rendered. It’s a bitmask, and it defaults to Annotation.Kind.all.

To just allow highlights and drawings to be rendered, configure the document like this:

1
document.renderAnnotationTypes = [.highlight, .ink]
1
document.renderAnnotationTypes = PSPDFAnnotationTypeHighlight|PSPDFAnnotationTypeInk;

You should configure this property before the document is presented in a PDFViewController. If you change it afterward, either call reloadData() or, as a faster and more fine-grained approach, call update() on all visible page views:

1
2
3
for pageView in pdfController.visiblePageViews {
    pageView.update()
}
1
[pdfController.visiblePageViews makeObjectsPerformSelector:@selector(updateView)];

When changing the visible annotations after a document has already been rendered — either in a previous session or when the document is presented right away — you need to clear the cache for this document by calling PDFCache.remove(for:).

Disabling All Annotations

With the annotationsEnabled property on Document, annotations can be completely disabled. Note that links are also annotations, and you almost never want to disable links. There are, however, valid use cases, so this is an option. Changing this also requires a call to reloadData() if the document is already displayed. When enabling or disabling annotations after the document has already been rendered — either in a previous session or when the document is presented right away — you need to clear the cache for this document by calling PDFCache.remove(for:).

Control Which Types Can Be Edited/Created

The editableAnnotationTypes property controls which annotation types can be edited. It’s a set containing annotation string types (e.g. Annotation.Tool.ink).

The annotation toolbar will only display items that are in editableAnnotationTypes, but it also has its own configuration.

The annotation creation menu that appears on a long tap has a different configuration as well.