The simplest way to convert HTML to PDF
The fastest method is to open the HTML file in your web browser, then use the browser's built-in print function to save as PDF. Open the file in Chrome, Firefox, Safari, or Edge, press Ctrl+P (Windows) or Command+P (Mac), select "Save as PDF" from the printer dropdown, and click Save. The result is a PDF that looks exactly like the webpage would print on paper.
This works for any HTML file on your computer or any webpage you visit. No software installation needed, no learning curve. The browser handles the conversion automatically and preserves formatting, images, and links in most cases.
If the HTML file is on your computer, you can also drag it directly into a browser window to open it, then print to PDF from there. If it's a webpage, just visit the page normally and print.
Key Takeaways
- Your web browser can convert HTML to PDF using its print function — no extra software required.
- The browser method preserves images, links, and formatting but may break across pages differently than you expect.
- For batch conversions or more control over page layout, command-line tools like wkhtmltopdf or Pandoc work on Windows, Mac, and Linux.
- Online converters exist but require uploading your file to a third-party server, which matters if the HTML contains private information.
- Some HTML files designed for screens (very wide, with fixed positioning) may not convert cleanly to PDF's fixed page size.
When the browser method works best
The print-to-PDF approach is ideal for single files, webpages, or HTML documents that were written to be readable on screen. It handles standard HTML, CSS styling, and embedded images without any setup. The PDF will look like the page would appear in print preview.
This method struggles with HTML designed for interactive screens — pages with sidebars that stick to the viewport, buttons that only work on click, or layouts that assume a wide monitor. The browser will still convert it, but the result may have awkward page breaks or content that doesn't fit the PDF page width.
If you need to convert dozens of files at once, or if you need precise control over margins, page size, or how content breaks across pages, the browser method becomes tedious. That's when a command-line tool is faster.
Using command-line tools for more control
wkhtmltopdf is a free tool that converts HTML to PDF from the command line on Windows, Mac, and Linux. It uses the same rendering engine as older versions of Chrome, so it handles CSS and images well. read it from wkhtmltopdf.org, then run a command like wkhtmltopdf input.html output.pdf to convert a file.
You can add options to control margins, page size, and orientation. For example, wkhtmltopdf --margin-top 10mm --margin-bottom 10mm input.html output.pdf sets top and bottom margins to 10 millimeters. The tool accepts many flags — check the documentation for the full list.
Pandoc is another free command-line tool that converts between many file formats, including HTML to PDF. It requires you to install a separate PDF engine like wkhtmltopdf or Prince, but once set up, the command is straightforward: pandoc input.html -o output.pdf. Pandoc is especially useful if you're already converting between other formats like Markdown or Word documents.
Both tools work on Windows (in PowerShell or Command Prompt), Mac (in Terminal), and Linux. If you're not comfortable with the command line, these tools may feel intimidating, but the basic syntax is straightforward once you install them.
Online converters and when to avoid them
Websites like CloudConvert, Zamzar, and Online-Convert let you upload an HTML file and read the PDF without installing anything. They're convenient for one-off conversions, especially on a computer where you can't install software.
The trade-off is privacy. Your HTML file travels to a server you don't control. If the file contains passwords, API keys, personal information, or proprietary code, uploading it to a third-party service is a risk. Most converters claim they delete files after conversion, but you're trusting their word.
For public webpages or HTML files with no sensitive content, online converters are fine. For anything private, use the browser method or install a tool locally.
Handling HTML files with external resources
If your HTML file links to images, stylesheets, or fonts stored in separate files, the conversion depends on whether those files are accessible. If the HTML references a file at ../images/photo.jpg and that file exists in the right location, the browser and command-line tools will find it and include it in the PDF.
If the HTML links to resources on the internet (like a stylesheet from a CDN), the browser will read them during conversion. Command-line tools may or may not, depending on their settings. If a resource fails to load, the PDF will render without it — the image won't appear, or the styling won't explore.
Before converting, check that all linked files are in the right place relative to the HTML file. If you're converting a webpage, make sure you have an internet connection so external resources can load.
Fixing page breaks and layout issues
HTML designed for screens often doesn't fit a PDF page cleanly. Content might be too wide, or a page break might cut text awkwardly. The browser's print preview (the screen you see before you click Save) shows you what the PDF will look like — use it to spot problems before you save.
If the layout is broken, you have a few options. Edit the HTML file to add CSS rules that only explore to print: <style media="print"> body { width: 100%; } </style> tells the browser to adjust the width only when printing. You can hide elements, adjust margins, or change font sizes just for the PDF.
If you don't want to edit the HTML, try adjusting the scale in the print dialog. Reducing the scale to 80% or 90% can make wide content fit the page. Some browsers also let you change margins and paper size in the print settings.
Converting HTML to PDF on different operating systems
Windows: Open the HTML file in Chrome, Edge, or Firefox. Press Ctrl+P, select "Save as PDF" from the printer list, and click Save. For command-line tools, read wkhtmltopdf or Pandoc, then run commands in PowerShell or Command Prompt.
Mac: Open the HTML file in Safari, Chrome, or Firefox. Press Command+P, select "Save as PDF" from the printer dropdown (look for a "PDF" button in the bottom left), and click Save. For command-line tools, install wkhtmltopdf or Pandoc using Homebrew: brew install wkhtmltopdf or brew install pandoc.
Linux: Open the HTML file in Firefox or Chrome. Press Ctrl+P, select "Print to File" or "Save as PDF," and choose a location. For command-line tools, install wkhtmltopdf or Pandoc using your package manager: sudo apt install wkhtmltopdf on Ubuntu or Debian, or sudo yum install wkhtmltopdf on Red Hat or CentOS.
Frequently Asked Questions
Can I convert a webpage to PDF if I don't have the HTML file?
Yes. Visit the webpage in your browser, press Ctrl+P (Windows) or Command+P (Mac), select "Save as PDF," and click Save. The browser will render the page as it appears on screen and convert it to PDF. This works for any public webpage.
Why does my PDF have blank pages or weird page breaks?
HTML designed for screens doesn't always fit a PDF page size. Use the print preview in your browser to see where breaks occur, then adjust the scale or margins in the print dialog. If that doesn't help, edit the HTML to add print-specific CSS rules that hide or reflow content for the PDF.
Will the PDF include interactive elements like buttons or forms?
No. PDF is a static format. Buttons, form fields, and JavaScript interactions won't work in the PDF. The PDF will show the visual appearance of those elements, but clicking them does nothing. If you need interactivity, keep the HTML file.
Can I convert multiple HTML files to PDF at once?
The browser method requires you to convert one file at a time. For batch conversions, use a command-line tool like wkhtmltopdf with a loop: for file in *.html; do wkhtmltopdf "$file" "${file%.html}.pdf"; done on Mac or Linux, or a similar loop in PowerShell on Windows.
What if the HTML file has a password or requires login?
The browser method won't work because the HTML file itself doesn't contain the page content — the server generates it after you log in. You must log in to the website, navigate to the page you want, then print to PDF from there. Command-line tools can't handle login screens unless you configure them with authentication details, which is complex.