Open an encrypted PDF with the user or owner password and save an unprotected copy. Works with RC4-128 and AES-128/256 encrypted files.
use pdfluent::PdfDocument;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open_encrypted("protected.pdf", "open123")?;
doc.remove_encryption()?;
doc.save("unprotected.pdf")?;
println!("Encryption removed.");
Ok(())
}Use PdfDocument::open_encrypted() and provide the user or owner password. The method returns an error if the password is wrong.
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open_encrypted("protected.pdf", "open123")?;Match on PdfError::WrongPassword to give the user a clear error instead of a generic failure.
use pdfluent::{PdfDocument, PdfError};
let result = PdfDocument::open_encrypted("protected.pdf", "guess");
match result {
Ok(doc) => { /* proceed */ }
Err(PdfError::WrongPassword) => eprintln!("Wrong password."),
Err(e) => return Err(e.into()),
}After opening, inspect the encryption type and permission flags that were set by the document author.
let enc = doc.encryption_info()?;
println!("Algorithm: {:?}", enc.algorithm);
println!("Print allowed: {}", enc.permissions.print_allowed);
println!("Copy allowed: {}", enc.permissions.copy_text_allowed);Call remove_encryption() to strip all password protection and permission flags from the document in memory.
doc.remove_encryption()?;Save to a new path. The saved file will open in any PDF reader without a password.
doc.save("unprotected.pdf")?;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.