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 configuration needs to do two things:

  1. Based on the property type, annotation configuration has to implement the respective interface extending AnnotationConfiguration.
  2. The #getSupportedProperties() method from the configuration must return the set of properties that should be shown in the inspector.

For example, to enable editing of the annotation color property, supported properties must be set to AnnotationProperty#COLOR, and the configuration must implement AnnotationColorConfiguration:

Copy
1
2
3
4
5
6
7
8
fragment.annotationConfiguration().put(
   AnnotationType.FREETEXT,
   FreeTextAnnotationConfiguration(context)
      // Free-text annotations support color and text size properties.
      // This will disable the text size property in the annotation inspector.
      .setSupportedProperties(EnumSet.of(AnnotationProperty.COLOR))
      .build()
)
Copy
1
2
3
4
5
6
7
8
getPdfFragment().getAnnotationConfiguration().put(
   AnnotationType.FREETEXT,
   FreeTextAnnotationConfiguration(context)
      // Free-text annotations support color and text size properties.
      // This will disable the text size property in the annotation inspector.
      .setSupportedProperties(EnumSet.of(AnnotationProperty.COLOR))
      .build()
);

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 the 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.