跳到主要内容

生成文档(多个)

此端点的作用

PDF4me 生成文档(多个) 一次性渲染多个文档 REST 调用。发送单个单词, HTML, 或者 PDF 模板 (Base64URL或原始 HTML加上一系列记录(JSON 或者 XML以文本形式呈现, Base64 文件,或 URL返回一个 JSON 生成的文件列表(每条记录一个条目) Base64outputDocuments[].streamFile或者根据响应情况返回单个二进制值。

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

验证您的身份 API 要求

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

端点

邮政/api/v2/GenerateDocumentMultiple

端点名称是 GenerateDocumentMultiple (单数) 文档), 不是 生成多个文档

您不容错过的重要事实

一个模板,多条记录
发送 JSON 数组(或重复记录) XML)在您的数据有效负载中。引擎会为每个数组元素渲染一个输出文档,并将它们一起返回。
回应通常是 JSON outputDocuments[]
每个条目都有一个 文件名 以及 base64 流文件 (有时 文件内容内容, 或者 数据)解码每个 base64 字符串以保存文件。
与 Single 版本不同:不支持 CSV 和 xlsx 文件格式,模板类型较少。
模板类型仅限于 DocxHTMLPDF数据类型仅限于 JSONXML输出结果 xlsx 适用于 Word / PDF 模板。

HTTP 设置

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

发送 IsAsync: true 在体内。 200 可能会返回 JSONoutputDocuments[] 或者单个二进制文件。 202 返回一个 地点 带有投票的标题 URL

差异 vs 生成文档(单个)

话题多种的单身的
Endpoint/api/v2/GenerateDocumentMultiple/api/v2/GenerateDocumentSingle
templateFileTypeDocx, HTML, PDF onlyAlso MailMerge, GoogleDocs
documentDataTypeJson, XML onlyAlso Csv
outputTypePDF, Docx, xlsx (Word/PDF), HTMLNo xlsx
Data shapeTypically array of records (one doc per row)Usually one object
outputFileNameIntegration-UI only (output naming)Not in API body either

变异矩阵(与 Postman 相关)

模板 (templateFileData

代码来源邮递员的价值也需要
T1Base64Base64 template (strip data:...;base64, prefix if present)templateFileName
T2URLHTTPS URL stringtemplateFileName
T3HTML codeBase64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64")templateFileName, templateFileType: HTML

文档数据

代码来源API字段邮递员的价值
D1TextdocumentDataTextJSON array (or XML with multiple records)
D2Base64documentDataFileBase64 of the .json / .xml file
D3URLdocumentDataFileURL to the data file

使用任一 文档数据文本 或者 文档数据文件 (省略未使用的字段)。

templateFileType → 允许的输出类型

模板文件类型允许 输出类型
DocxPDF, Docx, xlsx
PDFPDF, Docx, xlsx
HTMLHTML only

API 身体场

总是发送

场地必需的类型笔记
templateFileTypeYesstringDocx, HTML, PDF
templateFileNameYesstringe.g. template.docx, template.html, template.pdf
templateFileDataYesstringBase64 template, or template URL
documentDataTypeYesstringJson or XML (exact casing)
outputTypeYesstringPDF, Docx, xlsx, or HTML
IsAsyncYesbooleantrue

文档数据(一条路径)

场地需要类型笔记
documentDataTextD1stringValid JSON (JSON.parse) or XML-like for XML
documentDataFileD2 or D3stringBase64 data file or URL

选修的

场地什么时候默认
KeepPdfEditableoutputType is PDFfalse

验证规则

查看细节
Template URL / base64Same rules as Single.
HTML codeOnly when templateFileType is HTML.
JSON textMust parse with JSON.parse.
XML textLooser than Single (no strict tag check); send XML the template expects.
Data sourcedocumentDataFile or documentDataText is required.

多记录数据形状

为了 JSON使用对象数组(每个生成的文档对应一个对象):

[
{ "name": "Alice", "email": "[email protected]" },
{ "name": "Bob", "email": "[email protected]" }
]

为了 XML使用模板期望的重复行结构(与邮件合并的原理相同)。 API 仅检查 JSON 解析;引擎决定生成多少文档。

API 回复(邮递员)

通常像这样的 JSON:

{
"outputDocuments": [
{
"fileName": "document1.pdf",
"streamFile": "<base64>"
}
]
}

字段名称也可能显示为 fileContentcontent, 或者 data解码每个 Base64 用于保存每个文件的字符串。

示例有效载荷

1. Word模板(base64编码)+ JSON 数组(文本)→ 多个 PDFs

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataText": "[{\"name\": \"Alice\", \"email\": \"[email protected]\"}, {\"name\": \"Bob\", \"email\": \"[email protected]\"}]",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}

2. Word模板(URL)+ JSON 数据 (URL)→ PDFs

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/customers.json",
"outputType": "PDF",
"IsAsync": true
}

3. Word模板(base64编码)+ JSON 文件(base64编码)→ Excel(xlsx)

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "W3sibmFtZSI6ICJBbGljZSJ9LCB7Im5hbWUiOiAiQm9iIn1d",
"outputType": "xlsx",
"IsAsync": true
}

