Batch Document Generation: How to generate a document using multiple templates
Batch document generation allows you to combine multiple templates with dynamic data to create customized documents. Whether it's merging contracts, invoices, or reports, users can easily assemble different templates as needed, with the result delivered as a base64-encoded file or a public URL for quick access.
Prerequisites
Before proceeding, please ensure you are familiar with the basic setup process for Postman. If you have not configured Postman or downloaded our collection, please review the following guide first:
Step 1: Authentication
This process utilizes Bearer Token authentication. Your request must include a valid JSON Web Token (JWT) in the authorization header.
For detailed instructions on creating a temporary token for testing and development, please refer to our guide on How to Create a JSON Web Token (JWT).
In Postman, navigate to the Authorization tab and select "Bearer Token" from the type drop-down, then paste your token into the corresponding field.
Step 2: Configuring the API Request
The core of batch generation lies in structuring the request body to include multiple template and data pairs.
Endpoint Details
- HTTP Method:
POST
- Request URL:
https://us1.pdfgeneratorapi.com/api/v4/documents/generate/batch
For more details, check our documentation.
Request Body
The primary difference between single and batch generation is the structure of the JSON body. For batch requests, the template
key must be an array of objects. Each object in the array represents a single document to be generated and must contain a template id
and its corresponding data
payload.
In this example, we will merge a Certificate and a Delivery Note into a single output file.
id
values used in the example below are for demonstration purposes only. You must replace them with the actual IDs from your workspace.{
"template": [
{
"id": "1458495",
"data": {
"Name": "John Smith",
"DueDate": "2000-01-01"
}
},
{
"id": "1458496",
"data": {
"billing_address": {
"company": "Innovate Inc.",
"address1": "456 Oak Avenue",
"city": "Metropolis",
"country": "United States",
"country_code": "US"
},
"customer_memo": "Thank you for your order! Please include a gift receipt.",
"date": "2025-07-16",
"line_items": [
{
"name": "Premium Coffee Beans",
"quantity": 2,
"grams": 150
},
{
"name": "Large Cast Iron Skillet",
"quantity": 1,
"grams": 1200
},
{
"name": "Artisanal Chocolate Bar",
"quantity": 5,
"grams": 50
},
{
"name": "Stainless Steel Water Bottle",
"quantity": 1,
"grams": 450
},
{
"name": "Organic Tea Bags (Box of 20)",
"quantity": 3,
"grams": 100
},
{
"name": "A5 Hardcover Notebook",
"quantity": 2,
"grams": 350
}
],
"name": "John Smith",
"order_number": "1042",
"shipping_address": {
"company": "Innovate Inc.",
"address1": "456 Oak Avenue",
"city": "Metropolis",
"country": "United States",
"country_code": "US"
}
}
}
],
"format": "pdf",
"output": "url",
"name": "My First Batch Document Generation",
"testing": false
}
Step 3: Executing the Request and Handling the Response
After sending the request, the API will process both templates and merge them into a single file. Because we specified "output": "url"
in the request body, a successful response will contain a JSON object with a public URL to the generated PDF document.
The resulting document will contain the rendered Certificate followed by the Delivery Note.
API Usage and Billing
template
array. The example request above contains two templates, so it will consume two merges from your monthly allowance. For more information, please see: How is the monthly usage calculated?Related articles you may find helpful
- How to embed editor to my application?
- How to share templates with other workspaces?
- How to use the editor?
Updated on: 28/07/2025
Thank you!