Annotation Inspector

The annotation inspector is a PSPDFKit UI component that allows editing of annotation properties. It is integrated with the PdfActivity and is displayed when a user selects the annotation properties picker from the annotation creation or editing toolbars.

Annotation Property Defaults

In the annotation inspector, you can control annotation property defaults, allowed values, and whether or not a property is editable by setting a new AnnotationDefaultsProvider instance via the PdfFragment#setAnnotationDefaultsProvider().

The defaults for each annotation type are defined in interfaces extending AnnotationDefaultsProvider.

Interface Description
AnnotationDefaultsBorderStyleProvider Provides border style settings.
AnnotationDefaultsColorProvider Provides foreground color settings.
AnnotationDefaultsFillColorProvider Provides fill color settings.
AnnotationDefaultsLineEndTypeProvider Provides line end type settings.
AnnotationDefaultsNoteIconProvider Provides note annotation icon settings.
AnnotationDefaultsPreviewProvider Provides settings regarding the inspector preview.
AnnotationDefaultsStampProvider Provides stamp annotation settings.
AnnotationDefaultsTextSizeProvider Provides text size settings.
AnnotationDefaultsThicknessProvider Provides thickness settings.
AnnotationDefaultsAlphaProvider Provides alpha settings.
EraserDefaultsProvider Provides eraser settings.

To simplify the implementation of the annotation defaults providers, PSPDFKit provides ready-to-use implementations for all supported annotation types:

For an example of how to customize annotation defaults, see the AnnotationDefaultsExample inside the Catalog app.

Control Which Annotation Properties Are Available in the Annotation Inspector

To control the set of properties shown by the annotation inspector for each annotation type, your custom annotation defaults provider needs to do two things:

  1. Based on the property type, your defaults provider has to implement the respective interface from the table above.
  2. The #getSupportedProperties() method of your provider must return the set of properties that should be shown in the inspector.

For example, to enable editing of the annotation color property, #getSupportedProperties() must return AnnotationProperty#COLOR, and the provider must implement AnnotationDefaultsColorProvider:

Copy
1
2
3
4
5
6
7
fragment.setAnnotationDefaultsProvider(AnnotationType.FREETEXT, object : FreeTextAnnotationDefaultsProvider(context) {
   override fun getSupportedProperties(): EnumSet<AnnotationProperty> {
      // Free text annotation supports color and text size properties.
      // This will disable the text size property in the annotation inspector.
      return EnumSet.of(AnnotationProperty.COLOR)
    }
})
Copy
1
2
3
4
5
6
7
8
9
getPdfFragment().setAnnotationDefaultsProvider(AnnotationType.FREETEXT, new FreeTextAnnotationDefaultsProvider(context) {
   @NonNull
   @Override
   public EnumSet<AnnotationProperty> getSupportedProperties() {
       // Free text annotation supports color and text size properties.
       // This will disable the text size property in the annotation inspector.
       return EnumSet.of(AnnotationProperty.COLOR);
   }
});

Custom Annotation Inspector UI

PdfActivity uses AnnotationCreationInspectorController when creating annotations and AnnotationEditingInspectorController when editing annotations. Replacing the built-in annotation inspector UI with a custom implementation is simple. All you need to do is provide an implementation of both AnnotationCreationInspectorController and AnnotationEditingInspectorController to PdfActivity via #setAnnotationCreationInspectorController() and #setAnnotationEditingInspectorController().

If you don’t need to create the entire UI from scratch, you can extend the ready-to-use inspector controllers, DefaultAnnotationCreationInspectorController and DefaultAnnotationEditingInspectorController.

See the CustomAnnotationInspectorExample from the Catalog app for a complete overview of how to create a custom annotation inspector UI.

Using Annotation Inspector with a Custom Activity or Layout

If you are using a custom layout in PdfActivity, you need to provide PropertyInspectorCoordinatorLayout with the ID @id/pspdf__inspector_coordinator in order to be able to use the annotation inspector. See the Custom Activity Layouts section of the Extending the PdfActivity guide article for more details.

If you are using a custom activity built around PdfFragment, follow the Using Property Inspectors within Fragment guide for information on how to manually integrate the annotation inspector. Alternatively, you can take a look at the ToolbarsInFragmentExample from the Catalog app for a complete example of how to integrate contextual toolbars using the default annotation inspector in a custom activity using PdfFragment.