Sample code for 30+ languages & platforms
Rust 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 Rust Downloads

Rust

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

let pdf = chilkat::Pdf::new();

// Load a PDF.
if pdf.load_file("c:/someDir/sample.pdf").is_err() {
    println!("{}", pdf.last_error_text());
    return;
}

// Get information about the PDF that was collected in the call to LoadFile.
let ljd = chilkat::JsonObject::new();
pdf.get_last_json_data(&ljd);

ljd.set_emit_compact(false);

println!("{}", ljd.emit().unwrap_or_default());

// 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

let pdf_version = ljd.string_of("pdfVersion").unwrap_or_default();
let filter = ljd.string_of("encrypt.filter").unwrap_or_default();
let key_length = ljd.int_of("encrypt.keyLength");
let v = ljd.int_of("encrypt.V");
let r = ljd.int_of("encrypt.R");
let p = ljd.int_of("encrypt.P");
let print_low_resolution = ljd.string_of("encrypt.perm.printLowResolution").unwrap_or_default();
let print_high_resolution = ljd.string_of("encrypt.perm.printHighResolution").unwrap_or_default();
let modify_other = ljd.string_of("encrypt.perm.modifyOther").unwrap_or_default();
let modify_annotations = ljd.string_of("encrypt.perm.modifyAnnotations").unwrap_or_default();
let modify_forms = ljd.string_of("encrypt.perm.modifyForms").unwrap_or_default();
let fill_in_forms = ljd.string_of("encrypt.perm.fillInForms").unwrap_or_default();
let assemble_doc = ljd.string_of("encrypt.perm.assembleDoc").unwrap_or_default();
let extract_any_purpose = ljd.string_of("encrypt.perm.extractAnyPurpose").unwrap_or_default();
let extract_accessibility = ljd.string_of("encrypt.perm.extractAccessibility").unwrap_or_default();
let method = ljd.string_of("encrypt.method").unwrap_or_default();