Skip to main content

Protect PDF

POST https://api.getdocuforge.dev/v1/pdf/protect Add password protection and permission controls to a PDF document.

Request Body

ParameterTypeRequiredDescription
pdfstringYesBase64-encoded PDF document
owner_passwordstringYesOwner password (grants full access)
user_passwordstringNoUser password (required to open the document)
permissionsobjectNoPermission flags (see below)
outputstringNo"url" (default) or "base64"

Permissions

ParameterTypeDefaultDescription
printingbooleantrueAllow printing the document
copyingbooleanfalseAllow copying text and images
modifyingbooleanfalseAllow modifying the document

Example

curl -X POST https://api.getdocuforge.dev/v1/pdf/protect \
  -H "Authorization: Bearer df_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "pdf": "<base64-encoded-pdf>",
    "owner_password": "owner-secret-123",
    "user_password": "open-me-456",
    "permissions": {
      "printing": true,
      "copying": false,
      "modifying": false
    }
  }'

Response (URL mode)

{
  "url": "https://cdn.getdocuforge.dev/gen_abc123.pdf",
  "file_size": 52400,
  "protected": true
}

Response (base64 mode)

{
  "data": "<base64-encoded-protected-pdf>",
  "file_size": 52400,
  "protected": true
}

Errors

StatusCodeDescription
400VALIDATION_ERRORMissing owner password or PDF exceeds size limit
401UNAUTHORIZEDInvalid or missing API key
429RATE_LIMITEDToo many requests
500INTERNAL_ERRORServer error during protection