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
| Algorithm | Security | Compatibility |
|---|---|---|
Aes256 | High | PDF 2.0+ |
Aes128 | Medium | PDF 1.6+ |
Rc4_128 | Low | PDF 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
| Permission | Description |
|---|---|
print | Allow printing |
copy | Allow text/image copying |
modify | Allow document modification |
annotate | Allow adding annotations |
fill_forms | Allow form filling |
extract_accessibility | Allow accessibility extraction |
assemble | Allow page assembly |
print_high_quality | Allow 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.