跳到主要内容

生成文档(多个) n8n

生成多个文档 这是 n8n 中的一个 PDF4me 节点操作,在节点中显示为“生成文档(多个)”,它使用单个模板和记录数组,一次性生成多个最终文件。您可以将其用于批量生成发票、客户信函或区域报告,每个文档都会作为单独的 n8n 项返回。

此节点的功能

PDF4me生成文档(多个) 只需一个模板和一份记录列表,即可一次性生成多个成品文档。 n8n 运行。提供一个 单词, HTML, 或者 PDF 模板 通过二进制数据, Base64HTML 代码,或 URL批量数据 JSON 或者 XML (记录数组或重复) XML每个生成的文件都会作为单独的输出项返回,因此您可以循环执行、保存、通过电子邮件发送或单独上传它们的操作。请使用此节点代替 生成文档(单个) 当您有客户列表、发票或记录,并且希望在一次执行中为每一行生成一个完成的文档时。

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

验证您的身份 API 要求

每一个 PDF4me 节点 n8n 需要有效 用于连接的凭证创建或选择一个可以容纳您的 PDF4me API 关键在于确保工作流程能够安全地验证批量文档生成请求。

您不容错过的重要事实

n8n 每个生成的文档包含项目
一次成功的运行通常会返回多个项目,每个项目对应一个生成的文件。每个项目都包含二进制数据输出名称下的二进制文件。 JSON 使用 documentIndex 和 totalDocuments 等元数据,您可以循环、保存或通过电子邮件发送每个文件到下游。
传递一个数组(JSON)或重复 XML 所以 API 知道要渲染多少个文件
为了 JSON使用对象数组,每个生成的文档对应一个对象。 XML请使用模板所需的重复记录结构(邮件合并样式)。单个对象仅生成一个文档,这违背了此操作的初衷。
CSV这里不支持邮件合并和 Google 文档。
模板文件类型仅提供 Word 文档。 HTMLPDF文档数据类型仅提供 JSON 或者 XML如果您需要 CSV 如果要使用输入或邮件合并/Google 文档模板,请改用“生成文档(单个)”。
生成文档(多个)n8n 节点显示连接到 Pdf4me 的凭据,资源生成,生成操作生成文档(多个),模板文件类型 Word,输出类型 PDF,模板文件输入类型二进制数据,模板二进制属性数据,模板文件名 template.docx,文档数据类型 JSON,文档数据输入类型文本,示例文档数据文本,输出文件名 generated_document,保持 PDF 可编辑切换,二进制数据输出名称 data

完整节点面板。Word模板+ JSON 文本数据 + PDF 输出结果是典型的邮件合并设置。

生成文档(多个)与生成文档(单个)

这项任务中最常见的错误就是选错了其中一个选项。区别在于返回的文件数量以及可用的模板和数据格式。

方面生成文档(多个)生成文档(单个)
Files returnedMany, one n8n item per generated documentExactly one
Template typesWord, HTML, PDFWord, HTML, PDF, plus Mail Merge and Google Docs
Data formatsJSON or XML onlyJSON, XML, and CSV
Output typesPDF, Word, or Excel (HTML templates output HTML)PDF, Word (no Excel option)
Reach for it whenYou have a list of records and want one document per rowYou have a single record, CSV data, or a Mail Merge template

生成文档(多个)需要哪些参数?

