I Built pretext-pdf: Serverless PDFs Without Chromium
I got frustrated with PDF generation in Node.js. Every tool had trade-offs, and none of them felt right.
The Problem
Every time I needed to generate PDFs programmatically, I hit the same walls:
- Puppeteer — Renders HTML to PDF beautifully, but takes 500ms-2s per page. Way too slow for batch operations.
- wkhtmltopdf — Old, fragile, breaks in production, dependency hell.
- pdfmake — Good for simple invoices, falls apart with complex layouts.
- All of them — Overkill if you're not rendering HTML.
And here's the kicker: I didn't need to render HTML. I had structured data (invoices, reports, certificates) that I needed to turn into PDFs programmatically.
The Solution
I built pretext-pdf — a JSON-based PDF generation library.
Instead of:
javascript
// ❌ Puppeteer: render HTML
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html);
const pdf = await page.pdf(); // 1000ms+
You do:
// ✅ pretext-pdf: define structure
const doc = {
sections: [
{ type: 'heading', text: 'Invoice' },
{ type: 'table', rows: [...] }
]
};
const pdf = await renderPDF(doc); // 40-100ms
No Chromium. No external dependencies. Pure Node.js.
Why This Matters
If you're building:
✅ Invoice generation systems
✅ Dynamic reports for your SaaS
✅ AI agents that create PDFs (Claude, Cursor, Windsurf)
✅ Certificate systems
✅ Multi-language documents
...pretext-pdf is built for you.
Today: v2.0.14 Launch
I just shipped a major upgrade. The text layout engine (which handles how words break across lines) is now significantly better:
Better CJK + Latin mixed-script handling
Smarter punctuation (quotes stay with their text)
7-12% faster
Zero breaking changes
The Stats
337 tests passing — production-ready
0 critical vulnerabilities — secure
MIT licensed — free to use
Open source — contribute or fork
Technical Foundation
The layout engine is based on pretext by Cheng Lou (React core team). I cherry-picked 11 patches for specific edge cases and integrated it into pretext-pdf.
Try It
npm install pretext-pdf@2.0.14
GitHub: https://github.com/Himaan1998Y/pretext-pdf
npm: https://www.npmjs.com/package/pretext-pdf
Live Demo: https://himaan1998y.github.io/pretext-pdf/
MCP Server: https://www.npmjs.com/package/pretext-pdf-mcp (Claude, Cursor, Windsurf)
Questions?
How does it compare to X? Ask in comments.
Want to contribute? Issues and PRs welcome.
Found a bug? Report it on GitHub.
I'm here to help. Let's make PDF generation less painful. 🚀
























