PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkPdf.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
pdf.i = CkPdf::ckCreate()
If pdf.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load a PDF.
success = CkPdf::ckLoadFile(pdf,"c:/someDir/sample.pdf")
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
ProcedureReturn
EndIf
; Get information about the PDF that was collected in the call to LoadFile.
ljd.i = CkJsonObject::ckCreate()
If ljd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkPdf::ckGetLastJsonData(pdf,ljd)
CkJsonObject::setCkEmitCompact(ljd, 0)
Debug CkJsonObject::ckEmit(ljd)
; 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
pdfVersion.s = CkJsonObject::ckStringOf(ljd,"pdfVersion")
Filter.s = CkJsonObject::ckStringOf(ljd,"encrypt.filter")
KeyLength.i = CkJsonObject::ckIntOf(ljd,"encrypt.keyLength")
V.i = CkJsonObject::ckIntOf(ljd,"encrypt.V")
R.i = CkJsonObject::ckIntOf(ljd,"encrypt.R")
P.i = CkJsonObject::ckIntOf(ljd,"encrypt.P")
PrintLowResolution.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.printLowResolution")
PrintHighResolution.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.printHighResolution")
ModifyOther.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.modifyOther")
ModifyAnnotations.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.modifyAnnotations")
ModifyForms.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.modifyForms")
FillInForms.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.fillInForms")
AssembleDoc.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.assembleDoc")
ExtractAnyPurpose.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.extractAnyPurpose")
ExtractAccessibility.s = CkJsonObject::ckStringOf(ljd,"encrypt.perm.extractAccessibility")
Method.s = CkJsonObject::ckStringOf(ljd,"encrypt.method")
CkPdf::ckDispose(pdf)
CkJsonObject::ckDispose(ljd)
ProcedureReturn
EndProcedure