Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Encryption

Commercial License Required - This feature requires a commercial license. See printwell.dev/pricing.

Password-protect PDF documents with AES or RC4 encryption.

Encryption Algorithms

AlgorithmSecurityCompatibility
Aes256HighPDF 2.0+
Aes128MediumPDF 1.6+
Rc4_128LowPDF 1.4+ (legacy)

Encrypting PDFs

#![allow(unused)]
fn main() {
use printwell::encrypt::{encrypt_pdf, EncryptionOptions, Permissions};

let options = EncryptionOptions::builder()
    .owner_password("admin123")
    .user_password("user123")
    .algorithm(EncryptionAlgorithm::Aes256)
    .permissions(Permissions {
        print: true,
        copy: false,
        modify: false,
        annotate: true,
        fill_forms: true,
        extract_accessibility: true,
        assemble: false,
        print_high_quality: true,
    })
    .build();

let encrypted = encrypt_pdf(&pdf_data, &options)?;
}

Permissions

PermissionDescription
printAllow printing
copyAllow text/image copying
modifyAllow document modification
annotateAllow adding annotations
fill_formsAllow form filling
extract_accessibilityAllow accessibility extraction
assembleAllow page assembly
print_high_qualityAllow high-quality printing

Permission Presets

#![allow(unused)]
fn main() {
// All permissions
let perms = Permissions::all();

// No permissions (maximum restriction)
let perms = Permissions::none();

// Print only
let perms = Permissions::print_only();
}

Decrypting PDFs

#![allow(unused)]
fn main() {
use printwell::encrypt::decrypt_pdf;

let decrypted = decrypt_pdf(&encrypted_data, "password")?;
}

Node.js Example

import { encryptPdf, decryptPdf } from 'printwell';

const encrypted = encryptPdf(pdfData, {
    ownerPassword: 'admin123',
    userPassword: 'user123',
    algorithm: 'Aes256',
    permissions: {
        print: true,
        copy: false,
        modify: false
    }
});

const decrypted = decryptPdf(encrypted, 'admin123');

Python Example

from printwell import encrypt_pdf, decrypt_pdf, EncryptionOptions, Permissions

options = EncryptionOptions(
    owner_password="admin123",
    user_password="user123",
    permissions=Permissions(print=True, copy=False, modify=False)
)

encrypted = encrypt_pdf(pdf_data, options)
decrypted = decrypt_pdf(encrypted, "admin123")

Owner vs User Password

  • Owner password: Full access, can change permissions
  • User password: Opens document with specified permissions

If only owner password is set, anyone can open the document but restrictions apply.