Batch PDF Generation API: Webhooks and Async Calls
Updated by Cyril Nicodème
For a batch, call PDFShift asynchronously: add a webhook URL to each request, the call answers "queued" at once, and PDFShift posts a link to each finished PDF to your server. In our test, 40 invoices sent 10 at a time with webhooks were all back in 6.3 seconds. Sending them one by one and waiting for each took 108.8 seconds.
How does async PDF generation with a webhook callback work?
You send the same request you'd send for one PDF, plus a webhook parameter. Three things happen:
- PDFShift answers
202with{"success": true, "queued": true}. In our test that took about half a second. - PDFShift renders the page in Chromium, the same as a normal call.
- PDFShift sends a
POSTto your webhook URL with a JSON body like this one, from our test:
{
"success": true,
"url": "https://pdfshift.s3.amazonaws.com/d/2/2026-11/a9d36db7f02846bead80bb3a69a78d1c/a19c3826-b61c-4f50-be1f-8fe992bb7e6c.pdf",
"filesize": 20120,
"duration": 2043,
"response": { "status-code": 200, "content-length": 0, "requests": 0, "duration": 1992.71 },
"executed": "2026-11-30T20:11:36.250014+00:00",
"pdf_pages": 1
}
The url points to the PDF on Amazon S3 in Paris, kept for 2 days and then deleted, so download it when the webhook arrives.
webhook takes either a URL string or an object with url, method, auth and headers. For a batch, use the object.
How long does batch PDF generation take with webhooks?
We made 40 one-page invoices (a 30-row table, about 20 KB each as a PDF) and sent them to PDFShift three ways on November 30, 2026, from one machine:

