加密 PDF 文档 API
PDF4me 保护文档 这是一个 REST 端点,用于对 PDF 文件进行密码保护,并限制收件人对其的操作。将文件以 Base64 编码格式 POST 到该端点。 /api/v2/Protect 使用密码和权限标志,即可生成新的 AES 加密 PDF 文件。只有在您允许的情况下,才能进行打印、复制、编辑和填写表单等操作。
此端点的作用
PDF4me 保护文档 加密 PDF 使用密码并在单个文件中设置权限标志 REST 致电。发送 PDF 作为 Base64选择密码以及允许的操作(打印、复制、注释、填写表单),然后接收新密码。 AES加密 PDF 在响应中。所应用的加密方式是 AES-128 或 AES-256 PDF 规格,适用于 GDPR, HIPAA以及其他以合规性为导向的工作流程。
验证您的身份 API 要求
每一个 PDF4me REST API 通话必须包含您的 API 关键在于 Authorization 头部信息。在开发者控制面板中创建或选择一个密钥,并将其保存在服务器端。切勿将其暴露在浏览器代码中。
您不容错过的重要事实
密码 现场大门文件开启。 pdf权限 枚举控制用户打开文档后可以执行的操作。将两者结合使用以发布文档。 PDF 需要密码,并且禁用打印或复制功能。pdf权限 已阻止。请将其设置为 没有任何 阻止除打开之外的所有操作,或针对特定标志(例如)进行操作。 填写表格 仅允许填写表格,不允许其他任何操作。REST API 端点
方法: 邮政
网址: https://api.pdf4me.com/api/v2/Protect
发送 Content-Type: application/json 以及 授权 带有您标题的标题 API 键。设置 异步 到 错误的 对于同步响应(HTTP 200 加密 PDF (以原始二进制字节形式)或 真的 接收 HTTP 202 加一个 地点 轮询该标头,直到它返回 200 和二进制数据。 PDF。
Postman 请求设置
| 环境 | 价值 |
|---|---|
| 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. |
参数
始终需要: 文档内容, 文档名称, 密码, pdf权限。 这 异步 标志是可选的(默认为 错误的)并控制响应是立即返回还是通过轮询 URL 返回。
| 范围 | 必需的 | 类型 | 它的作用 | 例子 |
|---|---|---|---|---|
docContent | Required | 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 | Required | String | Filename of the source PDF including the .pdf extension. Used for tracking and the output filename. | invoice.pdf |
password | Required | String | The password applied to the encrypted PDF. Users must enter this to open the document. | Str0ng-P@ss! |
pdfPermission | Required | 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 | Optional | Boolean | 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 |
我应该选择哪个pdf权限标志?
密码和权限标志分别保护不同的对象。密码控制的是权限开启;权限标志控制的是权限开启后的操作。
| 密码与权限 | password 场地 | pdfPermission 场地 |
|---|---|---|
| 防止 | 未经授权的开启 | 打开后发生的意外行为 |
| 它会影响哪些人 | 所有没有密码的人 | 所有打开过该文档的人 |
| 典型用途 | 保密交付 | 只读合同,校样副本 |
| 最严格值 | 一个强而独特的密码 | None (仅限开放) |
全部一切皆可。没有任何仅开复制打开并复制文本或图像注释打开并添加注释填写表格打开并填写表单字段支持残疾人士使用辅助功能打开集合允许页面级更改数码印刷仅限低分辨率打印请求示例
示例 A:仅使用密码加密(All 权限)
{
"docContent": "JVBERi0xLjQK...",
"docName": "invoice.pdf",
"password": "Str0ng-P@ss!",
"pdfPermission": "All",
"async": false
}
示例 B:使用最大限制进行加密(None)
可进行打印、复制、编辑、注释和表格填写等操作。
{
"docContent": "JVBERi0xLjQK...",
"docName": "confidential.pdf",
"password": "Str0ng-P@ss!",
"pdfPermission": "None",
"async": false
}
示例 C:仅加密并允许填写表单
适用于保密性信息收集表格,收件人必须填写但不得重新分发。
{
"docContent": "JVBERi0xLjQK...",
"docName": "intake-form.pdf",
"password": "Form-2026",
"pdfPermission": "Fill Forms",
"async": true
}
成功响应(同步, async: false)
HTTP 200 加密 PDF 作为原始响应体(二进制) application/pdf)。 不 JSON 封装。将响应字节直接保存到文件中。
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="protected.pdf"
<binary PDF bytes>
成功响应(异步, async: true)
HTTP 202 带一个 Location 标题。轮询 URL 和 GET (相同的 Authorization 直到您收到标头) HTTP 200 二进制 PDF。
HTTP/1.1 202 Accepted
Location: https://api.pdf4me.com/api/v2/JobStatus/<job-id>
curl 示例
同步模式(将响应正文直接保存到文件):
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}'
异步模式(注) -D headers.txt 为了捕捉 Location 轮询标头):
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}'
API 返回什么结果?
加密文档本身。保护措施是: AES加密 根据以下定义 PDF规范因此,任何符合标准的读取器都会提示输入密码并强制执行权限标志。
| 场地 | 类型 | 它包含什么 |
|---|---|---|
| Response body (HTTP 200) | Binary | The encrypted PDF bytes (Content-Type application/pdf). Write them straight to a new .pdf file; the source file is never modified. |
| Location header (HTTP 202) | String (URL) | Returned when async is true and processing continues in the background. GET this URL with the same Authorization header. |
| Poll response (HTTP 200) | Binary | The finished encrypted PDF, returned once the async job completes. |
| Poll response (HTTP 202) | Empty | Job still processing. Wait and poll the same Location URL again. |
代码示例
集成示例
常见的 REST 集成模式Typical ways developers call Protect Document.
- 请仔细阅读每张发票 PDF 从文件夹中, S3 存储桶,或数据库队列。
- Base64对字节进行编码和 POST 保护
pdf权限设置为填写表格。 - 将响应字节直接写入 .pdf 文件(原始二进制文件),然后将加密文件上传到电子邮件或对象存储。
- 遍历每个文件。该端点是无状态的,并且在速率限制范围内可以安全地进行并行调用。
- POST 来源 PDF 到
/api/v2/保护使用收件人密码和所选权限。 - 取二进制响应字节,重新编码为 Base64并喂养它们
文档内容到 数字标牌 终点。 - 收到单个 PDF 也就是说,两者兼具 AES经过加密和加密签名,可防止篡改,适用于法律和合规性应用场景。
- 为每个收件人生成唯一的密码(UUID 或共享秘密派生)。
- POST 用该密码保护
pdf权限设置为没有任何阻止所有复制和打印操作。 - 通过电子邮件发送加密邮件 PDF 密码则通过单独的渠道发送,用于合规性审计跟踪。