Swift
Swift
PDF Get Encryption and Permissions Information
See more PDF Signatures Examples
Determine if a PDF is encrypted, and the associated user permissions.Note: Some PDFs are encrypted but not password-protected. In such cases, encryption is used primarily for preventing unauthorized modifications to the document, but it doesn't restrict access. Therefore, you can open and read the document without a password.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let pdf = CkoPdf()!
// Load a PDF.
success = pdf.loadFile(filePath: "c:/someDir/sample.pdf")
if success == false {
print("\(pdf.lastErrorText!)")
return
}
// Get information about the PDF that was collected in the call to LoadFile.
let ljd = CkoJsonObject()!
pdf.getLastJsonData(json: ljd)
ljd.emitCompact = false
print("\(ljd.emit()!)")
// Sample output:
// {
// "pdfVersion": "1.6",
// "encrypt": {
// "filter": "/Standard",
// "keyLength": 128,
// "V": 4,
// "R": 4,
// "P": -1340,
// "perm": {
// "printLowResolution": "allowed",
// "printHighResolution": "allowed",
// "modifyOther": "not allowed",
// "modifyAnnotations": "allowed",
// "modifyForms": "not allowed",
// "fillInForms": "allowed",
// "assembleDoc": "allowed",
// "extractAnyPurpose": "not allowed",
// "extractAccessibility": "not allowed"
// },
// "method": "AESV2"
// }
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var pdfVersion: String? = ljd.string(of: "pdfVersion")
var Filter: String? = ljd.string(of: "encrypt.filter")
var KeyLength: Int = ljd.int(of: "encrypt.keyLength").intValue
var V: Int = ljd.int(of: "encrypt.V").intValue
var R: Int = ljd.int(of: "encrypt.R").intValue
var P: Int = ljd.int(of: "encrypt.P").intValue
var PrintLowResolution: String? = ljd.string(of: "encrypt.perm.printLowResolution")
var PrintHighResolution: String? = ljd.string(of: "encrypt.perm.printHighResolution")
var ModifyOther: String? = ljd.string(of: "encrypt.perm.modifyOther")
var ModifyAnnotations: String? = ljd.string(of: "encrypt.perm.modifyAnnotations")
var ModifyForms: String? = ljd.string(of: "encrypt.perm.modifyForms")
var FillInForms: String? = ljd.string(of: "encrypt.perm.fillInForms")
var AssembleDoc: String? = ljd.string(of: "encrypt.perm.assembleDoc")
var ExtractAnyPurpose: String? = ljd.string(of: "encrypt.perm.extractAnyPurpose")
var ExtractAccessibility: String? = ljd.string(of: "encrypt.perm.extractAccessibility")
var Method: String? = ljd.string(of: "encrypt.method")
}