Configuring Editable/Visible Annotation Types

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

Hiding Specific Annotation Types

When building your PdfConfiguration, you have the ability to specify excludedAnnotationTypes. This allows you to exclude specific types from being rendered.

For example, to allow only highlights and drawings to be rendered, configure the document like this:

Copy
1
2
3
4
5
6
7
8
9
val configuration: PdfConfiguration = ...

// Create a list with all annotation types.
val excludedAnnotationTypes = ArrayList(EnumSet.allOf(AnnotationType::class.java))
// Then remove the ones you would like to display.
excludedAnnotationTypes.remove(AnnotationType.HIGHLIGHT)
excludedAnnotationTypes.remove(AnnotationType.INK)
// Apply this to your configuration.
configuration.excludedAnnotationTypes(excludedAnnotationTypes)
Copy
1
2
3
4
5
6
7
8
9
10
11
PdfConfiguration configuration = ...;

// Create a list with all annotation types.
ArrayList<AnnotationType> excludedAnnotationTypes = new ArrayList<>(EnumSet.allOf(AnnotationType.class));

// Then remove the ones you would like to display.
excludedAnnotationTypes.remove(AnnotationType.HIGHLIGHT);
excludedAnnotationTypes.remove(AnnotationType.INK);

// Apply this to your configuration.
configuration.excludedAnnotationTypes(excludedAnnotationTypes);

Or, to exclude only highlights and drawings, configure the document like this:

Copy
1
2
3
4
val configuration: PdfConfiguration = ...

// Excludes ink and stamps from being rendered.
configuration.excludedAnnotationTypes(ArrayList(EnumSet.of(AnnotationType.INK, AnnotationType.HIGHLIGHT)))
Copy
1
2
3
4
PdfConfiguration configuration = ...;

// Excludes ink and stamps from being rendered.
configuration.excludedAnnotationTypes(new ArrayList<>(EnumSet.of(AnnotationType.INK, AnnotationType.HIGHLIGHT)));

You need to configure this before creating the PdfFragment. If you are using a PdfActivity, you can update it using setConfiguration().

Including and Excluding All Annotation Types

You can also exclude all annotation types by passing in all types:

Copy
1
2
3
4
val configuration: PdfConfiguration = ...

// Passing all annotation types will exclude all annotations from being rendered.
configuration.excludedAnnotationTypes(ArrayList(EnumSet.allOf(AnnotationType::class.java)))
Copy
1
2
3
4
PdfConfiguration configuration = ...;

// Passing all annotation types will exclude all annotations from being rendered.
configuration.excludedAnnotationTypes(new ArrayList<>(EnumSet.allOf(AnnotationType.class)));

And to include them, pass in an empty array:

Copy
1
2
3
4
val configuration: PdfConfiguration = ...

// Passing an empty list will render all annotations.
configuration.excludedAnnotationTypes(ArrayList())
Copy
1
2
3
4
PdfConfiguration configuration = ...;

// Passing an empty list will render all annotations.
configuration.excludedAnnotationTypes(new ArrayList<>());

Control Which Types Can Be Edited/Created

The PdfConfiguration also contains editableAnnotationTypes to control which annotation types can be edited. Keep in mind that passing an empty list or null will result in ALL annotation types being editable. If you want to disable all types, you have to pass in NONE:

1
2
// Disable all annotation types.
configuration.editableAnnotationTypes(listOf(AnnotationType.NONE))
1
2
// Disable all annotation types.
configuration.editableAnnotationTypes(Collections.singletonList(AnnotationType.NONE));

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