必需 n8n 用户界面: 连接凭据、模板文件类型、模板文件输入类型、文档数据类型、文档数据输入类型和输出类型(始终显示,选项取决于模板文件类型)。条件必填字段(模板二进制属性、模板 Base64 内容, HTML 代码、模板文件 URL(例如,文档数据文本、文档二进制属性等)仅在选择其父输入类型时才会显示。输出文件名,保留 PDF 可编辑的二进制数据输出名称是可选的,并具有合理的默认值。

范围必需的它的作用例子
Template File TypeRequiredFormat 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 TypeRequiredFormat 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 TypeRequiredHow 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 PropertyConditionalName 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 ContentConditionalBase64-encoded template content. Required when Template File Input Type is Base64 String.UEsDBBQAAAAI...
HTML CodeConditionalRaw 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 URLConditionalPublicly reachable HTTPS URL to the template file. Required when Template File Input Type is URL.https://example.com/template.docx
Template File NameConditionalFilename 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 TypeRequiredFormat 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 TypeRequiredHow 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 TextConditionalRaw 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 PropertyConditionalName 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 NameConditionalFilename 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 ContentConditionalBase64-encoded data file. Required when Document Data Input Type is Base64 String.W3sibmFtZSI6...
Document Data File URLConditionalPublicly reachable HTTPS URL to the bulk data file. Required when Document Data Input Type is URL.https://example.com/customers.json
Output File NameOptionalPrefix 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 EditableOptionalOnly 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 NameOptionalName of the binary property each output item exposes. Default is data. Placeholder suggests generated-documents.data

模板文件类型选项

选择模板格式。输出类型选项会随此选择而改变。

n8n PDF4me“生成文档(多选)”节点中的“模板文件类型”下拉菜单显示三个选项:Word(高亮显示)、HTML 和 PDF。

模板文件类型下拉菜单。Word, HTML, 或者 PDF (这里不使用邮件合并或谷歌文档)

单词默认值:.docx 模板
标准 PDF4me 带有胡子占位符的 Word 模板。输出类型可以是…… PDFWord 或 Excel。最常用于批量开具发票、客户信函和个性化报告。
HTMLHTML 模板和粘贴 HTML 代码
渲染图 HTML 带有胡子占位符的模板。输出类型为 HTML 仅限与模板文件输入类型配对使用 HTML 粘贴原始代码 HTML 内联,或使用二进制数据 / URL 适用于托管的 .html 文件。
PDFPDF 模板
使用现有的 PDF 作为模板。输出类型可以是 PDF、Word 或 Excel。 PDF 输出,启用保留 PDF 如果您希望每个生成的文件中的字段都可编辑,则可以选择“可编辑”。

按模板输出类型

模板文件类型输出类型选项默认
WordPDF, Word, ExcelPDF
PDFPDF, Word, ExcelPDF
HTMLHTML onlyHTML

模板文件输入类型选项

选择模板进入节点的方式。后续字段会根据此选择而改变。

n8n PDF4me“生成文档(多选)”节点中的“模板文件输入类型”下拉菜单显示四个选项:二进制数据(高亮显示并附有说明):使用上一个节点中的模板文件;Base64字符串(附有说明):提供Base64编码的模板文件;HTML代码(附有说明):手动编写原始HTML代码(仅适用于HTML模板类型);URL(附有说明):提供模板文件的URL。

模板文件输入类型:二进制数据 Base64 细绳, HTML 代码,或 URL

二进制数据默认值:来自上一个节点的文件
直接从先前的节点(例如 Google 云端硬盘下载)读取模板, HTTP 请求或读取二进制文件。设置 模板二进制属性 二进制字段名称(默认值) 数据)。 模板文件名 是可选的,如果是,则默认使用上传的文件名。
Base64字符串Base64编码模板
将 base64 字符串粘贴或映射到 Base64 模板内容模板文件名 必须确保文件扩展名与模板文件类型(.docx、.html、.pdf)匹配。
HTML 代码糊状生料 HTML 排队 (HTML 仅有的)
仅当模板文件类型为 HTML粘贴全部或部分内容 HTML 带有占位符,例如 {{标题}}{{内容}} 进入 HTML 代码该节点将其包装在一个基本结构中。 <html> 如果缺少外壳,则执行 shell 操作。 模板文件名 是必需的(例如, template.html)。
URL从公共链接下载
提供 HTTPS URL模板文件 URLPDF4me 直接获取模板。 URL 必须开放(无需身份验证) 模板文件名 必须确保扩展名与模板类型匹配。

文档数据类型选项

选择您要发送的数据格式。

n8n PDF4me“生成文档(多个)”节点中的“文档数据类型”下拉菜单显示,JSON 高亮显示,XML 为两个选项。工具提示显示“参数 documentDataType”。

文档数据类型。 JSON 或者 XML (不 CSV 在此次操作中)

JSON默认值:记录数组(最常用)
使用 JSON 数组,其中每个对象都是一个生成的文档,例如: [{"name":"Alice"}, {"name":"Bob"}]该节点会验证有效负载是否能够解析。单个对象生成一个文档。如果需要生成多个文档,请传递一个数组。
XML重复录制 XML
使用 XML 模板中重复行的结构(邮件合并样式)符合要求。该节点不会执行深度验证。请确保 XML 与模板的绑定点匹配。

文档数据输入类型选项

选择批量数据进入节点的方式。

n8n PDF4me“生成文档(多个)”节点中的“文档数据输入类型”下拉菜单显示四个选项:文本高亮显示(带描述):手动输入 JSON 或 XML 数据;二进制数据(带描述):使用上一个节点的数据文件;Base64 字符串(带描述):提供 Base64 编码的数据文件;URL(带描述):提供数据文件的 URL。

文档数据输入类型:文本、二进制数据 Base64 字符串,或 URL

