Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/apache/pdfbox/llms.txt

Use this file to discover all available pages before exploring further.

PDFBox provides two commands for managing PDF security: encrypt applies password-based or certificate-based encryption and sets access permissions, while decrypt removes encryption entirely so the document can be opened without a password. Both commands read and write standard PDF files.
PDF encryption requires the Bouncy Castle library on the classpath. The pdfbox-app standalone JAR bundles Bouncy Castle automatically. If you are using pdfbox-tools without the app JAR, add bcprov-jdk18on and bcpkix-jdk18on to your classpath.

Encrypt

The encrypt command protects a PDF with a standard password or an X.509 certificate. You can independently control eight access permissions. If no output file is specified, the input file is overwritten in place.

Usage

java -jar pdfbox-app-3.0.0.jar encrypt -i <input.pdf> [options]

Options

OptionDefaultDescription
-i, --input(required)Path to the unencrypted input PDF
-o, --output(in-place)Path for the encrypted output PDF; overwrites input if omitted
-O(none)Owner password (ignored when -certFile is set)
-U(none)User password (ignored when -certFile is set)
-certFile(none)Path to an X.509 certificate file for public-key encryption; repeat for multiple recipients
-keyLength256Encryption key length in bits: 40, 128, or 256
-canAssembletrueAllow document assembly
-canExtractContenttrueAllow content extraction
-canExtractForAccessibilitytrueAllow extraction for accessibility tools
-canFillInFormtrueAllow form fill-in
-canModifytrueAllow document modification
-canModifyAnnotationstrueAllow annotation modification
-canPrinttrueAllow printing
-canPrintFaithfultrueAllow high-quality (faithful) printing

Examples

Encrypt with an owner and user password using 256-bit AES (default):
java -jar pdfbox-app-3.0.0.jar encrypt \
  -i document.pdf -o document-enc.pdf \
  -O ownerpass -U userpass
Encrypt and disallow printing and modification:
java -jar pdfbox-app-3.0.0.jar encrypt \
  -i document.pdf -o readonly.pdf \
  -O ownerpass -U userpass \
  -canPrint false -canModify false -canPrintFaithful false
Encrypt for a specific recipient using a certificate:
java -jar pdfbox-app-3.0.0.jar encrypt \
  -i document.pdf -o document-enc.pdf \
  -certFile recipient.crt

Build docs developers (and LLMs) love