Zig Requires Chilkat v11.0.0+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
// Load a PDF.
pdf.loadFile("c:/someDir/sample.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Get information about the PDF that was collected in the call to LoadFile.
const ljd = try chilkat.JsonObject.init();
defer ljd.deinit();
pdf.getLastJsonData(ljd);
ljd.setEmitCompact(false);
std.debug.print("{s}\n", .{try ljd.emit(alloc)});
// 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
_ = try ljd.stringOf(alloc, "pdfVersion");
_ = try ljd.stringOf(alloc, "encrypt.filter");
_ = ljd.intOf("encrypt.keyLength");
_ = ljd.intOf("encrypt.V");
_ = ljd.intOf("encrypt.R");
_ = ljd.intOf("encrypt.P");
_ = try ljd.stringOf(alloc, "encrypt.perm.printLowResolution");
_ = try ljd.stringOf(alloc, "encrypt.perm.printHighResolution");
_ = try ljd.stringOf(alloc, "encrypt.perm.modifyOther");
_ = try ljd.stringOf(alloc, "encrypt.perm.modifyAnnotations");
_ = try ljd.stringOf(alloc, "encrypt.perm.modifyForms");
_ = try ljd.stringOf(alloc, "encrypt.perm.fillInForms");
_ = try ljd.stringOf(alloc, "encrypt.perm.assembleDoc");
_ = try ljd.stringOf(alloc, "encrypt.perm.extractAnyPurpose");
_ = try ljd.stringOf(alloc, "encrypt.perm.extractAccessibility");
_ = try ljd.stringOf(alloc, "encrypt.method");
}