Encrypt a PDF
Protects a PDF with passwords, and restricts what readers may do with it.
Require a password
curl \
--request POST http://localhost:3000/forms/pdf/encrypt \
--form files=@report.pdf \
--form userPassword=secret \
-o report.pdf
A viewer asks for secret before it opens the PDF.
Restrict what readers may do
The owner password guards the permissions: printing, copying text, editing, filling forms, assembling pages. Turn off the ones you don't grant:
curl \
--request POST http://localhost:3000/forms/pdf/encrypt \
--form files=@report.pdf \
--form userPassword=secret \
--form ownerPassword=owner \
--form 'permissions={"print":false,"extractText":false}' \
-o report.pdf
permissions takes print, printHighQuality, modifyContent, extractText, modifyAnnotations, fillForms and assemble, each true unless you set it to false. Viewers enforce them; a tool that ignores them can still print. Only the user password keeps the content itself secret.
Pick the algorithm
algorithm takes aes256, the default, aes128, rc4-128 or rc4-40. Keep AES-256 unless an old reader can't open it.
Encrypt last
Encryption comes last in a list of stages: only optimize and render may follow it. A PDF/A or Factur-X can't be encrypted, and an encrypted PDF can't be signed: the order rules answer 400 first.
In a list of stages
The stage also runs in a list on /forms/pdf/pipe, and on the PDFs a Chromium or LibreOffice conversion makes, in its stages field:
curl \
--request POST http://localhost:3000/forms/pdf/pipe \
--form files=@report.pdf \
--form 'stages=[
{ "op": "encrypt", "userPassword": "secret", "permissions": { "print": false } }
]' \
-o report.pdf
To lift the protection, decrypt the PDF.