PDF Conversion

HTML to PDF: Conversion Methods, Tools and Common Pitfalls

March 11, 2026·8 min read
HTML to PDF: Conversion Methods, Tools and Common Pitfalls
In this article
  1. 1.Method 1: Browser Print to PDF
  2. 2.Method 2: Online HTML-to-PDF Tools
  3. 3.Method 3: Developer Libraries
  4. 4.Common HTML-to-PDF Pitfalls

Converting web pages to PDF is one of the most common document tasks — for archiving articles, generating reports, or making web content printable. But HTML and PDF are fundamentally different, and getting perfect results requires understanding the pitfalls.

Method 1: Browser Print to PDF (Free & Instant)

  1. Press Ctrl+P (Windows) or Cmd+P (Mac)
  2. Set the destination to "Save as PDF"
  3. Adjust margins, paper size, and scale if needed
  4. Toggle "Background graphics" on for backgrounds and colours
  5. Click Save

Method 3: Developer Libraries

Puppeteer (Node.js)

Google's headless Chrome library. Full JavaScript execution, CSS rendering, custom headers/footers. Gold standard for production systems.

Playwright (Node.js, Python, .NET)

Similar to Puppeteer but cross-browser support (Chromium, Firefox, WebKit). More actively maintained.

wkhtmltopdf

Lightweight CLI tool based on WebKit. Fast but doesn't support modern CSS features well.

WeasyPrint (Python)

Pure Python HTML/CSS-to-PDF converter. Great for documents with complex typography.

Common HTML-to-PDF Pitfalls

⚠

Content cut off mid-element

Add CSS: page-break-inside: avoid to important divs, tables, and images.

⚠

Background colours missing

Enable 'Background graphics' in print settings, or printBackground: true in Puppeteer.

⚠

Wrong fonts in output

Embed fonts with base64-encoded @font-face, or use system fonts.

⚠

Dynamic content not captured

Wait for content to load: Puppeteer's page.waitForSelector() or networkidle0.

Convert Word, Excel, and PowerPoint to PDF at instantconvert.io — free online document converter.

Frequently Asked Questions

How do I convert a web page to PDF in Chrome?

Press Ctrl+P (Windows) or Cmd+P (Mac) → set destination to 'Save as PDF' → toggle 'Background graphics' on if you need colours and backgrounds → click Save. This is free, instant, and produces a good result for most pages.

What is the best tool to convert HTML to PDF programmatically?

Puppeteer (Node.js) is the gold standard for production HTML-to-PDF. It uses headless Chrome for pixel-perfect rendering with full CSS/JS support. Playwright is similar but with cross-browser support. For Python: WeasyPrint for documents, Playwright for web pages.

Why does my HTML to PDF have wrong fonts?

Web fonts may not load in headless browsers without network access. Embed fonts using @font-face with base64-encoded font data, or use web-safe fonts (Arial, Georgia, Times New Roman) for guaranteed PDF consistency.

How do I add headers and footers to HTML-to-PDF?

In Puppeteer: use headerTemplate and footerTemplate options in page.pdf(). In CSS: use @page rules with @top-left, @top-right etc. selectors (CSS Paged Media module). Browser print-to-PDF uses the browser's own header/footer dialog.

Why is content cut off in my HTML-to-PDF output?

This is a page-break issue. Add CSS: page-break-inside: avoid to important elements. Use orphans and widows properties to control text flow. Add page-break-before: always before new sections. Test with Puppeteer's printBackground: true option.

Related Articles

Try it now — takes 10 seconds

No sign-up. No watermarks. Completely free.

Start Converting Free →