Create PDFs with Restricted Permissions on Android

The PDF specification defines a series of flags that can be set on a document to determine what a user can do with a document. These permissions are represented as a bitmask at the PDF level. When a permission bit isn’t present at its defined position, the permission is considered not granted.

PSPDFKit honors the permissions set on a document and enables or disables certain platform features based on the permission configuration. For instance, if a PDF doesn’t explicitly define the printing permission as loaded, PSPDFKit won’t enable the printing option in the UI.

The PDF specification defines the permissions shown below.

  • Printing: Print the document.

  • High-Quality Printing: Print the document in high fidelity.

  • Copying Content: Copy or otherwise extract text and graphics from the document.

  • Document Assembly: Insert, rotate, or delete pages and create document outline items or thumbnail images.

  • Editing Annotations and Forms: Add or modify text annotations and fill in interactive form fields.

  • Filling Forms: Fill in existing interactive form fields (including signature fields).

  • Modifying Content: Any other modifications not covered by previous permission flags.

By default, most documents will have all permissions marked as granted.

PSPDFKit has support for the above permissions on a per-platform basis. This is ongoing work, and support for more permissions is being worked on to reach feature parity across platforms.

The permissions will be honored when the document is unlocked with a user password (in case there’s one). Please note that a PDF document can have both an owner password and a user password (read more). We recommend not using the same value for both the owner and user password.

You can use the DocumentPermissions enumeration to programmatically read or update a document’s permissions.

Below you’ll find a detailed breakdown of the permissions that can be set.

Printing and High-Quality Printing

These permissions are defined by the PRINTING and PRINT_HIGH_QUALITY flags, respectively.

Text Extraction

When this permission isn’t given, users aren’t allowed to copy text out of the document, and the related UI elements will be disabled. However, text selection will still be available. This permission is defined by the EXTRACT flag.

Document Assembling

This permission is defined by the ASSEMBLE flag, but currently it isn’t honored by PSPDFKit for Android.

Forms and Annotations

PSPDFKit for Android will allow users to fill in forms whenever the ANNOTATIONS_AND_FORMS or the FILL_FORM flag is set.

When this permission isn’t given, users aren’t allowed to fill forms, and the related UI elements will be disabled.

Content Modification

This is defined by the MODIFICATION flag. This flag is currently not honored by PSPDFKit for Android.

Modifying a document’s permissions requires PSPDFKit to be instantiated with a license that includes the Document Editor component.

It’s worth noting that if you wish to modify the default document permissions with PSPDFKit, you’ll be required to protect the document with a password.

You can retrieve the current permissions of a document via the getPermissions() method defined in the PdfDocument class. This class also defines a method, hasPermission(DocumentPermission), which checks whether or not the document has a specific permission set.

Document permissions can be set by defining the appropriate flags on the DocumentSaveOptions object used to save an existing document:

val saveOptions = document.getDefaultDocumentSaveOptions()
saveOptions.setPermissions(EnumSet.of(DocumentPermissions.ANNOTATIONS_AND_FORMS))

document.save(documentPath, saveOptions)
DocumentSaveOptions saveOptions = document.getDefaultDocumentSaveOptions();
saveOptions.setPermissions(EnumSet.of(DocumentPermissions.ANNOTATIONS_AND_FORMS))

document.save(documentPath, saveOptions)

Currently, PSPDFKit for Android doesn’t offer a UI from which a user can modify the document permissions.