How-to guides/Errors & Debugging
PdfluentError::Encrypted
Error: document is encrypted and requires a password

How to fix the PDF encrypted error in PDFluent

This error means PDFluent found an encryption dictionary in the PDF and cannot proceed without credentials. The fix depends on whether you have the user password, owner password, or the file has an empty password.

Why this happens

The PDF has a user password set

The author protected the document with a password. Any reader must supply the correct user password before opening. PDFluent detects the encryption dictionary and returns this error instead of attempting to parse an unreadable stream.

The password string is an empty string, not None

Some PDFs are encrypted with an empty string as the password (""). Opening the file without passing any password triggers the error, but passing an explicit empty string succeeds. This is common with PDFs exported from older tools.

You have the user password but the operation requires the owner password

PDF encryption has two password levels: user and owner. The owner password unlocks permissions like printing, copying, and editing. If you open with the user password and then attempt a restricted operation (like flattening or signing), PDFluent returns a permissions error that looks similar to this one.

How to fix it

1

Open with the user password

Pass the password to Document::open_protected(). The password is a byte slice, not a string, because PDF passwords are byte sequences.

use pdfluent::Document;

let doc = Document::open_protected("locked.pdf", b"mypassword")?;
let text = doc.page(0)?.extract_text()?;
2

Try an empty password first

If you receive this error on a PDF you did not expect to be protected, try opening with an empty password. Many PDF generators set empty-string encryption.

use pdfluent::Document;

// Try empty password before concluding the document is inaccessible
let doc = Document::open_protected("export.pdf", b"")?;
3

Open with the owner password for restricted operations

If you need to modify the document (flatten, sign, redact), you need the owner password. Use Document::open_owner() to unlock full permissions.

use pdfluent::Document;

let mut doc = Document::open_owner("protected.pdf", b"ownerpassword")?;

// Now permitted to flatten, sign, or change permissions
doc.acroform()?.flatten()?;
doc.save("output.pdf")?;

Frequently asked questions