March 20, 20268 min read
Batch PDF Generation: Converting 1,000 Documents in Minutes
How to generate hundreds or thousands of PDFs efficiently using batch processing, async queues, and parallel execution.
batchperformanceasynctutorial
The challenge
You need to generate 500 invoices, 1,000 shipping labels, or 10,000 certificates. Doing this sequentially — one API call at a time — would take hours. You need parallel processing.
Using the batch API
const response = await fetch('https://pdfrelay.com/api/v1/batch', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json',
},
body: JSON.stringify({
items: invoices.map(inv => ({
source: 'html',
content: renderInvoiceHTML(inv),
hosting: { enabled: true },
})),
}),
});
const { batch_id, poll_url } = await response.json();
The batch API processes up to 100 items per request. All items are processed in parallel by the worker pool. Poll the status endpoint to track progress.
Mixing types in a batch
A single batch can contain different conversion types:
{
"items": [
{ "source": "html", "content": "<h1>Invoice</h1>..." },
{ "source": "url", "url": "https://dashboard.example.com/report" },
{ "type": "render", "template": "certificate", "data": { "name": "Jane" } },
{ "type": "compose", "parts": [
{ "template": "cover-page", "data": { "title": "Q1 Report" } },
{ "html": "<h2>Chapter 1</h2>..." }
]}
]
}
HTML, URLs, templates, and multi-part composed documents — all in one batch. Each rendered by the same Rust engine, no browser required.