Lock down what readers can do with your PDF. Restrict printing, copying text, editing, and form filling using the PDFluent SDK.
use pdfluent::{PdfDocument, EncryptOptions, Permissions};
fn main() -> pdfluent::Result<()> {
let mut doc = PdfDocument::open("report.pdf")?;
let opts = EncryptOptions::aes256()
.with_owner_password("owner-secret")
.with_permissions(Permissions::print_only());
doc.encrypt(opts)?;
doc.save("report-restricted.pdf")?;
Ok(())
}Add the dependency to Cargo.toml. The encryption feature includes AES-128 and AES-256 support.
# Cargo.toml
[dependencies]
pdfluent = "1.0.0-beta.8"Open the PDF you want to restrict. If it is already encrypted you must supply the owner password.
let mut doc = PdfDocument::open("input.pdf")?;
// Or, if already encrypted:
// let mut doc = PdfDocument::open_with("input.pdf", OpenOptions::new().with_password("current-owner-pw"))?;Use the Permissions builder to choose what is allowed. All operations default to denied when you use the builder.
use pdfluent::Permissions;
let permissions = Permissions::full_access()
.with_print(false) // block all printing
.with_print_high_quality(false)
.with_copy(false) // block text/image copying
.with_modify(false) // block page editing
.with_annotate(false) // block adding comments
.with_fill_forms(true); // allow form data entryPair the permission set with an encryption config. The owner password lets you change permissions later. The user password is what readers enter to open the file.
use pdfluent::EncryptOptions;
let opts = EncryptOptions::aes256().with_owner_password("owner-secret").with_user_password("user-secret")
.with_permissions(permissions);
doc.encrypt(opts)?;Write the encrypted PDF to disk. The original file is not modified.
doc.save("locked.pdf")?;
println!("Saved locked.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.