生成文档(多个) n8n
生成多个文档 这是 n8n 中的一个 PDF4me 节点操作,在节点中显示为“生成文档(多个)”,它使用单个模板和记录数组,一次性生成多个最终文件。您可以将其用于批量生成发票、客户信函或区域报告,每个文档都会作为单独的 n8n 项返回。
此节点的功能
PDF4me生成文档(多个) 只需一个模板和一份记录列表,即可一次性生成多个成品文档。 n8n 运行。提供一个 单词, HTML, 或者 PDF 模板 通过二进制数据, Base64, HTML 代码,或 URL 加 批量数据 JSON 或者 XML (记录数组或重复) XML每个生成的文件都会作为单独的输出项返回,因此您可以循环执行、保存、通过电子邮件发送或单独上传它们的操作。请使用此节点代替 生成文档(单个) 当您有客户列表、发票或记录,并且希望在一次执行中为每一行生成一个完成的文档时。
验证您的身份 API 要求
每一个 PDF4me 节点 n8n 需要有效 用于连接的凭证创建或选择一个可以容纳您的 PDF4me API 关键在于确保工作流程能够安全地验证批量文档生成请求。
您不容错过的重要事实
/generate-documents-multiple-full.png)
完整节点面板。Word模板+ JSON 文本数据 + PDF 输出结果是典型的邮件合并设置。
生成文档(多个)与生成文档(单个)
这项任务中最常见的错误就是选错了其中一个选项。区别在于返回的文件数量以及可用的模板和数据格式。
| 方面 | 生成文档(多个) | 生成文档(单个) |
|---|---|---|
| Files returned | Many, one n8n item per generated document | Exactly one |
| Template types | Word, HTML, PDF | Word, HTML, PDF, plus Mail Merge and Google Docs |
| Data formats | JSON or XML only | JSON, XML, and CSV |
| Output types | PDF, Word, or Excel (HTML templates output HTML) | PDF, Word (no Excel option) |
| Reach for it when | You have a list of records and want one document per row | You have a single record, CSV data, or a Mail Merge template |
生成文档(多个)需要哪些参数?
必需 n8n 用户界面: 连接凭据、模板文件类型、模板文件输入类型、文档数据类型、文档数据输入类型和输出类型(始终显示,选项取决于模板文件类型)。条件必填字段(模板二进制属性、模板 Base64 内容, HTML 代码、模板文件 URL(例如,文档数据文本、文档二进制属性等)仅在选择其父输入类型时才会显示。输出文件名,保留 PDF 可编辑的二进制数据输出名称是可选的,并具有合理的默认值。
| 范围 | 必需的 | 它的作用 | 例子 |
|---|---|---|---|
| Template File Type | Required | Format of the template the node will render. Word for .docx templates, HTML for HTML templates (including pasted code), PDF for PDF templates. There is no Mail Merge, Google Docs, or PDF form option here; use Generate Document (Single) for those. | Word |
| Output Type | Required | Format of every generated document. Word and PDF templates accept PDF, Word, or Excel. HTML templates accept HTML only. Default is PDF when available. | PDF |
| Template File Input Type | Required | How the template is supplied. Binary Data reads from a previous node (most common). Base64 String accepts an encoded template. HTML Code accepts pasted raw HTML (only valid when Template File Type is HTML). URL downloads the template from a public link. | Binary Data |
| Template Binary Property | Conditional | Name of the binary property on the incoming n8n item that holds the template. Required when Template File Input Type is Binary Data. Defaults to data. | data |
| Template Base64 Content | Conditional | Base64-encoded template content. Required when Template File Input Type is Base64 String. | UEsDBBQAAAAI... |
| HTML Code | Conditional | Raw HTML body (mustache placeholders such as {{title}} are supported). Required when Template File Input Type is HTML Code, which is only valid for Template File Type HTML. The node wraps the snippet in a basic <html> shell if missing. | <h1>{{title}}</h1> |
| Template File URL | Conditional | Publicly reachable HTTPS URL to the template file. Required when Template File Input Type is URL. | https://example.com/template.docx |
| Template File Name | Conditional | Filename of the template. Optional with Binary Data (falls back to the uploaded filename or a sensible default such as template.docx, template.html, template.pdf). Required for Base64 String, HTML Code, and URL. | template.docx |
| Document Data Type | Required | Format of the bulk records you are sending. JSON for arrays of objects (most common). XML for repeating-record XML. CSV is not available on this operation. | JSON |
| Document Data Input Type | Required | How the bulk data is supplied. Text is the default (paste JSON or XML directly). Binary Data reads from a previous node. Base64 String accepts an encoded data file. URL downloads the data file from a public link. | Text |
| Document Data Text | Conditional | Raw bulk JSON or XML payload. Required when Document Data Input Type is Text. The node validates that JSON parses; XML is sent as-is. Use an array of objects in JSON so the API renders many files. | [{"name":"Alice"},{"name":"Bob"}] |
| Document Binary Property | Conditional | Name of the binary property on the incoming n8n item that holds the data file. Required when Document Data Input Type is Binary Data. Defaults to data. | data |
| Document Data File Name | Conditional | Filename for the bulk data file. Optional with Binary Data (falls back to data.json). Required when Document Data Input Type is Base64 String or URL. | customers.json |
| Document Base64 Content | Conditional | Base64-encoded data file. Required when Document Data Input Type is Base64 String. | W3sibmFtZSI6... |
| Document Data File URL | Conditional | Publicly reachable HTTPS URL to the bulk data file. Required when Document Data Input Type is URL. | https://example.com/customers.json |
| Output File Name | Optional | Prefix for the generated filenames. The node appends _1, _2, ... and the correct extension. Example: invoice becomes invoice_1.pdf, invoice_2.pdf. Leave blank to use API-provided names or generated_document_1, generated_document_2, ... | invoice |
| Keep PDF Editable | Optional | Only shown when Output Type is PDF. Keeps AcroForm fields editable on every generated PDF when enabled. Default is off (flattened output). | Off |
| Binary Data Output Name | Optional | Name of the binary property each output item exposes. Default is data. Placeholder suggests generated-documents. | data |
模板文件类型选项
选择模板格式。输出类型选项会随此选择而改变。
/generate-documents-multiple-template-file-type.png)
模板文件类型下拉菜单。Word, HTML, 或者 PDF (这里不使用邮件合并或谷歌文档)
单词默认值:.docx 模板HTMLHTML 模板和粘贴 HTML 代码PDFPDF 模板按模板输出类型
| 模板文件类型 | 输出类型选项 | 默认 |
|---|---|---|
| Word | PDF, Word, Excel | |
| PDF, Word, Excel | ||
| HTML | HTML only | HTML |
模板文件输入类型选项
选择模板进入节点的方式。后续字段会根据此选择而改变。
/generate-documents-multiple-template-file-input-type.png)
模板文件输入类型:二进制数据 Base64 细绳, HTML 代码,或 URL
二进制数据默认值:来自上一个节点的文件模板二进制属性 二进制字段名称(默认值) 数据)。 模板文件名 是可选的,如果是,则默认使用上传的文件名。Base64字符串Base64编码模板Base64 模板内容。 模板文件名 必须确保文件扩展名与模板文件类型(.docx、.html、.pdf)匹配。HTML 代码糊状生料 HTML 排队 (HTML 仅有的){{标题}}, {{内容}} 进入 HTML 代码该节点将其包装在一个基本结构中。 <html> 如果缺少外壳,则执行 shell 操作。 模板文件名 是必需的(例如, template.html)。URL从公共链接下载模板文件 URL。 PDF4me 直接获取模板。 URL 必须开放(无需身份验证) 模板文件名 必须确保扩展名与模板类型匹配。文档数据类型选项
选择您要发送的数据格式。
/generate-documents-multiple-document-data-type.png)
文档数据类型。 JSON 或者 XML (不 CSV 在此次操作中)
JSON默认值:记录数组(最常用)[{"name":"Alice"}, {"name":"Bob"}]该节点会验证有效负载是否能够解析。单个对象生成一个文档。如果需要生成多个文档,请传递一个数组。XML重复录制 XML文档数据输入类型选项
选择批量数据进入节点的方式。
/generate-documents-multiple-document-data-input-type.png)
文档数据输入类型:文本、二进制数据 Base64 字符串,或 URL
文本默认:直接粘贴批量数据文档数据文本当选择文本时,多选操作中此字段为必填项(比单选更严格)。二进制数据使用来自先前节点的数据文件文档二进制属性 二进制字段名称(默认值) 数据注意模板和数据二进制属性名称在来自同一项时不要冲突。Base64字符串Base64编码数据文件.json 或者 .xml 文件格式为 base64 文档 Base64 内容。 文档数据文件名 是必须的。URL从公共链接下载文档数据文件 URL 对公众 HTTPS URL 的 JSON 或者 XML 数据文件。 文档数据文件名 必须确保扩展名与数据类型匹配。输出文件名行为
| 设想 | 输出文件名 | 生成的文件名 |
|---|---|---|
| One document returned | invoice | invoice.pdf (extension added if missing) |
| Many documents returned | invoice | invoice_1.pdf, invoice_2.pdf, invoice_3.pdf, ... |
| Many documents, name left empty | (empty) | API-provided names or generated_document_1, generated_document_2, ... |
输出字段
一次成功的运行返回一个 n8n 每个生成的文档包含一个条目。每个条目包含两个信息。 JSON 元数据和二进制文件。
| 场地 | 类型 | 它包含什么 |
|---|---|---|
success | Boolean | True when the document was generated successfully. Use to route error handling branches. |
fileName | String | Filename of this generated document, e.g. invoice_2.pdf. Map into upload or email nodes. |
mimeType | String | MIME type of the output file, e.g. application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/html. |
fileSize | Number | Size of the generated file in bytes. |
documentIndex | Number | Index of this document within the batch (1-based). Useful for filenames or logging. |
totalDocuments | Number | How many documents were produced in this run. Same on every item. |
Binary (data) | Binary | The generated document under Binary Data Output Name (default data). Pass to Write Binary File, Email, or any cloud-storage upload. |
如何在 n8n 中设置生成文档(多个)?
- 添加 PDF4me 致你 n8n 工作流程。设置 资源 到 产生 和 生成操作 到 生成文档(多个)。
- 在 用于连接的凭证请选择您的 PDF4me 凭证或点击 创建新凭证 并粘贴你的 API 钥匙。
- 放 模板文件类型 到 单词 (默认), HTML, 或者 PDF。
- 放 输出类型。 PDFWord 或 Excel for Word / PDF 模板; HTML 仅限 HTML 模板。
- 放 模板文件输入类型 到 二进制数据 (默认), Base64 细绳, HTML 代码 (HTML 仅),或 URL 并填写匹配的模板字段 模板文件名 如有需要。
- 放 文档数据类型 到 JSON (默认)或 XML。
- 放 文档数据输入类型 到 文本 (默认)并粘贴您的 JSON 将数组放入 文档数据文本或者选择二进制数据, Base64 字符串,或 URL 并提供数据文件。
- 放 输出文件名 变成类似这样易读的东西
invoice因此,文件会返回为invoice_1.pdf,invoice_2.pdf,…… - 如果输出 PDF 如果您的模板包含表单字段,请启用 保持 PDF 可编辑。
- 离开 二进制数据输出名称 作为
data除非下游节点需要不同的属性名称。执行该节点并将多个输出项路由到“分批拆分”、“写入二进制文件”、“通过电子邮件发送”或“上传到云存储”。
典型配置
工作流程示例Common n8n workflow patterns using Generate Documents (Multiple).
- Google Sheets 节点将包含姓名、地址和余额的客户列表导入到工作流中。
- Code 或 Set 节点将行打包成一个整体。 JSON 对象数组(每个客户一个对象)。
- PDF4me 使用 Word 模板文件类型生成多个文档,输出类型 PDF模板文件输入类型为二进制数据,文档数据输入类型为文本。输出文件名是
客户信函。 - 该节点为每个名为“客户”的用户返回一个项目。
客户信函 1.pdf,客户信函 2.pdf, 等等。 - “循环遍历项目”节点会发送每个 PDF 通过 Gmail 发送给匹配的客户或上传到 Google 云端硬盘。
- 一个节点下载 .docx 模板;另一个节点下载 .json 客户文件。合并节点将它们合并,使两个二进制文件都保存在同一个条目中。
- PDF4me “生成文档(多个)”配置为使用模板文件输入类型二进制数据(
模板二进制属性设置为模板字段名称)和文档数据输入类型二进制数据(文档二进制属性设置为数据字段名称)。 - 放
文档数据文件名如果数据文件未命名data.json。 - 生成的文件将作为单独的项目返回,并写入到 SharePoint 以客户 ID 命名的文档库。
- 每晚的计划触发器会触发发票批处理运行。
- PDF4me “生成文档(多个)”设置为“模板文件输入类型”。 URL (
模板文件 URL指向 S3 上的 .docx 发票模板)和文档数据输入类型 URL (文档数据文件 URL指向生成的计费周期.json文件)。 模板文件名是发票.docx和文档数据文件名是计费周期.json。- 输出类型为 PDF输出文件名是
发票并保持 PDF 可编辑功能已关闭。 - 每件退回的商品都会上传到客户在 Dropbox 中的文件夹,并通过 Outlook 通过电子邮件发送。
- Webhook触发器会在营销活动启动时触发。
- PDF4me “生成文档(多个)”设置为“模板文件类型”。 HTML 和模板文件输入类型 HTML 代码。 HTML 直接粘贴到带有 Mustache 占位符的节点中。
- 文档数据类型是 JSON文档数据输入类型为文本,表达式将营销活动的潜在客户列表映射到 JSON 大批。
- 输出类型为 HTML该节点返回一个 HTML 每个线索一个文件。
- “写入二进制文件”节点会保存每个生成的二进制文件。 HTML 发送到公共网络文件夹;另一个节点将个性化链接发送给每个潜在客户。
- 每日计划触发器从 PostgreSQL 中提取 KPI 数据。
- 集合节点按区域将行分组到一个集合中 JSON 数组,每个区域一条记录。
- PDF4me 使用模板文件类型 Word、输出类型 Excel、文档数据类型,运行“生成文档(多次)”程序,生成多个文档。 JSON文档数据输入类型为文本。输出文件名是
区域报告。 - 该节点为每个区域返回一个 .xlsx 文件,名称为
region_report_1.xlsx,region_report_2.xlsx, 等等。 - Microsoft OneDrive 节点会将每个文件上传到分析团队对应的区域文件夹。
实用技巧
速查表
| 场地 | 价值 |
|---|---|
| Resource | Generate |
| Operation | Generate Documents (Multiple) |
| Template File Type | Word |
| Output Type | PDF |
| Template File Input Type | Binary Data |
| Template Binary Property | data |
| Document Data Type | JSON |
| Document Data Input Type | Text |
| Document Data Text | (bulk JSON array with multiple records) |
| Output File Name | my_document (optional, becomes prefix) |
| Binary Data Output Name | data |
| Credentials | PDF4me API credential |
常见问题解答
相关操作
在其他平台上执行相同任务
POST /api/v2/GenerateDocumentMultiple 端点,用于自定义后端代码或 Postman 测试。