Create PDFs with Restricted Permissions in iOS

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.

Secured Documents

PDF documents can be secured with a password or with other security methods. PSPDFKit can handle protected and secured documents and write annotations and forms into a password-protected document the same as it would a non-protected document.

Adobe Security Dialog

As shown above, Acrobat defines various restrictions. For example, sometimes form filling isn’t allowed for a document.

Sometimes documents are password secured but have an empty password set. This might sound paradoxical, but it isn’t unusual in the PDF world. In such a case, PSPDFKit will attempt to unlock documents with an empty password before showing the password dialog. This way, users don’t get confused. This behavior is the same as in Adobe Acrobat.

Getting and Setting Permissions

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 Document.permissions property. This property is read-only and will only return the permissions from the first file when the document is comprised of multiple underlying files.

Document permissions can be set using the Document.SecurityOptions class when interacting with the document processor. After you define your desired security options, you instantiate a Processor object with it:

do {
  let documentSecurityOptions = try Document.SecurityOptions(ownerPassword: password, userPassword: password, keyLength: Document.SecurityOptionsKeyLengthAutomatic, permissions: [.annotationsAndForms])
} catch {
  // Handle error.
guard let processorConfiguration = Processor.Configuration(document: document) else {
  // Handle error.

// Create a processor and write the file with the permissions applied.
let processor = Processor(configuration: processorConfiguration, securityOptions: securityOptions)
try processor.write(toFileURL: outputFileURL)

Users can also customize the permissions directly from the UI via PDFDocumentSecurityViewController. This is part of the default UI that’s presented when outlineButtonItem is invoked.

Restricting Draggable Content

PSPDFKit allows users to drag and drop various elements, such as images and text, from and to an application. All drag-and-drop interactions are enabled by default. However, you can selectively restrict specific interactions, as described in our Drag and Drop guide.