Generate a Password-Protected PDF on iOS

PSPDFKit for iOS allows you to generate a password-protected document. To accomplish this task, you’ll need to use the securityOptions exposed by Processor’s initializer.

See CreatePasswordProtectedDocumentExample from the Catalog app for a complete example of how to create a password-protected document.

// Create a `configuration` as described in any of the other PDF generation guides.
do {
    // Set the proper password and key length in `Document.SecurityOptions`.
    let documentSecurityOptions = try Document.SecurityOptions(ownerPassword: ownerPassword, userPassword: userPassword, keyLength: Document.SecurityOptionsKeyLengthAutomatic)
    let processor = Processor(configuration: configuration, securityOptions: documentSecurityOptions)
    try processor.write(toFileURL: outputFileURL)
} catch {
    // Handle error.

// Initialize the password-protected document.
let passwordProtectedDocument = Document(url: outputFileURL)