Skip to content
ComPDF

PDF Encryption API

BASE URLhttps://api-server.compdf.com/server/

❖ Feature Description

Set a user password, owner password, and permission controls for one PDF.

❖ Request Mode

Synchronous Request (Sync)
The API returns the result file directly after processing. Recommended for small files and real-time interactive scenarios that need immediate feedback.
Asynchronous Request (Async)
The API first returns task acceptance information, then you query progress and results with taskId. Suitable for large files and batch workloads.
Secure Request Mode
Upload and process files through secure mechanisms such as pre-signed URLs. Suitable for high-security and privacy compliance scenarios.

▎Call Flow

1Upload file
2Call API (sync)
3Get result URL
4Download file

▎Usage Limits

Download validity24 hours

PDF Encryption (Sync)

POSThttps://api-server.compdf.com/server/v2/process/pdf/encrypt

❖ Request Parameters

Authentication credential sent in the header: x-api-key

Body Parameters multipart/form-data

No file selected
Upload file
File password (if the PDF is password-protected)
API error message language (1 = English, 2 = Chinese)
User password. This is the password required to open the encrypted PDF. Fill in at least one of userPassword or ownerPassword.
Owner password. This is used for permission control and later permission removal. It can control permissions such as printing, copying, editing, commenting, and form filling. Use a value different from userPassword when possible.
Encryption algorithm. Allowed values: rc4, aes128, aes256. Default: rc4.
Whether printing is allowed. Enter true or false. Default: false.
Whether copying PDF content is allowed. Enter true or false. Default: false.
Whether modifying document content is allowed. Enter true or false. Default: false.
Whether page assembly is allowed, such as inserting, deleting, rotating, or reordering pages. Enter true or false. Default: false.
Whether adding or editing comments is allowed. Enter true or false. Default: false.
Whether filling form fields is allowed. Enter true or false. Default: false.
Output file name

❖ Response Properties

FieldTypeDescription
codeStringBusiness status code
msgStringMessage
dataObjectResponse data
data.fileKeyStringUnique key of the file in the storage system.
data.taskIdStringTask ID
data.fileNameStringSource file name. Required in presigned mode to generate the object storage upload URL.
data.downFileNameStringOutput file name after conversion.
data.fileUrlStringSource file storage URL or object storage key.
data.downloadUrlStringFile download URL
data.sourceTypeStringSource file type
data.targetTypeStringTarget file type
data.fileSizeIntegerSource file size in bytes.
data.convertSizeIntegerConverted file size in bytes.
data.convertTimeIntegerConversion time for a single file, typically in milliseconds.
data.statusStringFile processing status. Common values: success, failed, processing, etc.
data.failureCodeStringError code when file conversion fails.
data.failureReasonStringError reason when file conversion fails.
data.fileParameterStringConversion parameter JSON string submitted when creating the task.
🔗Request Example
curl --request POST \
  --url https://api-server.compdf.com/server/v2/process/pdf/encrypt \
  --header 'x-api-key: YOUR API-KEY' \
  --form [email protected] \
  --form algorithm=rc4
Response Example
200 OK
{
  "code": "200",
  "msg": "success",
  "data": {
    "fileKey": "saas/2026/06/30/[email protected]",
    "taskId": "bce85055-093a-49da-94c3-7f3fdf3ee527",
    "fileName": "input.pdf",
    "downFileName": "encrypted.pdf",
    "fileUrl": "https://example.com/source.pdf",
    "downloadUrl": "https://example.com/result.pdf",
    "sourceType": "pdf",
    "targetType": "encrypt",
    "fileSize": 123456,
    "convertSize": 123000,
    "convertTime": 1200,
    "status": "success",
    "failureCode": null,
    "failureReason": null,
    "fileParameter": "{\"userPassword\":\"123456\",\"algorithm\":\"rc4\"}"
  }
}