跳到主要内容

填写 PDF 形式

此端点的作用

PDF4me 填写PDF表格 在 AcroForm 中填充字段 PDF 包含来自以下对象的值的模板 JSON 单个对象 REST 致电。发送模板。 Base64 或公众 URL将字段值作为字符串发送。 数据数组并接收已填好的 PDF 以二进制字节 (200) 或通过 Location 标头轮询 URL (202)切换 KeepPdf可编辑 提供可重新编辑的表单或扁平化的静态记录。

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

验证您的身份 API 要求

每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。

端点

邮政/api/v2/FillPdfForm

您不容错过的重要事实

数据数组 是一个字符串,而不是一个对象。
API 需要一个字符串。 JSON始终将表单有效负载包裹在……中 JSON.stringify({...}) 发布前请注意,发送嵌套对象会返回反序列化错误。
键名必须与 AcroForm 字段名称完全匹配。
字段名称区分大小写。请使用 Adobe Acrobat 检查模板。 准备表格 或者先调用“提取表单数据”端点,以获取所有可填写字段的干净列表。
异步返回 202 + Location 标头
IsAsync: trueAPI 可能会响应 202 和 Location 标头。 GETURL (相同的授权)直到它返回 200 为止 PDF 二进制。标准 PDF4me 异步模式(pdf4meAsyncRequest)。

HTTP 设置

方法: 邮政
URL https://api.pdf4me.com/api/v2/FillPdfForm
内容类型: application/json
授权: 基本 <您的 PDF4me API 键>

发送 IsAsync: true 在体内。 200 返回已填充的内容 PDF 以二进制字节形式表示。 202 返回一个 地点 带有投票的标题 URLGETURL 使用相同的 Authorization 标头,直到返回 200 状态码为止。 PDF 二进制(与二进制相同) pdf4meAsyncRequest)。

变异矩阵(与 Postman 相关)

三种输入方式涵盖了所有 Postman / curl / SDK 调用。请选择与您的需求相匹配的输入方式。 PDF 模板和表单数据实时更新。

变体PDF模板(模板文档内容表单字段必填 API 字段
ABase64 PDFJSON object → stringify → dataArrayAll rows in the JSON-form table below.
BPublic PDF URLJSON object → stringify → dataArraySame as A; templateDocContent is the URL string.
CBase64 PDFBase64-encoded JSON file → decode → stringify into dataArraySame as A; build dataArray from the decoded JSON.

API 身体场

总是发送

场地必需的类型默认/备注
templateDocNameYes*stringFilename of the template, e.g. template.pdf. Derived from the source URL filename or defaulted to template.pdf. Used for downstream output naming.
templateDocContentYesstringBase64-encoded PDF (no data: prefix) OR a publicly reachable https URL to the PDF.
KeepPdfEditableNobooleanDefault false. Set true to keep AcroForm fields editable in the output PDF; false flattens the form into static text.
IsAsyncYesbooleanDefault true. Toggles the 200 / 202 + Location async pattern.

*模板文档名称 必须始终在请求中设置;选择一个合理的文件名,以便下游输出文件名清晰明了。

当表单输入是 JSON

场地必需的类型笔记
dataArrayYesstringJSON.stringify({ ... }). Keys = AcroForm field names; values = strings to fill.
inputDataTypeYesstringAlways "json" for this path.
outputTypeYesstringAlways "pdf".

表单数据规则(JSON 小路)

规则细节
ShapeSingle object: {"fieldName": "value", ...}.
Not allowedEmpty array, or an array of multiple objects.
Base64 form inputDecode the UTF-8 JSON file, then JSON.stringify into dataArray. In Postman: put the decoded-then-stringified result directly into dataArray.
Data URLStrip the data:...;base64, prefix if present (applies to the PDF Base64 in templateDocContent).

示例有效载荷

版本 A. PDF Base64 + 表单 JSON

{
"templateDocName": "application-form.pdf",
"templateDocContent": "JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZw...",
"dataArray": "{\"firstname\": \"John\", \"lastname\": \"Doe\", \"email\": \"[email protected]\"}",
"inputDataType": "json",
"outputType": "pdf",
"KeepPdfEditable": false,
"IsAsync": true
}

数据数组 必须是字符串,不能是嵌套字符串。 JSON 目的
"dataArray": "{"firstname":"John","lastname":"Doe"}"

方案 B. PDF URL + 表单 JSON

{
"templateDocName": "application-form.pdf",
"templateDocContent": "https://example.com/forms/application-form.pdf",
"dataArray": "{\"firstname\": \"John\", \"lastname\": \"Doe\", \"email\": \"[email protected]\"}",
"inputDataType": "json",
"outputType": "pdf",
"KeepPdfEditable": false,
"IsAsync": true
}

变体 C. PDF Base64 + 来自 base64 JSON 的表单

仓库中的占位符: eyJmaXJzdG5hbWUiOiJKb2huIn0={"firstname":"John"}

相等的 API 身体 解码表单后 JSON

{
"templateDocName": "application-form.pdf",
"templateDocContent": "JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZw...",
"dataArray": "{\"firstname\": \"John\"}",
"inputDataType": "json",
"outputType": "pdf",
"KeepPdfEditable": false,
"IsAsync": true
}

可选。保持表单可编辑

{
"templateDocName": "application-form.pdf",
"templateDocContent": "https://example.com/forms/application-form.pdf",
"dataArray": "{\"firstname\": \"John\", \"lastname\": \"Doe\"}",
"inputDataType": "json",
"outputType": "pdf",
"KeepPdfEditable": true,
"IsAsync": true
}

邮递员收款小贴士

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON. Copy one of the variant payloads above.
Response
Save as .pdf when status is 200 and the body is binary. If 202, GET the Location URL with the same Authorization until 200.
Field names
Must exactly match AcroForm names in the template. Use the Extract Form Data endpoint or a PDF editor if you are unsure.

curl 示例

curl -X POST https://api.pdf4me.com/api/v2/FillPdfForm \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"templateDocName": "application-form.pdf",
"templateDocContent": "https://example.com/forms/application-form.pdf",
"dataArray": "{\"firstname\":\"John\",\"lastname\":\"Doe\"}",
"inputDataType": "json",
"outputType": "pdf",
"KeepPdfEditable": false,
"IsAsync": true
}' \
--output filled-form.pdf

