Lua Requires Chilkat v11.0.0+
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local pdf = chilkat.Pdf.new()
-- Load a PDF.
local success = pdf:load_file("c:/someDir/sample.pdf")
if not success then
print(pdf.last_error_text)
return
end
-- Get information about the PDF that was collected in the call to LoadFile.
local ljd = chilkat.JsonObject.new()
pdf:get_last_json_data(ljd)
ljd.emit_compact = 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
local pdfVersion = ljd:string_of("pdfVersion")
local Filter = ljd:string_of("encrypt.filter")
local KeyLength = ljd:int_of("encrypt.keyLength")
local V = ljd:int_of("encrypt.V")
local R = ljd:int_of("encrypt.R")
local P = ljd:int_of("encrypt.P")
local PrintLowResolution = ljd:string_of("encrypt.perm.printLowResolution")
local PrintHighResolution = ljd:string_of("encrypt.perm.printHighResolution")
local ModifyOther = ljd:string_of("encrypt.perm.modifyOther")
local ModifyAnnotations = ljd:string_of("encrypt.perm.modifyAnnotations")
local ModifyForms = ljd:string_of("encrypt.perm.modifyForms")
local FillInForms = ljd:string_of("encrypt.perm.fillInForms")
local AssembleDoc = ljd:string_of("encrypt.perm.assembleDoc")
local ExtractAnyPurpose = ljd:string_of("encrypt.perm.extractAnyPurpose")
local ExtractAccessibility = ljd:string_of("encrypt.perm.extractAccessibility")
local Method = ljd:string_of("encrypt.method")