Solutions

Encrypt PDFs. Control permissions.

Apply 128-bit RC4 or 256-bit AES encryption. Set user and owner passwords. Restrict printing, copying, and editing per PDF spec.

Code example

rust
use pdfluent::{Sdk, EncryptOptions, EncryptionAlgorithm, Permissions};

fn main() -> pdfluent::Result<()> {
    let sdk = Sdk::new()?;
    let mut doc = sdk.open("contract.pdf")?;

    let opts = EncryptOptions::builder()
        .algorithm(EncryptionAlgorithm::Aes256)
        .user_password("view-only")
        .owner_password("owner-secret-42")
        .permissions(
            Permissions::empty()
                | Permissions::PRINT_LOW_QUALITY
        )
        .build();

    doc.encrypt(opts)?;
    doc.save("contract-encrypted.pdf")?;

    println!("Document encrypted with AES-256");
    Ok(())
}

Run cargo add pdfluent to get started.

What it does

AES-256 encryption

Applies 256-bit AES encryption as defined in PDF 1.7 Extension Level 3 and PDF 2.0. This is the strongest encryption level supported by the PDF specification and is recognized by all major PDF viewers.

RC4-128 encryption

Applies 128-bit RC4 encryption for compatibility with older PDF 1.4+ viewers. Choose RC4 when you need to support legacy systems that do not handle AES. PDFluent writes the correct /Encrypt dictionary for both algorithms.

User password

The user password is required to open and view the document. Set it with .user_password(). Leave it empty to allow opening without a password while still enforcing permission restrictions.

Owner password

The owner password grants full access and bypasses permission restrictions. Required when encrypting. PDFluent rejects identical user and owner passwords to avoid trivial permission bypass.

Permission flags

Control print, copy, modify, extract, fill forms, and assemble permissions independently. Permissions are bit flags on the Permissions struct. Combine them with bitwise OR. Unset flags deny that capability to the user password.

Decryption

Open an encrypted document with sdk.open_with_password(path, password). PDFluent tries the supplied string as both user and owner password. Once opened, save without encryption to produce a decrypted copy.

Deployment options

Server-side (Linux/macOS/Windows)AWS LambdaDockerKubernetes

Frequently asked questions