Convert 7 min read22 January 2025

How to Convert HTML to PDF

Try it free — no sign-up needed

Use PDF Mate's PDF Tools tool directly in your browser.

Open PDF Tools

Converting HTML to PDF — either a web page you're looking at or an HTML file you have — is something you can do without any third-party tools in most cases. Here's the full range of options and when each is appropriate.

The simplest method: browser print to PDF

In any browser: Ctrl+P (Cmd+P on Mac) → change the destination from your printer to "Save as PDF" (Chrome) or "Microsoft Print to PDF" (Windows) → Print. This creates a PDF from exactly what you see in the browser — same rendering, same layout, same fonts.

This works for any web page you can open. It respects the page's print styles (most websites have CSS that adjusts layout for print, removing navigation bars and hiding unnecessary elements). The result is typically clean and readable.

The limitation: interactive content doesn't carry over (forms, videos, JavaScript-rendered elements appear as they were at the moment of capture). Very long pages may paginate oddly if the original layout wasn't designed for print. Background colors and images sometimes don't print by default — in Chrome's print dialog, check "Background graphics" to include them.

Chrome's headless print (for developers)

For automated conversion of HTML to PDF — generating reports, creating documents programmatically — Chrome's headless mode is a standard approach: `chrome --headless --print-to-pdf=output.pdf page.html`. This produces consistent, high-quality PDFs from HTML using Chrome's rendering engine. Libraries like Puppeteer (Node.js) and Playwright wrap this for programmatic use.

Converting an HTML file (not a URL)

If you have a local HTML file rather than a URL, the browser approach still works: File → Open (or drag the HTML file onto the browser) → Print to PDF. The browser renders the local file and you print to PDF as described above.

Relative resource paths (images, stylesheets referenced with relative paths) will load correctly if they're in the same folder as the HTML file. External resources (CDN fonts, external stylesheets) load if you have internet access.

When you need more control

For PDF generation with specific margins, headers, footers, or page numbering not supported by browser print: wkhtmltopdf (open source command-line tool) gives full control over PDF output settings. WeasyPrint is another option that handles CSS print standards well. Both require installation but produce professionally configurable PDF output from HTML/CSS.

Print-specific CSS

If you're creating HTML that will be regularly converted to PDF, adding `@media print` CSS rules gives you control over how the printed/PDF version looks — hiding navigation, controlling page breaks, adjusting font sizes. This is worth doing for any HTML that will regularly be converted.

Quick answers

Will a web page with login-protected content convert to PDF? Yes — if you're logged in and viewing the content in your browser, the print-to-PDF method captures exactly what you see, including content behind login.

How do I capture a full-length webpage (not just what's on screen)? Browser print-to-PDF captures the full page, not just the visible viewport. Chrome's print dialog often shows a page count preview reflecting the full content.

Browse PDF tools at pdfmate.io/tools.

Ready to try it?

Free, browser-based, no sign-up required.

Open PDF Tools