Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oPdf
LOCAL oLjd
LOCAL cPdfVersion
LOCAL cFilter
LOCAL nKeyLength
LOCAL V
LOCAL R
LOCAL P
LOCAL cPrintLowResolution
LOCAL cPrintHighResolution
LOCAL cModifyOther
LOCAL cModifyAnnotations
LOCAL cModifyForms
LOCAL cFillInForms
LOCAL cAssembleDoc
LOCAL cExtractAnyPurpose
LOCAL cExtractAccessibility
LOCAL cMethod

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oPdf := CreateObject("Chilkat.Pdf")

//  Load a PDF.
nSuccess := oPdf:LoadFile("c:/someDir/sample.pdf")
IF (nSuccess == 0)
    ? oPdf:LastErrorText
    oPdf:destroy()
    RETURN
ENDIF

//  Get information about the PDF that was collected in the call to LoadFile.
oLjd := CreateObject("Chilkat.JsonObject")
oPdf:GetLastJsonData(oLjd)

oLjd:EmitCompact := 0

? oLjd: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

cPdfVersion := oLjd:StringOf("pdfVersion")
cFilter := oLjd:StringOf("encrypt.filter")
nKeyLength := oLjd:IntOf("encrypt.keyLength")
V := oLjd:IntOf("encrypt.V")
R := oLjd:IntOf("encrypt.R")
P := oLjd:IntOf("encrypt.P")
cPrintLowResolution := oLjd:StringOf("encrypt.perm.printLowResolution")
cPrintHighResolution := oLjd:StringOf("encrypt.perm.printHighResolution")
cModifyOther := oLjd:StringOf("encrypt.perm.modifyOther")
cModifyAnnotations := oLjd:StringOf("encrypt.perm.modifyAnnotations")
cModifyForms := oLjd:StringOf("encrypt.perm.modifyForms")
cFillInForms := oLjd:StringOf("encrypt.perm.fillInForms")
cAssembleDoc := oLjd:StringOf("encrypt.perm.assembleDoc")
cExtractAnyPurpose := oLjd:StringOf("encrypt.perm.extractAnyPurpose")
cExtractAccessibility := oLjd:StringOf("encrypt.perm.extractAccessibility")
cMethod := oLjd:StringOf("encrypt.method")

oPdf:destroy()
oLjd:destroy()