文本默认:直接粘贴批量数据
类型或表达式映射完整 JSON 数组或 XML 进入 文档数据文本当选择文本时,多选操作中此字段为必填项(比单选更严格)。
二进制数据使用来自先前节点的数据文件
文档二进制属性 二进制字段名称(默认值) 数据注意模板和数据二进制属性名称在来自同一项时不要冲突。
Base64字符串Base64编码数据文件
提供全部内容 .json 或者 .xml 文件格式为 base64 文档 Base64 内容文档数据文件名 是必须的。
URL从公共链接下载
文档数据文件 URL 对公众 HTTPS URLJSON 或者 XML 数据文件。 文档数据文件名 必须确保扩展名与数据类型匹配。

输出文件名行为

设想输出文件名生成的文件名
One document returnedinvoiceinvoice.pdf (extension added if missing)
Many documents returnedinvoiceinvoice_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 元数据和二进制文件。

场地类型它包含什么
successBooleanTrue when the document was generated successfully. Use to route error handling branches.
fileNameStringFilename of this generated document, e.g. invoice_2.pdf. Map into upload or email nodes.
mimeTypeStringMIME type of the output file, e.g. application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/html.
fileSizeNumberSize of the generated file in bytes.
documentIndexNumberIndex of this document within the batch (1-based). Useful for filenames or logging.
totalDocumentsNumberHow many documents were produced in this run. Same on every item.
Binary (data)BinaryThe generated document under Binary Data Output Name (default data). Pass to Write Binary File, Email, or any cloud-storage upload.

如何在 n8n 中设置生成文档(多个)?

  1. 添加 PDF4me 致你 n8n 工作流程。设置 资源产生生成操作生成文档(多个)
  2. 用于连接的凭证请选择您的 PDF4me 凭证或点击 创建新凭证 并粘贴你的 API 钥匙。
  3. 模板文件类型单词 (默认), HTML, 或者 PDF
  4. 输出类型PDFWord 或 Excel for Word / PDF 模板; HTML 仅限 HTML 模板。
  5. 模板文件输入类型二进制数据 (默认), Base64 细绳HTML 代码HTML 仅),或 URL 并填写匹配的模板字段 模板文件名 如有需要。
  6. 文档数据类型JSON (默认)或 XML
  7. 文档数据输入类型文本 (默认)并粘贴您的 JSON 将数组放入 文档数据文本或者选择二进制数据, Base64 字符串,或 URL 并提供数据文件。
  8. 输出文件名 变成类似这样易读的东西 invoice 因此,文件会返回为 invoice_1.pdfinvoice_2.pdf,……
  9. 如果输出 PDF 如果您的模板包含表单字段,请启用 保持 PDF 可编辑
  10. 离开 二进制数据输出名称 作为 data 除非下游节点需要不同的属性名称。执行该节点并将多个输出项路由到“分批拆分”、“写入二进制文件”、“通过电子邮件发送”或“上传到云存储”。

典型配置

工作流程示例Common n8n workflow patterns using Generate Documents (Multiple).
从 JSON 数组进行邮件合并。客户信函
  1. Google Sheets 节点将包含姓名、地址和余额的客户列表导入到工作流中。
  2. Code 或 Set 节点将行打包成一个整体。 JSON 对象数组(每个客户一个对象)。
  3. PDF4me 使用 Word 模板文件类型生成多个文档,输出类型 PDF模板文件输入类型为二进制数据,文档数据输入类型为文本。输出文件名是 客户信函
  4. 该节点为每个名为“客户”的用户返回一个项目。 客户信函 1.pdf客户信函 2.pdf, 等等。
  5. “循环遍历项目”节点会发送每个 PDF 通过 Gmail 发送给匹配的客户或上传到 Google 云端硬盘。
模板和数据均以文件形式存在 n8n
  1. 一个节点下载 .docx 模板;另一个节点下载 .json 客户文件。合并节点将它们合并,使两个二进制文件都保存在同一个条目中。
  2. PDF4me “生成文档(多个)”配置为使用模板文件输入类型二进制数据(模板二进制属性 设置为模板字段名称)和文档数据输入类型二进制数据(文档二进制属性 设置为数据字段名称)。
  3. 文档数据文件名 如果数据文件未命名 data.json
  4. 生成的文件将作为单独的项目返回,并写入到 SharePoint 以客户 ID 命名的文档库。
托管模板 + 托管数据。发票批量处理
  1. 每晚的计划触发器会触发发票批处理运行。
  2. PDF4me “生成文档(多个)”设置为“模板文件输入类型”。 URL模板文件 URL 指向 S3 上的 .docx 发票模板)和文档数据输入类型 URL文档数据文件 URL 指向生成的 计费周期.json 文件)。
  3. 模板文件名发票.docx文档数据文件名计费周期.json
  4. 输出类型为 PDF输出文件名是 发票并保持 PDF 可编辑功能已关闭。
  5. 每件退回的商品都会上传到客户在 Dropbox 中的文件夹,并通过 Outlook 通过电子邮件发送。