documentDataFile = base64 [{"name":"Alice"},{"name":"Bob"}]。)

4. HTML 模板(base64)+ JSON 数组(文本)→ HTML

{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "[{\"title\": \"Invoice 1\", \"heading\": \"Hello\", \"content\": \"A\"}, {\"title\": \"Invoice 2\", \"heading\": \"Hi\", \"content\": \"B\"}]",
"outputType": "HTML",
"IsAsync": true
}

5. PDF 模板 (URL)+ XML (文本)→ 多个 PDFs

{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "https://example.com/template.pdf",
"documentDataType": "XML",
"documentDataText": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><records><record><name>Alice</name></record><record><name>Bob</name></record></records>",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}

6. Word模板(base64编码)+ XMLURL) → Word (Docx)

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "XML",
"documentDataFile": "https://example.com/data.xml",
"outputType": "Docx",
"IsAsync": true
}

邮递员收款小贴士

Array data
Prefer a JSON array in documentDataText when documentDataType is Json and you expect more than one file.
Filename match
Match the extension in templateFileName to templateFileType.
Base64 of file
For D2, base64-encode the whole data file (not each row separately).
Decode response
If the response is JSON, decode each outputDocuments[].streamFile (or fileContent / content / data) from base64.
Endpoint name
Endpoint name is GenerateDocumentMultiple (singular Document), not GenerateDocumentsMultiple.

curl 示例

curl -X POST https://api.pdf4me.com/api/v2/GenerateDocumentMultiple \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataText": "[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]",
"outputType": "PDF",
"IsAsync": true
}' \
--output response.json

快速参考:按变体划分的必需项与可选项

场地T1+D1T2+D3T1+D2T3+D1PDF 输出
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReqReqOmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt

*仅当 输出类型PDF

代码示例

常问问题

How is Multiple different from Single?+
Different endpoint (/api/v2/GenerateDocumentMultiple), fewer template types (Docx, HTML, PDF only), no CSV, can output xlsx, and expects array-shaped data to produce one document per record in a single call.
What does the response look like?+
Typically a JSON object with outputDocuments[], each containing fileName and streamFile (base64). Some responses may use fileContent, content, or data as the field name. Decode each base64 string to save the file.
Which output types are allowed?+
Docx and PDF templates accept PDF, Docx, or xlsx. HTML template accepts HTML only.
Does HTML output produce multiple files?+
Yes when the engine renders one HTML document per input record. The response still uses the outputDocuments[] shape.
What is the maximum array size?+
No published hard cap. Large batches usually push you onto the async path (202 + Location poll). For very large workloads, split into multiple calls of a few hundred records each.
Why is the endpoint name singular Document?+
The path is /api/v2/GenerateDocumentMultiple, not GenerateDocumentsMultiple. A common typo. The plural version returns 404.
Does KeepPdfEditable work for xlsx or HTML output?+
No. It only applies when outputType is PDF. For other outputs the API ignores it.
Can I mix multiple template files in one call?+
No. One call uses one template. To render the same data set against multiple templates, issue one call per template.

相关行动

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

获取帮助