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-2025 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 PSPDFKitimport 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.