Blog
How to generate a PDF from HTML in Node.js
There are three common ways to turn HTML into a PDF in Node, and they trade off control, output quality, and how much infrastructure you own. Here is each one and when to reach for it.
Option 1: a PDF library (PDFKit, pdfmake)
Libraries draw the PDF by hand from a document model. You get full control and no browser, but you do not get to use HTML or CSS, so you rebuild your layout in the library API. Good for fixed, simple documents, painful for anything that already exists as a web page.
Option 2: Puppeteer
Puppeteer launches headless Chrome, loads your HTML, and calls page.pdf(). The output is excellent because it is a real browser, but you now operate a browser: cold starts, memory growth, crashes under load, and a Chromium binary that does not fit most serverless functions.
Option 3: a render API (recommended for production)
Send the HTML to a hosted renderer and stream the PDF back. You keep the browser-quality output and drop all the operations. It is one fetch with no native dependencies.
const res = await fetch("https://api.pdfpipe.xyz/v1/pdf", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PDFPIPE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ html: "<h1>Hello</h1>", options: { format: "A4" } }),
});
const pdf = Buffer.from(await res.arrayBuffer());Which to choose
- Fixed, simple layouts with no HTML: a PDF library.
- A few PDFs, full control of the environment, willing to operate Chrome: Puppeteer.
- Production volume, serverless, or you just want it to work: a render API.
Frequently asked
What is the simplest way to generate a PDF from HTML in Node?
POST your HTML to a render API and read the response as bytes. It is one fetch with no Chromium binary and no native build steps.
Is Puppeteer good for production PDFs?
It produces great output but requires operating a browser fleet: pooling, recycling, concurrency limits, and crash recovery. Many teams move that to an API once volume grows.
Keep reading
The rest of the series, for when this one leaves a question open.
How to generate invoice PDFs in React
Turn an Invoice component into a real PDF with selectable text and tables that paginate cleanly.
Automate month-end invoice generation with n8n
Schedule trigger to finished PDF invoices in one workflow, including the template and the failure handling.
How to create PDFs with Puppeteer
A clean example, the print options that matter, and the production pitfalls to expect.
100 free documents a month, flat pricing after that, and a live playground you can try without signing up.