跳到主要内容

加密 PDF 文档 API

PDF4me 保护文档 这是一个 REST 端点,用于对 PDF 文件进行密码保护,并限制收件人对其的操作。将文件以 Base64 编码格式 POST 到该端点。 /api/v2/Protect 使用密码和权限标志,即可生成新的 AES 加密 PDF 文件。只有在您允许的情况下,才能进行打印、复制、编辑和填写表单等操作。

此端点的作用

PDF4me 保护文档 加密 PDF 使用密码并在单个文件中设置权限标志 REST 致电。发送 PDF 作为 Base64选择密码以及允许的操作(打印、复制、注释、填写表单),然后接收新密码。 AES加密 PDF 在响应中。所应用的加密方式是 AES-128 或 AES-256 PDF 规格,适用于 GDPRHIPAA以及其他以合规性为导向的工作流程。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

验证您的身份 API 要求

每一个 PDF4me REST API 通话必须包含您的 API 关键在于 Authorization 头部信息。在开发者控制面板中创建或选择一个密钥,并将其保存在服务器端。切勿将其暴露在浏览器代码中。

您不容错过的重要事实

密码和权限同时应用。
单曲 密码 现场大门文件开启。 pdf权限 枚举控制用户打开文档后可以执行的操作。将两者结合使用以发布文档。 PDF 需要密码,并且禁用打印或复制功能。
权限标志是允许列表,而不是拒绝列表。
你没有包括在内的任何内容 pdf权限 已阻止。请将其设置为 没有任何 阻止除打开之外的所有操作,或针对特定标志(例如)进行操作。 填写表格 仅允许填写表格,不允许其他任何操作。
来源 PDF 从未修改过
API 返回加密后的数据 PDF 以原始二进制字节的形式写入响应正文(Content-Type application/pdf)。您的原始文件保持不变。将响应字节直接写入新的 .pdf 文件。这对于合规性审计跟踪非常有用,因为在这些情况下,未受保护的源文件必须保持完整。

REST API 端点

方法: 邮政
网址: https://api.pdf4me.com/api/v2/Protect

发送 Content-Type: application/json 以及 授权 带有您标题的标题 API 键。设置 异步错误的 对于同步响应(HTTP 200 加密 PDF (以原始二进制字节形式)或 真的 接收 HTTP 202 加一个 地点 轮询该标头,直到它返回 200 和二进制数据。 PDF

Postman 请求设置

环境价值
MethodPOST
URLhttps://api.pdf4me.com/api/v2/Protect
HeadersContent-Type: application/json
AuthorizationBasic Auth with your API key, or header Authorization: Basic YOUR_API_KEY
Bodyraw 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 返回。

范围必需的类型它的作用例子
docContentRequiredBase64 StringThe source PDF file encoded as Base64 (no data: prefix). Read the file as bytes and run it through your language's Base64 encoder.JVBERi0xLjQK...
docNameRequiredStringFilename of the source PDF including the .pdf extension. Used for tracking and the output filename.invoice.pdf
passwordRequiredStringThe password applied to the encrypted PDF. Users must enter this to open the document.Str0ng-P@ss!
pdfPermissionRequiredEnumWhat 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
asyncOptionalBooleanDefaults 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 (仅限开放)
全部一切皆可。
打开、打印、复制、编辑、注释、填写表单。仅用于密码保护,无其他限制。
没有任何仅开
限制打印、复制、编辑、注释和表格填写。这是限制最多的选项。
复制打开并复制文本或图像
区块打印、编辑、注释。
注释打开并添加注释
允许使用便签和高亮标记。禁止复制、打印和编辑。
填写表格打开并填写表单字段
打印、复印、编辑模块。常用于保密登记表。
支持残疾人士使用辅助功能打开
屏幕阅读器和辅助工具访问。这是默认启用无障碍功能的 PDF 文件的必要条件。
集合允许页面级更改
插入、删除或旋转页面。当下游工具需要重组 PDF 文件时使用。
数码印刷仅限低分辨率打印
会阻止高分辨率打印和复印。适用于校样复印。

请求示例

示例 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 标题。轮询 URLGET (相同的 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)BinaryThe 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)BinaryThe finished encrypted PDF, returned once the async job completes.
Poll response (HTTP 202)EmptyJob still processing. Wait and poll the same Location URL again.

