Document Permissions

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 is not 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 that does not 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 PSPDFDocumentPermissions enumeration to programmatically read or update a document’s permissions.

Below you’ll find a detailed breakdown of the permissions that can be set, and what the out-of-the-box behavior will be in case the given permission is not granted in the document.

Printing and High-Quality Printing

Printing and high-quality printing are represented by the PSPDFDocumentPermissionsPrinting and PSPDFDocumentPermissionsPrintHighQuality flags, respectively. PSPDFKit for iOS only honors the PSPDFDocumentPermissionsPrinting permission, since iOS only offers a single printing pipeline.

If PSPDFDocumentPermissionsPrinting is not granted:

  • the UIActivityTypePrint activity will be removed from the available sharing activities when using the PSPDFDocumentSharingDestinationActivity sharing destination.
  • the PSPDFDocumentSharingDestinationPrint sharing destination won’t be available.

Text Extraction

Text extraction is represented by the PSPDFDocumentPermissionsExtract flag.

If not granted, the user won’t be able to copy selected text or images.

Document Assembling

Document assembling is represented by the PSPDFDocumentPermissionsAssemble flag.

If not granted, the user won’t be able to enter the Document Editor view mode.

Forms and Annotations

Forms and annotations are represented by the PSPDFDocumentPermissionsAnnotationsAndForms flag.

If not granted, the user won’t be able to:

  • Create new annotations
  • Move, resize, or rotate existing annotations
  • Add comments to existing annotations

If PSPDFDocumentPermissionsFillForms is not granted either, the user won’t be able to fill in form fields, including signature fields, checkboxes, and radio buttons.

Content Modification

Content modification is represented by the PSPDFDocumentPermissionsModification flag.

If not granted, the user won’t be able to add or edit bookmarks, redact portions of the document, or edit information like the document title and author information.

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

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

Copy
1
2
3
4
5
6
PSPDFDocumentSecurityOptions *securityOptions = [[PSPDFDocumentSecurityOptions alloc] initWithOwnerPassword:password userPassword:password keyLength:PSPDFDocumentSecurityOptionsKeyLengthAutomatic permissions:PSPDFDocumentPermissionsAnnotationsAndForms error:&error];
PSPDFProcessorConfiguration *processorConfiguration = [[PSPDFProcessorConfiguration alloc] initWithDocument:document];

// Create a processor and write the file with the permissions applied.
PSPDFProcessor *processor = [[PSPDFProcessor alloc] initWithConfiguration:processorConfiguration securityOptions:securityOptions];
[processor writeToFileURL:outputFileURL error:&error];
Copy
1
2
3
4
5
6
7
8
9
let securityOptions = try? PSPDFDocumentSecurityOptions(ownerPassword: password, userPassword: password, keyLength: PSPDFDocumentSecurityOptionsKeyLengthAutomatic, permissions: [.annotationsAndForms])

guard let processorConfiguration = PSPDFProcessorConfiguration(document: document) else {
  return
}

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

Users can also customize the permissions directly from the UI via PSPDFDocumentSecurityViewController.

Bypassing Document Permissions

If, for whatever reason, you wish to ignore any permissions that might have been disabled on a given document, you can do so by setting the PSPDFHonorDocumentPermissionsKey key to false in the shared PSPDFKit object:

1
PSPDFSDK.shared[.honorDocumentPermissionsKey] = false
1
[PSPDFKitGlobal.sharedInstance setValue:@NO forKey:PSPDFHonorDocumentPermissionsKey];

For documents that were instantiated before changing this option, [document.features updateFeatures] needs to be invoked to ensure the changes are correctly reflected in the features system.