Skip to main content

Generate Documents (Multiple)

What this endpoint does

PDF4me Generate Documents (Multiple) renders many documents in one REST call. Send a single Word, HTML, or PDF template (Base64, URL, or raw HTML) plus an array of records (JSON or XML, as text, Base64 file, or URL). Returns a JSON list of generated files (one entry per record) as Base64 in outputDocuments[].streamFile, or a single binary depending on the response.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog →

Authenticating Your API Request

Every PDF4me REST call must include your API key in the Authorization header as Basic auth. Get or rotate your key from the developer dashboard.

Endpoint

POST/api/v2/GenerateDocumentMultiple

Endpoint name is GenerateDocumentMultiple (singular Document), not GenerateDocumentsMultiple.

Important Facts You Should Not Miss

One template, many records
Send a JSON array (or repeating-record XML) in your data payload. The engine renders one output document per array element and returns them together.
Response is usually JSON outputDocuments[]
Each entry has a fileName and a base64 streamFile (sometimes fileContent, content, or data). Decode each base64 string to save the file.
Differs from Single: no CSV, xlsx allowed, fewer template types
Template types limited to Docx, HTML, PDF. Data types limited to Json, XML. Output adds xlsx for Word / PDF templates.

HTTP setup

Method: POST
URL: https://api.pdf4me.com/api/v2/GenerateDocumentMultiple
Content-Type: application/json
Authorization: Basic <your PDF4me API key>

Send IsAsync: true in the body. 200 may return JSON with outputDocuments[] or a single binary file. 202 returns a Location header with a poll URL.

Differences vs Generate Document (Single)

TopicMultipleSingle
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

Variant matrix (Postman-relevant)

Template (templateFileData)

CodeSourcePostman valueAlso required
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

Document data

CodeSourceAPI fieldPostman value
D1TextdocumentDataTextJSON array (or XML with multiple records)
D2Base64documentDataFileBase64 of the .json / .xml file
D3URLdocumentDataFileURL to the data file

Use either documentDataText or documentDataFile (omit the unused field).

templateFileType → allowed outputType

templateFileTypeAllowed outputType
DocxPDF, Docx, xlsx
PDFPDF, Docx, xlsx
HTMLHTML only

API body fields

Always sent

FieldRequiredTypeNotes
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

Document data (one path)

FieldRequired whenTypeNotes
documentDataTextD1stringValid JSON (JSON.parse) or XML-like for XML
documentDataFileD2 or D3stringBase64 data file or URL

Optional

FieldWhenDefault
KeepPdfEditableoutputType is PDFfalse

Validation rules

CheckDetail
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.

Multiple-record data shape

For JSON, use an array of objects (one object per generated document):

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

For XML, use a structure your template expects for repeating rows (same idea as mail merge). The API only checks that JSON parses; the engine drives how many documents are produced.

API response (Postman)

Often JSON like:

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

Field name may also appear as fileContent, content, or data. Decode each Base64 string to save each file.

Sample payloads

1. Word template (base64) + JSON array (text) → multiple 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 template (URL) + JSON data (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 template (base64) + JSON file (base64) → Excel (xlsx)

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

(documentDataFile = base64 of [{"name":"Alice"},{"name":"Bob"}].)

4. HTML template (base64) + JSON array (text) → 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 template (URL) + XML (text) → multiple 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 template (base64) + XML (URL) → Word (Docx)

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

Postman collection tips

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 example

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

Quick reference: required vs optional by variant

FieldT1+D1T2+D3T1+D2T3+D1PDF output
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReqReqOmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt

*Only when outputType is PDF.

Code samples

FAQ

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.

Same task on other platforms

Get Help