生成文档(多个)
PDF4me 生成文档(多个) 一次性渲染多个文档 REST 调用。发送单个单词, HTML, 或者 PDF 模板 (Base64, URL或原始 HTML加上一系列记录(JSON 或者 XML以文本形式呈现, Base64 文件,或 URL返回一个 JSON 生成的文件列表(每条记录一个条目) Base64 在 outputDocuments[].streamFile或者根据响应情况返回单个二进制值。
验证您的身份 API 要求
每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。
端点
/api/v2/GenerateDocumentMultiple端点名称是 GenerateDocumentMultiple (单数) 文档), 不是 生成多个文档。
您不容错过的重要事实
outputDocuments[]文件名 以及 base64 流文件 (有时 文件内容, 内容, 或者 数据)解码每个 base64 字符串以保存文件。Docx, HTML, PDF数据类型仅限于 JSON, XML输出结果 xlsx 适用于 Word / PDF 模板。HTTP 设置
方法: 邮政
URL: https://api.pdf4me.com/api/v2/GenerateDocumentMultiple
内容类型: application/json
授权: 基本 <您的 PDF4me API 键>
发送 IsAsync: true 在体内。 200 可能会返回 JSON 和 outputDocuments[] 或者单个二进制文件。 202 返回一个 地点 带有投票的标题 URL。
差异 vs 生成文档(单个)
| 话题 | 多种的 | 单身的 |
|---|---|---|
| Endpoint | /api/v2/GenerateDocumentMultiple | /api/v2/GenerateDocumentSingle |
| templateFileType | Docx, HTML, PDF only | Also MailMerge, GoogleDocs |
| documentDataType | Json, XML only | Also Csv |
| outputType | PDF, Docx, xlsx (Word/PDF), HTML | No xlsx |
| Data shape | Typically array of records (one doc per row) | Usually one object |
| outputFileName | Integration-UI only (output naming) | Not in API body either |
变异矩阵(与 Postman 相关)
模板 (templateFileData)
| 代码 | 来源 | 邮递员的价值 | 也需要 |
|---|---|---|---|
| T1 | Base64 | Base64 template (strip data:...;base64, prefix if present) | templateFileName |
| T2 | URL | HTTPS URL string | templateFileName |
| T3 | HTML code | Base64(UTF-8 HTML): Buffer.from(html, "utf8").toString("base64") | templateFileName, templateFileType: HTML |
文档数据
| 代码 | 来源 | API字段 | 邮递员的价值 |
|---|---|---|---|
| D1 | Text | documentDataText | JSON array (or XML with multiple records) |
| D2 | Base64 | documentDataFile | Base64 of the .json / .xml file |
| D3 | URL | documentDataFile | URL to the data file |
使用任一 文档数据文本 或者 文档数据文件 (省略未使用的字段)。
templateFileType → 允许的输出类型
模板文件类型 | 允许 输出类型 |
|---|---|
Docx | PDF, Docx, xlsx |
PDF | PDF, Docx, xlsx |
HTML | HTML only |
API 身体场
总是发送
| 场地 | 必需的 | 类型 | 笔记 |
|---|---|---|---|
templateFileType | Yes | string | Docx, HTML, PDF |
templateFileName | Yes | string | e.g. template.docx, template.html, template.pdf |
templateFileData | Yes | string | Base64 template, or template URL |
documentDataType | Yes | string | Json or XML (exact casing) |
outputType | Yes | string | PDF, Docx, xlsx, or HTML |
IsAsync | Yes | boolean | true |
文档数据(一条路径)
| 场地 | 需要 | 类型 | 笔记 |
|---|---|---|---|
documentDataText | D1 | string | Valid JSON (JSON.parse) or XML-like for XML |
documentDataFile | D2 or D3 | string | Base64 data file or URL |
选修的
| 场地 | 什么时候 | 默认 |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
验证规则
| 查看 | 细节 |
|---|---|
| Template URL / base64 | Same rules as Single. |
| HTML code | Only when templateFileType is HTML. |
| JSON text | Must parse with JSON.parse. |
| XML text | Looser than Single (no strict tag check); send XML the template expects. |
| Data source | documentDataFile or documentDataText is required. |
多记录数据形状
为了 JSON使用对象数组(每个生成的文档对应一个对象):
[
]
为了 XML使用模板期望的重复行结构(与邮件合并的原理相同)。 API 仅检查 JSON 解析;引擎决定生成多少文档。
API 回复(邮递员)
通常像这样的 JSON:
{
"outputDocuments": [
{
"fileName": "document1.pdf",
"streamFile": "<base64>"
}
]
}
字段名称也可能显示为 fileContent, content, 或者 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编码)+ XML (URL) → Word (Docx)
{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "XML",
"documentDataFile": "https://example.com/data.xml",
"outputType": "Docx",
"IsAsync": true
}
邮递员收款小贴士
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+D1 | T2+D3 | T1+D2 | T3+D1 | PDF 输出 |
|---|---|---|---|---|---|
templateFileType | Req | Req | Req | Req | Req |
templateFileName | Req | Req | Req | Req | Req |
templateFileData | Req (b64) | Req (URL) | Req (b64) | Req (b64) | Req |
documentDataType | Req | Req | Req | Req | Req |
outputType | Req | Req | Req | Req | Req |
documentDataText | Req | Omit | Omit | Req | Omit |
documentDataFile | Omit | Req | Req | Omit | Omit |
IsAsync | Req | Req | Req | Req | Req |
KeepPdfEditable | Opt | Opt | Opt | N/A* | Opt |
*仅当 输出类型 是 PDF。