快速参考:必填项与可选项(Postman)

场地A (PDF b64)B(PDF URL)C(b64 格式 → JSON)
templateDocNameRequiredRequiredRequired
templateDocContentRequired (b64)Required (URL)Required (b64)
dataArrayRequiredRequiredRequired (from decoded JSON)
inputDataTypeRequired (json)Required (json)Required (json)
outputTypeRequired (pdf)Required (pdf)Required (pdf)
IsAsyncRequired (true)Required (true)Required (true)
KeepPdfEditableOptionalOptionalOptional

代码示例

常问问题

Why must dataArray be a stringified JSON, not a nested object?+
The API contract defines dataArray as a string field. The engine parses the string server-side. Sending a nested object returns a deserialization error. Always wrap your form values with JSON.stringify before posting.
What happens when KeepPdfEditable is true?+
The output PDF retains its AcroForm field definitions so the recipient can re-edit values in any PDF viewer. KeepPdfEditable false (the default) flattens the form into static text, useful for delivering a locked record of what was submitted.
How do I know the exact AcroForm field names?+
Open the template in Adobe Acrobat (Prepare Form), use any PDF editor with field inspection, or call the PDF4me Extract Form Data endpoint first. Keys in your dataArray JSON must match those names exactly, including case.
When should I use Variant B (PDF URL) over Variant A (Base64)?+
Use Variant B when the template is already hosted at a publicly reachable HTTPS URL. It avoids the Base64 size bloat (~33%) and is the simplest path for templates pinned in S3, CDN, or your own static asset host. Use Variant A when the template is private or local.
How does the async flow work?+
Send IsAsync true. If the API returns 200, the PDF binary is in the body. If it returns 202, read the Location response header for a poll URL. GET that URL with the same Authorization header. Continue polling (commonly 10s intervals up to 15 retries) until it returns 200 with the PDF.
Can I send an array of multiple form-data objects?+
No. The REST contract requires a single object inside dataArray (after JSON.stringify). To fill many forms, call the endpoint once per form.
My PDF Base64 has a data: prefix. Do I strip it?+
Yes. The API expects raw Base64 in templateDocContent. Strip any data:application/pdf;base64, prefix before posting.
How do I get back something other than PDF?+
You cannot. outputType is fixed to pdf for this endpoint. To rasterize the filled PDF into PNG / JPEG, chain a downstream PDF4me Convert PDF to Image call.

相关行动

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

获取帮助