| How we sent 40 invoices | All 40 PDFs back after | Per call (median) |
|---|---|---|
| 10 at a time, each with a webhook | 6.3 s | 0.48 s to get 202; 2.8 s from call to webhook |
| 10 at a time, waiting for each PDF | 10.9 s | 2.69 s |
| One at a time, waiting for each PDF | 108.8 s | 2.69 s |
The render didn't get faster: each invoice took about 2.1 seconds of PDFShift's time in every run. What changed is who waits. When you wait for each PDF, your 10 connections set the pace. With a webhook, our script was done in seconds and PDFShift rendered many invoices at once.
Use webhooks for any batch that starts from a web request, a serverless function or a no-code step with a 30-second limit. It hands off the whole batch and returns, and Chromium stays on our servers, where we've run it at scale since 2018.
How do I send a large batch of PDF requests asynchronously?
PDFShift runs up to 50 conversions at once on every plan and takes up to 250 documents a minute. At about 2.7 seconds a call, 50 at once could start roughly 1,100 a minute, so plan around the 250. Past it, PDFShift answers 429.
So pace the sends instead of firing them all. This sender starts one call every 250 ms, which is 240 a minute, and puts your invoice ID and a secret of yours in the webhook's headers. It needs Node 18 or later for the built-in fetch, and it follows the convert reference for API v3:
const API_KEY = process.env.PDFSHIFT_API_KEY;
const WEBHOOK_URL = 'https://example.com/pdfshift-webhook';
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET; // a long random string you choose
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function queuePdf(invoice) {
while (true) {
const res = await fetch('https://api.pdfshift.io/v3/convert/pdf', {
method: 'POST',
headers: { 'X-API-Key': API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
source: invoice.html,
webhook: {
url: WEBHOOK_URL,
headers: { 'X-Invoice-Id': invoice.id, 'X-Webhook-Secret': WEBHOOK_SECRET },
},
}),
});
if (res.status === 202) return; // queued: the PDF will be POSTed to WEBHOOK_URL
if (res.status === 429) { await sleep(60_000); continue; } // over 250 a minute: wait, then resend
throw new Error(`${invoice.id}: ${res.status} ${await res.text()}`);
}
}
export async function sendBatch(invoices) {
const calls = [];
for (const invoice of invoices) {
calls.push(queuePdf(invoice));
await sleep(250); // 4 a second = 240 a minute, under the 250 limit
}
const results = await Promise.allSettled(calls);
return results.filter((r) => r.status === 'rejected').map((r) => r.reason.message);
}
sendBatch returns the invoices that failed to queue, with the API's answer, so you can fix and resend just those. The same sender in Python 3.9 or later, with requests:
import os
import time
from concurrent.futures import ThreadPoolExecutor
import requests
API_KEY = os.environ["PDFSHIFT_API_KEY"]
WEBHOOK_URL = "https://example.com/pdfshift-webhook"
WEBHOOK_SECRET = os.environ["WEBHOOK_SECRET"] # a long random string you choose
def queue_pdf(invoice):
while True:
r = requests.post(
"https://api.pdfshift.io/v3/convert/pdf",
headers={"X-API-Key": API_KEY},
json={
"source": invoice["html"],
"webhook": {
"url": WEBHOOK_URL,
"headers": {"X-Invoice-Id": invoice["id"], "X-Webhook-Secret": WEBHOOK_SECRET},
},
},
timeout=30,
)
if r.status_code == 202: # queued: the PDF will be POSTed to WEBHOOK_URL
return
if r.status_code == 429: # over 250 a minute: wait, then resend
time.sleep(60)
continue
r.raise_for_status()
def send_batch(invoices):
with ThreadPoolExecutor(max_workers=10) as pool:
calls = []
for invoice in invoices:
calls.append(pool.submit(queue_pdf, invoice))
time.sleep(0.25) # 4 a second = 240 a minute, under the 250 limit
return [c.exception() for c in calls if c.exception()]
If your invoices already sit in a job queue (BullMQ, SQS, Celery), set its worker to the same rate, 4 jobs a second, and call queuePdf from the job.
Here's a month-end run of 10,000 one-page invoices, worked through:
- At 240 a minute, sending takes about 42 minutes.
- The PDFs arrive as you go, a few seconds after each call (5.8 seconds at most in our test).
- Each of our one-page invoices cost 1 credit, so the run needs 10,000 credits. The $99 plan has 25,000 a month.
How do I match each webhook callback to its PDF job?
Put your own ID in the webhook's headers. The body PDFShift posts has the file's URL, size and timings, but no request ID and nothing of yours, and the webhooks don't come back in the order you sent them. The headers you set on the webhook object come back on the POST: in our runs, all 80 webhooks carried the right X-Invoice-Id.
Headers also prove the call is yours: the sender above adds a secret, and the receiver below checks it. For basic auth instead, the webhook object takes auth with a username and password. If your endpoint can't read headers, put the ID in the URL's query string (?invoice=INV-1000).
What happens when the webhook callback fails?
We pointed one webhook at an endpoint that always answered 500. PDFShift sent the same POST, with the same file URL, 4 times: once, then again 30, 60 and 90 seconds later. After that it stopped. We watched for 5 minutes.
So the receiver has three jobs:
- Save each PDF once. An error answer gets the same PDF sent again, so saving it must be safe to repeat.
- Answer first. Reply
200before you download and store the file, so a slow download or a storage error never turns into an error answer. - Chase the PDFs that never arrive. If your server is down for longer than those 90 seconds, don't count on another delivery. Keep the ID as pending until the file is saved, and every few minutes resend the invoices still pending after 10 minutes, with the same
sendBatch.
Here's a receiver in Express 4 that handles all three. db and storage stand for your own database and file storage:
import express from 'express';
import { db, storage } from './your-app.mjs'; // your own database and file storage
const app = express();
app.use(express.json());
app.post('/pdfshift-webhook', async (req, res) => {
if (req.get('X-Webhook-Secret') !== process.env.WEBHOOK_SECRET) return res.sendStatus(401);
res.sendStatus(200); // answer at once: an error answer gets the same PDF sent again
const invoiceId = req.get('X-Invoice-Id');
if (await db.isDone(invoiceId)) return; // a repeat delivery of a PDF we already saved
if (req.body.error) return db.markFailed(invoiceId, req.body.error.error);
const pdf = Buffer.from(await (await fetch(req.body.url)).arrayBuffer()); // the link expires after 2 days
await storage.save(`invoices/${invoiceId}.pdf`, pdf);
await db.markDone(invoiceId);
});
app.listen(3000);
We tested it with a real webhook body: a wrong secret got 401, the PDF was saved once, the repeat delivery was skipped, and an error body marked the invoice as failed. This follows the webhook events page for API v3.
What does a failed async conversion send to the webhook?
When a conversion fails, the webhook still gets a POST, with an error key in place of url:
{
"error": {
"code": 400,
"error": "The requested page took too long to load.",
"identifier": "A74",
"success": false
}
}
Check for error before anything else. Mark the invoice as failed with the message, fix the cause (a page that loads too slowly, for example), and resend only that invoice. If you send a URL as the source, add "raise_for_status": true so a page that answers 404 or 500 isn't turned into a PDF of the error page.
Frequently asked questions
Does PDFShift have a batch endpoint?
Not a separate one. A batch is one request per document, and each request with a webhook is queued and handled on its own. On accounts with parallel conversions enabled, source can also be an array of documents.
Can I use webhooks on the free plan?
Yes. Webhooks need an API key, and the free plan gives you one with 50 credits a month, no card.
Can I get PNG, JPEG or WebP images in a batch the same way?
Yes. The /v3/convert/png, /jpeg and /webp endpoints take the same parameters as /v3/convert/pdf, webhook included.
Can the PDFs go straight to my own S3 bucket?
Yes. Allow PDFShift to write to the bucket in its policy (the S3 setup shows it), then add s3_destination with a path like s3://your-bucket/invoices/INV-1000.pdf. With is_hipaa set to true, a webhook request needs s3_destination.
To try the whole flow, create a free account and push 5 invoices through the sender and your receiver before the month-end run.
Did a snippet fail, or is something unclear?
Drop us a line and we'll look at it.