Skip to main content
Version: 9.x

Encrypt a PDF

Protects a PDF with passwords, and restricts what readers may do with it.

POST/forms/pdf/encrypt
filesfile[]required

The PDFs.

archivesfile[]

ZIP files Gotenberg unpacks: each entry counts as a file uploaded under files.

URLs Gotenberg downloads first, as if you had uploaded the files. Each entry takes a url, and optionally extraHttpHeaders.

The password to open the PDF. Set userPassword, ownerPassword, or both.

The password to lift the permissions.

algorithmstring

aes256, aes128, rc4-128 or rc4-40.

Default: aes256

What a reader without the owner password may do: print, printHighQuality, modifyContent, extractText, modifyAnnotations, fillForms, assemble. Each is true unless you set it to false.

The PDF, or a ZIP of the PDFs when you send several.

The route also takes the headers. An error answers a status and a message: see Errors.

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.