Ask how to turn HTML into a PDF in JavaScript and you get five names: Puppeteer, Playwright, jsPDF, html2pdf.js and pdfmake. They get recommended side by side, although they do very different things. So we ran one real document through all five. One of them gave us two blank pages. Another one gave us a PDF that looks right and contains no text.
Disclosure: I'm on the team behind Dynamic Document API, a hosted HTML to PDF API, so we have a horse in this race. That's why everything below is in a public repository and runs in GitHub Actions: the code, the PDFs and the results file.
The test document
An invoice with the things a real one uses today:
- a header laid out with Flexbox, with an inline SVG logo
- the invoice details (number, dates, PO) in a two-column CSS grid
- a web font (Inter, from Google Fonts)
- 36 line items, so the table runs onto page 2 and should repeat its header row there
- totals that shouldn't be split across pages
- US Letter, and a footer with the seller on the left and "Page 1 of 2" on the right
Every library got the same finished HTML. Only the page setup (size, margins, page numbers) was added the way each library wants it. jsPDF and html2pdf.js are made for the visitor's browser, so we ran them inside Chrome. The run used Node.js 24 on the ubuntu-24.04 GitHub runner.
This time we also read the text back out of every PDF: are all 36 line items in there, in order, with their amounts? That's what search, copy and paste, screen readers and accounting software depend on.
The results
Page 1 from each library. Playwright's looks the same as Puppeteer's, so it isn't shown twice:

Puppeteer 26.0.0 and Playwright 1.65.2: as designed.

jsPDF 4.2.1: two blank pages at first. This is the result after two changes.

html2pdf.js 0.14.0: looks right, but it's a picture.