从粘贴的代码批量生成 HTML → 个性化落地页
  1. Webhook触发器会在营销活动启动时触发。
  2. PDF4me “生成文档(多个)”设置为“模板文件类型”。 HTML 和模板文件输入类型 HTML 代码。 HTML 直接粘贴到带有 Mustache 占位符的节点中。
  3. 文档数据类型是 JSON文档数据输入类型为文本,表达式将营销活动的潜在客户列表映射到 JSON 大批。
  4. 输出类型为 HTML该节点返回一个 HTML 每个线索一个文件。
  5. “写入二进制文件”节点会保存每个生成的二进制文件。 HTML 发送到公共网络文件夹;另一个节点将个性化链接发送给每个潜在客户。
从 Word 模板生成 Excel 输出。批量报告
  1. 每日计划触发器从 PostgreSQL 中提取 KPI 数据。
  2. 集合节点按区域将行分组到一个集合中 JSON 数组,每个区域一条记录。
  3. PDF4me 使用模板文件类型 Word、输出类型 Excel、文档数据类型,运行“生成文档(多次)”程序,生成多个文档。 JSON文档数据输入类型为文本。输出文件名是 区域报告
  4. 该节点为每个区域返回一个 .xlsx 文件,名称为 region_report_1.xlsxregion_report_2.xlsx, 等等。
  5. Microsoft OneDrive 节点会将每个文件上传到分析团队对应的区域文件夹。

实用技巧

Shape your data as rows
One record per output document. Single objects yield one file. defeats the purpose of this operation.
Use Generate Document (Single) for CSV / Mail Merge / Google Docs
Generate Documents (Multiple) only accepts JSON or XML data and Word / HTML / PDF templates.
"No binary data found" errors
Double-check Template Binary Property and Document Binary Property names. The Merge node from a fan-in workflow can rename binary properties.
Document Data Text is strictly required
On the Multiple operation, leaving the Text field empty rejects the node, stricter than Single.
Name outputs with a meaningful prefix
Use Output File Name like <code>invoice</code> or <code>customer_letter</code> so files are easy to scan in storage (avoid the generic <code>generated_document_*</code> default).
Plan for multiple items downstream
Use Split In Batches, Loop Over Items, or any node that handles many items. not just the first one.

速查表

场地价值
ResourceGenerate
OperationGenerate Documents (Multiple)
Template File TypeWord
Output TypePDF
Template File Input TypeBinary Data
Template Binary Propertydata
Document Data TypeJSON
Document Data Input TypeText
Document Data Text(bulk JSON array with multiple records)
Output File Namemy_document (optional, becomes prefix)
Binary Data Output Namedata
CredentialsPDF4me API credential

常见问题解答

How is Generate Documents (Multiple) different from Generate Document (Single)?+
Multiple renders many documents per run, one n8n item per generated document. Single produces exactly one file. Multiple supports fewer template types (Word, HTML, PDF only, no Mail Merge or Google Docs), only JSON or XML data (no CSV), and adds Excel as an output option for Word and PDF templates. Use Single for one-off documents, CSV data, Mail Merge, Google Docs, or PDF form templates.
What shape should my JSON data have?+
A JSON array where each object becomes one generated document, e.g. [{"name":"Alice","email":"[email protected]"},{"name":"Bob","email":"[email protected]"}] generates two files. The node validates that the payload parses; the API drives how many documents are produced based on the records you pass.
What does Output File Name do when many documents come back?+
It becomes a prefix. Setting Output File Name to invoice with Output Type PDF produces invoice_1.pdf, invoice_2.pdf, ... If you leave it empty, filenames come from the API or default to generated_document_1, generated_document_2, ...
Can I use CSV data with Generate Documents (Multiple)?+
No. Document Data Type only offers JSON and XML on this operation. Use Generate Document (Single) for CSV input or any other workflow that needs CSV.
How do I handle the multiple output items in n8n downstream?+
Each generated document is its own n8n item with the binary file under Binary Data Output Name (default data) and metadata fields like documentIndex and totalDocuments. Wire the node into Split In Batches, Loop Over Items, Write Binary File, or any cloud-storage / email node. they iterate over all items automatically.
Can I keep generated PDFs editable?+
Yes. Enable Keep PDF Editable when Output Type is PDF. Every generated PDF in the batch keeps its AcroForm field definitions. With Keep PDF Editable off, the form is flattened to static text on each file.
What happens if the API returns a single file instead of a list?+
You will get one n8n item only. Downstream nodes that already handle multiple items behave correctly for the single-item case. Always design the rest of the flow to handle 1..N items, not exactly N.
My data file is not named data.json. does it matter?+
When using Binary Data input, set Document Data File Name explicitly so the API treats the payload with the correct extension. Same applies to the template: use Template File Name when the binary does not carry a recognisable filename.

相关操作

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

获取帮助