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. PSPDFAnnotationType as an integer bit-field with all PDF types as defined in the PDF spec (e.g. PSPDFAnnotationTypeInk); and a string variant that is better suited for arrays (PSPDFAnnotationStringInk).

There are also some special annotation types that correspond to subtypes (e.g. PSPDFAnnotationStringSignature is actually of type PSPDFAnnotationTypeInk but is handled differently in the framework). There are also some features masked as annotation types, such as PSPDFAnnotationStringEraser or PSPDFAnnotationStringSelectionTool. (See PSPDFAnnotationStateManager.h for all definitions).

Hiding specific annotation types

The renderAnnotationTypes property controls what annotations are rendered. It's a bit-mask and defaults to PSPDFAnnotationTypeAll.

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 PSPDFViewController. If you change it afterwards, either call reloadData or, as a more fine-grained and faster approach, call updateView 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 now, you need to clear the cache for this document by calling -[PSPDFCache removeCacheForDocument:].

Disabling all annotations

With the annotationsEnabled property on PSPDFDocument, annotations can be completely disabled. Note that links are also annotations, and you almost never want to disable links. There are valid use cases however, 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 now, you need to clear the cache for this document by calling -[PSPDFCache removeCacheForDocument:].

Control what types can be edited/created

The editableAnnotationTypes property controls what annotation types can be edited. It's a set containing annotation string types (e.g. PSPDFAnnotationStringInk).

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.