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.

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 extending AnnotationDefaultsProvider.
  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 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.