Disabling Annotation Editing on Android

Annotation editing can be configured using PdfActivityConfiguration.Builder when using PdfActivity, or using PdfConfiguration.Builder when using PdfFragment.

Controlling Which Annotation Types Can Be Edited

By default, PSPDFKit enables editing of all supported annotation types. You can disable editing for all annotation types via #disableAnnotationEditing.

If you want to control which annotation types are editable, use #editableAnnotationTypes. For example, when using PdfActivityConfiguration.Builder:

val config =
    PdfActivityConfiguration.Builder(context)
        // By default, all supported annotation types are editable.
        // You can selectively enable certain types by providing them here.
        .editableAnnotationTypes(listOf(AnnotationType.NOTE, AnnotationType.INK, AnnotationType.STAMP))
        .build()
final PdfActivityConfiguration config =
    new PdfActivityConfiguration.Builder(context)
        // By default, all supported annotation types are editable.
        // You can selectively enable certain types by providing them here.
        .editableAnnotationTypes(Arrays.asList(AnnotationType.NOTE, AnnotationType.INK, AnnotationType.STAMP))
        .build();

Or when using PdfConfiguration.Builder:

val config =
    PdfConfiguration.Builder()
        // By default, all supported annotation types are editable.
        // You can selectively enable certain types by providing them here.
        .editableAnnotationTypes(listOf(AnnotationType.NOTE, AnnotationType.INK, AnnotationType.STAMP))
        .build()
PdfConfiguration config =
    new PdfConfiguration.Builder()
        // By default, all supported annotation types are editable.
        // You can selectively enable certain types by providing them here.
        .editableAnnotationTypes(Arrays.asList(AnnotationType.NOTE, AnnotationType.INK, AnnotationType.STAMP))
        .build();

Passing null or an empty list to this method means that all supported annotation types are editable.

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

Enabling Modifications Only for Specific Annotation Types

You can control which annotation types are editable, and you can specify their types in editableAnnotationTypes. For example, you can allow only the modification of ink annotations:

val builder = PdfActivityConfiguration.Builder(context)
// Only ink annotations are editable.
builder.editableAnnotationTypes(listOf(AnnotationType.INK))
PdfActivityConfiguration.Builder builder = new PdfActivityConfiguration.Builder(context);
// Only ink annotations are editable.
builder.editableAnnotationTypes(Collections.singletonList(AnnotationType.INK));

Disabling Adding New Annotations but Allowing Modification of Existing Ones

Hiding your PdfActivity’s annotation editing button from the toolbar will prevent users from adding new annotations, but it won’t stop them from editing or deleting existing ones:

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
    // It's important to call `super` before removing the item so that PSPDFKit can add its own items.
    super.onPrepareOptionsMenu(menu)
    // Remove the annotation item.
    menu.removeItem(R.id.pspdf__menu_option_edit_annotations)
    return true
}
@Override
public boolean onPrepareOptionsMenu(@NonNull Menu menu) {
    // It's important to call `super` before removing the item so that PSPDFKit can add its own items.
    super.onPrepareOptionsMenu(menu);
    // Remove the annotation item.
    menu.removeItem(R.id.pspdf__menu_option_edit_annotations);
    return true;
}

Disabling the Modification of a Specific Annotation

You can disable the modification of a specific annotation by using setFlags with the READONLY flag, like so:

// Make the annotation read-only.
annotation.setFlags(EnumSet.of(AnnotationFlags.READONLY));
// Make the annotation read-only.
annotation.setFlags(EnumSet.of(AnnotationFlags.READONLY));

For more information, see the guide on annotation flags.