PDF Encryption API
Encrypt a PDF and optionally set permissions.
Feature
The ComPDF Self-hosted accepts files and a request JSON string through multipart/form-data, forwards the parameters to the private PDF SDK, and streams the result file back on success.
Synchronous Request
| Item | Value |
|---|---|
| Authentication | x-api-key: your_api_key_here |
| Request URL | POST http://localhost:8080/api/v1/process/pdf/encrypt |
| Content type | multipart/form-data |
| Success response | Result file stream |
Request Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
file | File | Source PDF file. | Yes |
request | String | JSON string containing the PDF SDK parameters below. If omitted, remaining non-file form-data fields are forwarded as the request object. | No |
Request Object Parameters
Put the following fields in the request JSON string.
| Parameter | Type | Purpose |
|---|---|---|
userPassword | String | Password required to open the encrypted PDF. |
ownerPassword | String | Owner password used to manage permissions. |
permissions | Object | Permission object forwarded to the SDK. |
allowPrint | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowPrint. |
allowCopy | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowCopy. |
allowDocumentChanges | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowDocumentChanges. |
allowDocumentAssembly | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowDocumentAssembly. |
allowCommenting | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowCommenting. |
allowFormFieldEntry | Boolean | Shortcut accepted by the middle layer and moved to permissions.allowFormFieldEntry. |
outputFileName | String | Optional output filename. When present, it is used as the preferred download filename. |
Request Example
bash
curl -X POST "http://localhost:8080/api/v1/process/pdf/encrypt" \
-H "x-api-key: your_api_key_here" \
-F "[email protected]" \
-F 'request={"userPassword":"user-pass","ownerPassword":"owner-pass","permissions":"","allowPrint":"","allowCopy":""}'Response
On success, the API returns the processed file stream with Content-Type and Content-Disposition headers. On failure, the ComPDF Self-hosted returns a normalized error JSON response.