Generate Documents (Multiple)
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.
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
/api/v2/GenerateDocumentMultipleEndpoint name is GenerateDocumentMultiple (singular Document), not GenerateDocumentsMultiple.
Important Facts You Should Not Miss
outputDocuments[]fileName and a base64 streamFile (sometimes fileContent, content, or data). Decode each base64 string to save the file.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)
| Topic | Multiple | Single |
|---|---|---|
| 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 |
Variant matrix (Postman-relevant)
Template (templateFileData)
| Code | Source | Postman value | Also required |
|---|---|---|---|
| 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 |
Document data
| Code | Source | API field | Postman value |
|---|---|---|---|
| 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 |
Use either documentDataText or documentDataFile (omit the unused field).
templateFileType → allowed outputType
templateFileType | Allowed outputType |
|---|---|
Docx | PDF, Docx, xlsx |
PDF | PDF, Docx, xlsx |
HTML | HTML only |
API body fields
Always sent
| Field | Required | Type | Notes |
|---|---|---|---|
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 |
Document data (one path)
| Field | Required when | Type | Notes |
|---|---|---|---|
documentDataText | D1 | string | Valid JSON (JSON.parse) or XML-like for XML |
documentDataFile | D2 or D3 | string | Base64 data file or URL |
Optional
| Field | When | Default |
|---|---|---|
KeepPdfEditable | outputType is PDF | false |
Validation rules
| Check | Detail |
|---|---|
| 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. |
Multiple-record data shape
For JSON, use an array of objects (one object per generated document):
[
]
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
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
| Field | T1+D1 | T2+D3 | T1+D2 | T3+D1 | PDF output |
|---|---|---|---|---|---|
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 |
*Only when outputType is PDF.