TL;DR
TL;DR
For most use cases in 2026, headless Chromium (Puppeteer/Playwright) is the gold standard for HTML-to-PDF conversion — it produces pixel-perfect results matching Chrome's rendering. For quick, no-code conversions, aipdf.studio's HTML-to-PDF tool is the simplest option.
Converting HTML to PDF is a deceptively common problem. Whether you're generating invoices, exporting reports, or archiving web pages, you need reliable output that looks identical across devices.
Here are the 5 main approaches, compared honestly.
Method 1: Browser Print (window.print)
How it works: Call window.print() in JavaScript. The browser opens its print dialog, which can save as PDF.
Pros:
- Zero server dependencies
- Free
- Preserves CSS exactly as rendered
Cons:
- Requires user interaction (print dialog)
- No programmatic control over output
- Headers/footers are browser-controlled
- Inconsistent between Chrome, Firefox, Safari
Best for: Simple one-off exports where the user manually triggers the save.
window.print();
Method 2: Headless Chromium (Puppeteer / Playwright)
How it works: Launch a headless Chrome instance server-side, load the HTML, and call page.pdf().
Pros:
- Pixel-perfect rendering (actual Chrome engine)
- Full control over paper size, margins, headers/footers
- Supports modern CSS, web fonts, images
- Can handle JavaScript-heavy pages
Cons:
- Chromium binary is ~170MB
- Slower than other methods (~1-3 seconds per page)
- Requires Node.js server environment
Best for: Production applications that need reliable, high-fidelity PDF generation.
import puppeteer from 'puppeteer-core';
import chromium from '@sparticuz/chromium-min';
const browser = await puppeteer.launch({
executablePath: await chromium.executablePath(),
args: chromium.args,
headless: 'new',
});
const page = await browser.newPage();
await page.setContent(htmlString, { waitUntil: 'networkidle0' });
const pdf = await page.pdf({
format: 'A4',
printBackground: true,
margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' },
});
await browser.close();
This is exactly how aipdf.studio's HTML-to-PDF tool works internally.
Method 3: wkhtmltopdf
How it works: A command-line tool using Qt WebKit to render HTML and output PDF.
Pros:
- Fast (sub-second for most pages)
- Good CSS support
- Available on all major Linux distros
Cons:
- Uses WebKit, not Blink — rendering differences vs Chrome
- No ES6+ JavaScript support
- Actively being deprecated in some stacks
- No longer actively maintained
Best for: Legacy systems or situations where Chromium is too heavy.
Method 4: jsPDF / html2canvas
How it works: html2canvas takes a "screenshot" of the DOM as a canvas, then jsPDF converts that canvas to a PDF.
Pros:
- Runs client-side (no server required)
- Easy to implement
Cons:
- Results are bitmaps, not vector text — poor quality at high zoom
- File sizes are much larger than proper PDF
- Text is not selectable/searchable in the output PDF
- Font rendering can be inconsistent
Best for: Quick client-side exports where quality is not critical.
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
const canvas = await html2canvas(document.getElementById('content'));
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF();
pdf.addImage(imgData, 'PNG', 0, 0);
pdf.save('document.pdf');
Note: Avoid this method for any document that needs to look professional.
Method 5: Dedicated PDF APIs
How it works: Send HTML to a third-party API (PDFShift, DocRaptor, WeasyPrint) that returns a PDF.
Pros:
- No server infrastructure needed
- Some services handle complex edge cases well
- Good for low-volume use
Cons:
- Per-page pricing can add up
- Data leaves your infrastructure (privacy concern)
- API latency adds to render time
- Vendor lock-in
Best for: Low-volume use cases where operational simplicity outweighs cost.
Comparison Table
| Method | Quality | Speed | Server Required | Cost | Complexity |
|---|---|---|---|---|---|
| Browser Print | ⭐⭐⭐⭐ | Instant | No | Free | Low |
| Headless Chromium | ⭐⭐⭐⭐⭐ | 1-3s/page | Yes | Free | Medium |
| wkhtmltopdf | ⭐⭐⭐ | <1s | Yes | Free | Low |
| jsPDF/html2canvas | ⭐⭐ | 2-5s | No | Free | Low |
| PDF APIs | ⭐⭐⭐⭐ | 1-5s | No | $0.001-0.01/page | Low |
The Easiest Option: aipdf.studio
If you don't want to set up any infrastructure, aipdf.studio's free HTML-to-PDF converter lets you paste HTML and download a high-quality PDF instantly — powered by Chromium under the hood, no account required.
Frequently Asked Questions
What's the best HTML-to-PDF library for Node.js?
Puppeteer with @sparticuz/chromium-min (for serverless environments) is the most reliable choice in 2026. It produces the highest quality output and handles modern CSS including CSS Grid, CSS Variables, and web fonts.
How do I include web fonts in my PDF?
With Puppeteer, load the page with waitUntil: 'networkidle0' to ensure fonts are downloaded before capturing. For Google Fonts, embed the CSS link in your HTML's <head>.
Can I convert a live URL to PDF?
Yes, with Puppeteer you can page.goto(url) instead of page.setContent(html). Be aware of authentication, cookie consent banners, and lazy-loaded content that may not render correctly.
How do I add page numbers to the PDF?
With Puppeteer's page.pdf(), use the headerTemplate and footerTemplate options with the special <span class="pageNumber"> and <span class="totalPages"> elements.
Ready to try it?
Create your first PDF with AI
Free to start. No design skills needed.
Get Started Free