Hiding Annotations on iOS

By default, PSPDFKit will render all known annotation types. You can find a full list of the available types here.

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 enable all annotations except audio, image, and video annotations, you can set the following:

var annotationTypes = Annotation.Kind.all
annotationTypes.remove(.screen)
annotationTypes.remove(.richMedia)
annotationTypes.remove(.sound)
document.renderAnnotationTypes = annotationTypes
document.renderAnnotationTypes = PSPDFAnnotationTypeAll & ~(PSPDFAnnotationTypeScreen|PSPDFAnnotationTypeRichMedia|PSPDFAnnotationTypeSound|PSPDFAnnotationTypeStamp);

ℹ️ Note: Images are rendered as stamps, but there’s no simple way to differentiate between a text stamp (e.g. Approved) and an image stamp.

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

document.renderAnnotationTypes = [.highlight, .ink]
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:

for pageView in pdfController.visiblePageViews {
    pageView.update()
}
[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:).