Controlling PDF Document Editing

PDF documents can be modified in several ways — for instance, by adding annotations or filling forms. The PDF format has standard restrictions (see Secured Documents), but in addition to those built-in restrictions, PSPDFKit gives you control over how to restrict certain modifications of PDF documents.

UI

Disable All UI Interaction

If you want to disable all UI interactions, including scrolling, the thumbnail bar, and all toolbar items, you can call PdfActivity#setUserInterfaceEnabled(false).

Disable Scrolling

If you want to disable scrolling and zooming while keeping everything else (including the thumbnail bar and all toolbar items) enabled, you can call PdfActivity#setDocumentInteractionEnabled(false). Keep in mind that the user will still be able to change the current page using the thumbnail bar.

Annotations

The following section assumes you’re familiar with annotations. If not, first see Introduction to Annotations for more details.

Disable the Modification of All Annotation Types

You can disable all annotation modifications using PdfConfiguration by setting editableAnnotationTypes to null. This will prevent users from adding new annotations and editing existing ones:

1
2
val builder = PdfActivityConfiguration.Builder(context)
builder.editableAnnotationTypes(null)
1
2
PdfActivityConfiguration.Builder builder = new PdfActivityConfiguration.Builder(context);
builder.editableAnnotationTypes(null);

Enable 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:

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

Disable Adding New Annotations But Allow Modification of Existing Ones

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

Copy
1
2
3
4
5
6
7
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
}
Copy
1
2
3
4
5
6
7
8
@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;
}

Disable the Modification of a Specific Annotation

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

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

For more information, see the Annotation Flags guide.

Forms

The following section assumes you are familiar with forms. If not, first see Introduction to Forms for more details.

Disable All Form Interactions

You can disable all form interactions and modifications using disableFormEditing:

1
2
val builder = PdfActivityConfiguration.Builder(context)
builder.disableFormEditing()
1
2
PdfActivityConfiguration.Builder builder = new PdfActivityConfiguration.Builder(context);
builder.disableFormEditing();

Restricting Features

Document Editor

PDF documents can be modified using the Document Editor feature, which allows new page creation, page duplication, and the reordering, rotation, or deletion of pages. See the Document Editing guide for more details.