Inspect the permission flags on any PDF before processing it. Useful for pre-flight checks in document pipelines.
use pdfluent::PdfDocument;
fn main() -> pdfluent::Result<()> {
let doc = PdfDocument::open("document.pdf")?;
let perms = doc.permissions();
println!("Printing allowed: {}", perms.printing());
println!("High-res print: {}", perms.high_res_printing());
println!("Text copy allowed: {}", perms.copying());
println!("Editing allowed: {}", perms.editing());
println!("Form filling allowed: {}", perms.form_filling());
println!("Annotations allowed: {}", perms.annotations());
Ok(())
}Permission inspection works with or without the encryption feature. The base crate is enough.
# Cargo.toml
[dependencies]
pdfluent = "0.9"For password-protected PDFs, supply the user or owner password. A user password is enough to read permission flags.
use pdfluent::PdfDocument;
// Unprotected PDF
let doc = PdfDocument::open("document.pdf")?;
// Password-protected PDF
let doc = PdfDocument::open_with_password("protected.pdf", "user-password")?;Call doc.permissions() to get a Permissions struct. On an unencrypted PDF all flags return true.
let perms = doc.permissions();
println!("Printing: {}", perms.printing());
println!("High-res: {}", perms.high_res_printing());
println!("Copy: {}", perms.copying());
println!("Edit: {}", perms.editing());
println!("Forms: {}", perms.form_filling());
println!("Annotations: {}", perms.annotations());Use the flags to decide how to process the document downstream. For example, skip text extraction on documents that disallow copying.
let perms = doc.permissions();
if !perms.copying() {
eprintln!("Text extraction not permitted by document policy.");
return Ok(());
}
let text = doc.extract_text()?;
println!("{}", text);Use doc.is_encrypted() to distinguish between an unencrypted PDF (all permissions are open by default) and one that has explicit restrictions.
if doc.is_encrypted() {
println!("Document is encrypted. Checking permission flags...");
let perms = doc.permissions();
println!("Copy allowed: {}", perms.copying());
} else {
println!("Document is not encrypted. All operations are allowed.");
}No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.