This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/ios/samples/preset-pdf-passwords.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Open PDF with preset password using Swift for iOS

Unlock document with password programmatically. Get additional resources by visiting our guide on opening password-protected PDFs in iOS.


//
// Copyright © 2017-2026 PSPDFKit GmbH. All rights reserved.
//
// The Nutrient sample applications are licensed with a modified BSD license.
// Please see License for details. This notice may not be removed from this file.
//
import PSPDFKit
import PSPDFKitUI
class PasswordPresetExample: Example {
override init() {
super.init()
title = "Password preset"
category = .security
}
override func invoke(with delegate: ExampleRunnerDelegate) -> UIViewController {
let document = AssetLoader.document(for: "Password-Protected.pdf")
document.unlock(withPassword: "test123")
return PDFViewController(document: document)
}
}

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.