代码示例

集成示例

常见的 REST 集成模式Typical ways developers call Protect Document.
批量加密发票以进行交付
  1. 请仔细阅读每张发票 PDF 从文件夹中, S3 存储桶,或数据库队列。
  2. Base64对字节进行编码和 POST 保护 pdf权限 设置为 填写表格
  3. 将响应字节直接写入 .pdf 文件(原始二进制文件),然后将加密文件上传到电子邮件或对象存储。
  4. 遍历每个文件。该端点是无状态的,并且在速率限制范围内可以安全地进行并行调用。
先加密再签名,适用于法律工作流程。
  1. POST 来源 PDF/api/v2/保护 使用收件人密码和所选权限。
  2. 取二进制响应字节,重新编码为 Base64并喂养它们 文档内容数字标牌 终点。
  3. 收到单个 PDF 也就是说,两者兼具 AES经过加密和加密签名,可防止篡改,适用于法律和合规性应用场景。
GDPR 或者 HIPAA 按接收者加密
  1. 为每个收件人生成唯一的密码(UUID 或共享秘密派生)。
  2. POST 用该密码保护 pdf权限 设置为 没有任何 阻止所有复制和打印操作。
  3. 通过电子邮件发送加密邮件 PDF 密码则通过单独的渠道发送,用于合规性审计跟踪。

常见问题解答

What encryption strength does the Protect endpoint apply?+
PDF4me applies AES encryption per the PDF specification (ISO 32000). Modern PDF readers use 128-bit or 256-bit AES depending on the PDF version of the source. Both meet GDPR and HIPAA encryption requirements for documents in transit and at rest.
Can I set an owner password and a user password separately?+
The password field is applied as the user password (required to open). The pdfPermission enum is the owner-level signal controlling what is allowed once the document is open. Together they behave like a combined owner-and-user setup. The endpoint does not currently accept two distinct passwords in one call.
How do I disable printing or copying on the encrypted PDF?+
Pick a pdfPermission value that does NOT include the action you want to block. Set it to None to block everything except opening. Set it to Copy to allow text or image copy only. Set it to Fill Forms to allow form filling only. The flag is allow-list: anything not explicitly listed is blocked.
Is the original PDF modified, or is a new copy returned?+
The original file is never touched. The API returns the encrypted PDF as raw binary bytes in the response body (Content-Type application/pdf). Write the response bytes directly to a new .pdf file. Useful when the unprotected source must remain intact for audit trails.
Can I encrypt PDFs in bulk?+
Each call protects one PDF and the endpoint is stateless. For bulk encryption, loop over files in your script (Python for loop, C# foreach, Node async map) or use a Make, Zapier, Power Automate, or n8n scenario that fires the Protect action per file picked up by a folder watcher.
Does this work as an alternative to SmallPDF, iLovePDF, or Adobe Acrobat password protection?+
Yes. The Protect endpoint provides the same outcome (password-encrypted PDF with permission control) through a REST API. No per-user license, no manual upload, and full automation. The same call from a script handles one document or one thousand.
Is the response binary or Base64?+
The response body is the raw binary PDF (Content-Type application/pdf), not JSON. Write the response bytes straight to a .pdf file: response.content in Python requests, response.body in fetch, await Content.ReadAsByteArrayAsync in C#. The Base64 envelope is only used for input (the docContent field you send in the request), not for the output.
How do I test the API without writing code?+
Open the Protect Document API Tester, paste your API key, upload a PDF, type a password, and pick a pdfPermission flag. The tester shows the request and lets you download the encrypted PDF directly.

相关行动

在其他平台上执行相同的任务

获取帮助