Encrypt PDF Document API
What this endpoint does
PDF4me Protect Document encrypts a PDF with a password and sets permission flags in a single REST call. Send the PDF as Base64, choose the password and which actions are allowed (printing, copying, annotating, form filling), and receive a new AES-encrypted PDF in the response. The encryption applied is AES-128 or AES-256 per the PDF specification, suitable for GDPR, HIPAA, and other compliance-driven workflows.
Authenticating Your API Request
Every PDF4me REST API call must include your API key in the Authorization header. Create or select a key from the developer dashboard and keep it server-side. Never expose it in browser code.
Important Facts You Should Not Miss
password field gates document opening. The pdfPermission enum controls what users can do once the document is open. Use both together to ship a PDF that requires a password AND disables printing or copying.pdfPermission is blocked. Set it to None to block every action except opening, or to a specific flag such as Fill Forms to allow only form filling and nothing else.REST API endpoint
Method: POST
URL: https://api.pdf4me.com/api/v2/Protect
Send Content-Type: application/json and an Authorization header with your API key. Set async to false for a synchronous response (HTTP 200 with the encrypted PDF as raw binary bytes), or true to receive HTTP 202 plus a Location header that you poll until it returns 200 with the binary PDF.
Postman request setup
| Setting | Value |
|---|---|
| Method | POST |
| URL | https://api.pdf4me.com/api/v2/Protect |
| Headers | Content-Type: application/json |
| Authorization | Basic Auth with your API key, or header Authorization: Basic YOUR_API_KEY |
| Body | raw JSON with docContent, docName, password, pdfPermission, and async fields |
| Response (sync) | When async is false: HTTP 200 with the encrypted PDF as raw binary bytes. Save the response body directly to a .pdf file. |
| Response (async) | When async is true: HTTP 202 with a Location header. GET that URL until you receive 200 plus the binary PDF. Useful for large files or slow networks. |
Parameters
Always required: docContent, docName, password, pdfPermission. The async flag is optional (defaults to false) and controls whether the response is returned immediately or via a polling URL.
| Parameter | Required | Type | What it does | Example |
|---|---|---|---|---|
docContent | Yes | Base64 String | The source PDF file encoded as Base64 (no data: prefix). Read the file as bytes and run it through your language's Base64 encoder. | JVBERi0xLjQK... |
docName | Yes | String | Filename of the source PDF including the .pdf extension. Used for tracking and the output filename. | invoice.pdf |
password | Yes | String | The password applied to the encrypted PDF. Users must enter this to open the document. | Str0ng-P@ss! |
pdfPermission | Yes | Enum | What the user can do once the PDF is unlocked. One of: All, None, Copy, Annotate, Fill Forms, Support Disabilities, Assemble, Digital Print. See the flag reference card grid below. | Fill Forms |
async | No | Boolean | Optional, defaults to false. When false the API returns the encrypted PDF immediately as binary bytes (HTTP 200). When true the API returns HTTP 202 with a Location header; poll that URL with GET until you receive 200 with the binary PDF. Use true for large PDFs or batch processing. | false |
pdfPermission flag reference
AllEverything is allowedNoneOnly openingCopyOpen and copy text or imagesAnnotateOpen and annotateFill FormsOpen and fill form fieldsSupport DisabilitiesOpen with accessibility toolsAssemblePage-level changes allowedDigital PrintLow-resolution print onlyRequest examples
Example A: Encrypt with password only (All permissions)
{
"docContent": "JVBERi0xLjQK...",
"docName": "invoice.pdf",
"password": "Str0ng-P@ss!",
"pdfPermission": "All",
"async": false
}
Example B: Encrypt with maximum restrictions (None)
Blocks printing, copying, editing, annotating, and form filling.
{
"docContent": "JVBERi0xLjQK...",
"docName": "confidential.pdf",
"password": "Str0ng-P@ss!",
"pdfPermission": "None",
"async": false
}
Example C: Encrypt and allow form filling only
Useful for confidential intake forms where the recipient must fill but not redistribute.
{
"docContent": "JVBERi0xLjQK...",
"docName": "intake-form.pdf",
"password": "Form-2026",
"pdfPermission": "Fill Forms",
"async": true
}
Successful response (sync, async: false)
HTTP 200 with the encrypted PDF as the raw response body (binary application/pdf). No JSON wrapping. Save the response bytes directly to a file.
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="protected.pdf"
<binary PDF bytes>
Successful response (async, async: true)
HTTP 202 with a Location header. Poll that URL with GET (same Authorization header) until you receive HTTP 200 with the binary PDF.
HTTP/1.1 202 Accepted
Location: https://api.pdf4me.com/api/v2/JobStatus/<job-id>
curl examples
Sync mode (save the response body straight to a file):
curl -X POST https://api.pdf4me.com/api/v2/Protect \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-o protected.pdf \
-d '{"docContent":"JVBERi0xLjQK...","docName":"invoice.pdf","password":"Str0ng-P@ss!","pdfPermission":"Fill Forms","async":false}'
Async mode (note -D headers.txt to capture the Location header for polling):
curl -X POST https://api.pdf4me.com/api/v2/Protect \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-D headers.txt \
-d '{"docContent":"...","docName":"invoice.pdf","password":"Str0ng-P@ss!","pdfPermission":"Fill Forms","async":true}'
Code samples
Integration examples
Common REST integration patternsTypical ways developers call Protect Document.
- Read each invoice PDF from a folder, S3 bucket, or database queue.
- Base64-encode the bytes and POST to Protect with
pdfPermissionset toFill Forms. - Write the response bytes directly to a .pdf file (raw binary), then upload the encrypted file to email or object storage.
- Loop over every file. The endpoint is stateless and safe for parallel calls within your rate limit.
- POST the source PDF to
/api/v2/Protectwith the recipient password and chosen permission. - Take the binary response bytes, re-encode to Base64, and feed them as
docContentto the Digital Sign endpoint. - Receive a single PDF that is both AES-encrypted and cryptographically signed. Tamper-evident for legal and compliance use cases.
- Generate a unique password per recipient (UUID or shared-secret derived).
- POST to Protect with that password and
pdfPermissionset toNoneto block all copy and print. - Email the encrypted PDF and the password through a separate channel for compliance audit trails.