Why developers stop using Puppeteer for PDF generation (and what they use instead)
TL;DR: Puppeteer works in dev, then becomes a production nightmare — OOM kills, font rendering failures, 600MB+ Docker images, and no built-in async queue. The better pattern: upload a DOCX template once, POST JSON tokens, receive a PDF in seconds. Zero ops overhead.
The decision to use Puppeteer usually starts with a Monday afternoon prototype. You spin up a headless Chrome instance, call page.pdf(), and get a beautiful PDF. You push it to GitHub on Friday feeling great. Three weeks later you're at 2am debugging memory leaks in production.
Where Puppeteer fails in production
Memory leaks that kill your pod
Puppeteer's Chromium process is notoriously difficult to keep memory-stable under concurrent load. A browser instance handling 10 sequential PDF requests often shows steadily growing RSS — hit 50 concurrent requests and you're looking at OOM kills. Common failure patterns: browser instance not properly closed, page contexts accumulating on error paths, font cache growing unboundedly in long-lived processes.
Font rendering is deeply unreliable
Your PDF looks perfect in local dev (using your MacBook's system fonts). In production Docker on Linux, headless Chrome has no system fonts, no corporate fonts, no CJK characters without noto-fonts-cjk packages, and different font rendering than local Chrome. Every deployment, you're one font upgrade away from rendering regressions.
Docker image size explodes
A bare-minimum Puppeteer Docker image weighs in at 600MB–1.2GB. This blows cold-start times on serverless platforms, increases bandwidth costs on every CI build, and violates most teams' container size budgets.
Large documents time out
For a 30-page report, page.pdf() can run for 60–90 seconds. No HTTP client, no platform, and no load balancer will wait that long. Your server returns a 504 and the client gets nothing. Puppeteer gives you no async queue — you build it yourself.
The alternative: DOCX-based template generation
The pattern that solves all of these problems at once:
- Template authored in Microsoft Word — any team member can edit it
- Data posted as JSON — a single API call with your token values
- Conversion handled server-side — LibreOffice headless on the backend, fonts baked into the server image, isolated per-job
- PDF returned via a signed download URL, or delivered by webhook for async jobs
DOCX template workflow
Step 1: create your template in Word
Use {{tokenName}} syntax for simple field insertion. Loops and conditionals use their own commands (not Handlebars-style {{#each}}/{{#if}}): {{FOR item IN lineItems}} ... {{END-FOR item}} for repeating rows, and {{IF condition}} ... {{END-IF}} for conditional sections. Inside a loop, prefix the current item's fields with $ — e.g. {{$item.description}}.
Step 2: upload your template once
Unlike parsing and generation (which take real file uploads), this endpoint takes the DOCX as a base64 string in a JSON body:
curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/templates" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Invoice Template", "docxBase64": "UEsDBBQABgAI..." }'
Response:
{ "id": "tpl_abc123", "name": "Invoice Template", "tokens": ["customerName", "invoiceTotal", "lineItems"] }
Step 3: generate a PDF
curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"templateId": "tpl_abc123",
"tokens": {
"customerName": "Acme Corporation",
"invoiceNumber": "INV-2024-0892",
"invoiceTotal": "$4,250.00",
"dueDate": "November 30, 2024",
"lineItems": [
{ "description": "Enterprise License Q4", "amount": "$3,500.00" },
{ "description": "Support Package", "amount": "$750.00" }
]
}
}'
Response:
{
"jobId": "job_xyz789",
"correlationId": "b3f1c2a0-1234-4a5b-9c6d-7e8f9a0b1c2d",
"status": "completed",
"url": "https://storage.logicspoke.com/generated/job_xyz789.pdf?sas=...",
"pages": 2,
"processingMs": 850,
"creditsCharged": 1,
"outputBytes": 88213
}
The url is a time-limited SAS link. For large documents, use /v1/pdf/generate/async instead — same body, but it returns a jobId immediately and your account-level webhook (registered once via POST /v1/webhooks, subscribed to job.completed) fires when it's ready, instead of a per-request callback field.
Batch generation (up to 50 PDFs in one request)
curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/generate/batch" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jobs": [
{ "templateId": "tpl_abc123", "tokens": { "customerName": "Acme Corp" } },
{ "templateId": "tpl_abc123", "tokens": { "customerName": "Beta Ltd" } }
]
}'
Billed per document using the same weight-band pricing as a single generate call — there's no separate batch discount.
HTML or URL generation
For complex CSS layouts — branded marketing collateral, dashboards, reports with charts — use the HTML endpoint:
{
"html": "<html><body><h1>Q4 Report</h1>...</body></html>",
"options": { "format": "A4", "marginMm": 20 }
}
Or render an existing page:
{ "url": "https://your-app.com/reports/q4/pdf-view", "options": { "format": "A4" } }
Security features
- Watermarks:
"options": { "watermark": { "text": "DRAFT", "opacity": 0.3 } } - Password protection:
"options": { "password": "secure-client-password" }(AES-256, via qpdf) - Audit trail (opt-in):
"options": { "auditTrail": true }appends a visible page listing the job ID, account, and timestamp — off by default, not automatic - SSRF protection: URL-based generation blocks internal/private IP ranges
Puppeteer vs. API-based generation
| Criterion | Self-hosted Puppeteer | LogicSpoke Generate API |
|---|---|---|
| Setup time | 2–8 hours | < 30 minutes |
| Production stability | Memory leaks, OOM kills | Managed, isolated per-job |
| Font support | Manual per Docker image | 20+ system fonts + custom upload |
| Template editing | Developer required (HTML/CSS) | Any user (Word/DOCX) |
| Large document handling | Timeout — build queue yourself | Async + account-level webhook built in |
| Batch generation | Build yourself | 50-job batch endpoint |
| Pricing model | Always-on server | Pay per job, by document size (1–20 credits) |
Questions
What DOCX features are supported?
Tables, headers/footers, images (static), page numbers, conditional content via {{IF}}/{{END-IF}}, loops via {{FOR}}/{{END-FOR}}, styles (bold, italic, font sizes), page breaks.
Can I use my own custom fonts?
Yes. Upload fonts via POST /v1/pdf/fonts (TTF/OTF, max 10MB). They're cached per-account and available in all your templates.
What's the credit cost for PDF generation?
It's a flat per-job charge based on the size of the source template/data, not a strict per-page rate: 1 credit up to 5MB/20 pages, 3 credits up to 15MB/50 pages, 8 credits up to 30MB/100 pages, 20 credits above that. HTML/URL rendering is a flat 5 credits per job regardless of size. There's no self-serve tier ladder with volume discounts — accounts that need negotiated per-credit pricing at real scale go through the Enterprise (sales-assisted) track instead.
How do I handle conditional sections in a template?
Use {{IF fieldName === 'value'}}...{{END-IF}} in your DOCX — it works on paragraphs, table rows, and inline text, and the condition is a real JavaScript expression, not just a truthy check.
Upload a template. POST JSON. Receive a PDF.
No Chromium. No font management. No 2am debugging.