pdfmake 0.3.15 with html-to-pdfmake 2.6.0: the stylesheet is ignored.
| Puppeteer, Playwright | jsPDF .html() | html2pdf.js | pdfmake + html-to-pdfmake | |
|---|---|---|---|---|
| Runs | on your server | in the visitor's browser | in the visitor's browser | in either |
| How it works | Chrome prints the page | html2canvas reads the page, jsPDF redraws it | html2canvas takes a picture of the page | turns the HTML into its own document format |
| Inline SVG logo | ✅ | ❌ all pages blank | ✅ | ✅ |
| Flexbox and grid | ✅ | ✅ | ✅ | ❌ stacked |
| Web font | ✅ | ✅ if you add it as TrueType | ✅ | ❌ Roboto |
| Table header on page 2 | ✅ | ❌ | ❌ | ✅ with an attribute |
| Line items readable as text | 36 of 36 | 36 of 36 | 0 of 36 | 36 of 36 |
| 1,500 line items | ✅ | ✅ | ❌ all pages blank | ✅ |
| Page numbers | footer template | draw them yourself | draw them yourself | footer function |
| Runs JavaScript | ✅ | ✅ | ✅ | ❌ |
| File size | 240 KB, 158 KB | 691 KB | 933 KB | 35 KB |
| License | Apache-2.0 | MIT | MIT | MIT |
| Latest release | Dec 2026 | Mar 2026 | Jan 2026 | Nov 2026 |
Now the parts that don't fit in a table.
Puppeteer and Playwright: right result, but you run Chrome
Both drive a real Chrome, so the PDF is what Chrome's print preview shows you. They even take the same settings:
import puppeteer from "puppeteer"; const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(html, { waitUntil: "networkidle0" }); // wait for the web font await page.pdf({ path: "invoice.pdf", format: "letter", margin: { top: "16mm", right: "16mm", bottom: "20mm", left: "16mm" }, printBackground: true, // otherwise the green table header comes out white displayHeaderFooter: true, headerTemplate: "<span></span>", footerTemplate: `<div style="font-size: 7pt; width: 100%; margin: 0 16mm; text-align: right"> Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>`, }); await browser.close(); In Playwright, only the launch and the wait differ: playwright.chromium.launch() and waitUntil: "networkidle". If you already use one of them for tests, take that one.
What the code doesn't show:
- The download. Each of them put about 700 MB of browser files on the disk. Bake them into your Docker image, not into the first request.
- The sandbox. Puppeteer starts Chrome with its sandbox, and on Ubuntu 23.10 and later AppArmor gets in the way ("No usable sandbox!"). Playwright leaves the sandbox off unless you pass
chromiumSandbox: true. If you render HTML that comes from users, you want it on. - The footer is its own little page. It doesn't see your document's CSS or fonts, so it needs inline styles and its own margins.
jsPDF: two blank pages, because of the logo
Our first PDF from jsPDF had two pages, the footer, and nothing else. No exception. The text was even in there: our check read all 36 line items from a blank page.
The culprit was the inline SVG logo. jsPDF's .html() uses html2canvas to read the page. For every picture, html2canvas sets a clipping area, draws the picture and removes the clipping area again. jsPDF can't draw an SVG and throws an error in the middle of that. html2canvas writes "Error loading svg" to the console and carries on, but the clipping area stays, and everything after the logo is cut off. (We checked: catch the error, and the invoice appears, only without its logo.)
So we made two changes:
- Turn the SVG into a PNG first, with a canvas, right before calling
.html(). The code is about 20 lines. - Give jsPDF the web font as TrueType files. It doesn't read WOFF2, and without them you get Helvetica with uneven gaps between the words.
const doc = new jsPDF({ unit: "mm", format: "letter" }); await doc.html(document.body, { margin: [16, 16, 20, 16], autoPaging: "text", // don't cut lines of text in half width: 183.9, // Letter minus the margins, in mm windowWidth: 695, // the same width in CSS pixels fontFaces: [ { family: "Inter", weight: 400, src: [{ url: "/fonts/inter-400.ttf", format: "truetype" }] }, // and one entry per weight ], }); After that, the result is close to the design, and the text is real text. What's left: the table header isn't repeated on page 2, the gaps between words are still a bit off in places, and you draw the page numbers yourself.
html2pdf.js: looks right, contains no text
html2pdf.js is the quickest way to a "Download PDF" button, and the page looks almost exactly like the design:
html2pdf() .set({ margin: [16, 16, 20, 16], html2canvas: { scale: 2 }, jsPDF: { unit: "mm", format: "letter" } }) .from(document.body) .save("invoice.pdf"); But every page is a JPEG. When we read the text back, the only words in the PDF were the footer lines we had drawn on top ourselves. Nobody can search this invoice, copy the number or the amount from it, or have a screen reader read it aloud. The project's README says so openly, so it isn't a bug. It's just easy to miss, because the PDF looks fine.
The second limit only shows up with long documents. The browser caps how big a canvas can get, and html2pdf.js puts the whole document on one canvas. With 1,000 line items we got 30 good pages. With 1,500 we got 45 blank pages, again without an error.
Good for: a short document that someone looks at or prints. Not for invoices that another program has to read.
pdfmake: small files, but not for your HTML
pdfmake made by far the smallest file, 35 KB. It needs no browser, and all 36 line items came out as text.
It just isn't an HTML renderer. You describe the document in pdfmake's own format, and the html-to-pdfmake package translates simple HTML into it. It reads style attributes and a list of CSS properties; our <style> block was ignored. So everything is stacked, the table has black borders, and the invoice details run together: "Invoice numberINV-2026-0418".
One useful detail: the header row repeats on page 2 if you tell pdfmake about it in the HTML:
<table data-pdfmake='{"headerRows":1}'> Good for: documents you're happy to build in pdfmake's format from the start. For templates that already exist as HTML and CSS, expect to rebuild them.
What about html-pdf, PDFKit and React-pdf?
- html-pdf still gets about 130,000 downloads a week. Don't start with it: the package is deprecated, and npm tells you to "migrate your projects to a newer library like puppeteer".
- PDFKit, pdf-lib and React-pdf don't take HTML. You draw the page, edit an existing PDF, or build it from React components.
So which one?
- It has to look like it does in Chrome, and you have a server: Puppeteer or Playwright. Plan for running Chrome: image size, memory, sandbox, updates.
- A download button without a server: try
window.print()with a print stylesheet first. It uses the browser's own PDF output, with real text, but the visitor sees the print dialog. If it has to be a direct download, use jsPDF, with the two changes above. - A quick picture of a short page: html2pdf.js.
- Documents defined in code, not in HTML: pdfmake.
- Chrome's result without running Chrome: that's what a hosted API is for, and it's what we build. The Node.js tutorial renders a nine-page report through ours with plain
fetch. Your HTML and data are sent to us, so check whether that works for your project.
We ran the same test for other languages: Python and .NET.
Run it yourself
Everything is in DynamicDocumentApi/html-to-pdf-javascript: the invoice, the code for each library in renderers.mjs, the workflow and the results. No API key needed:
npm ci npx puppeteer browsers install chrome npx playwright install chromium npm run compare If you'd configure one of the libraries differently, or know a setting that fixes one of these results, open an issue or a pull request. We'll rerun it and update the results.

