TruePage · Osabee

HTML to PDF: how to convert an HTML file or a webpage to PDF, free methods first

By Osabee, the makers of TruePage · Updated September 29, 2026

The quickest free way to convert HTML to PDF is to open the file in Chrome, Edge, Firefox or Safari and print it to PDF: press Ctrl + O (Windows) or Cmd + O (Mac) to open the .html file, then Ctrl + P or Cmd + P and choose Save as PDF. The browser renders the HTML exactly as it would on screen, and the PDF keeps real, selectable text.

If you need to convert many files, or do it from a script, headless Chrome can write a PDF straight from the command line. Online converters such as iLovePDF, Sejda or Smallpdf work too, but they upload your file (or fetch your URL) to their servers, which matters for anything private.

This guide covers each route with exact settings, the problems that make an HTML file look wrong as a PDF (missing backgrounds, broken images, a file path printed in the footer), and the developer libraries worth knowing if you are building this into an app.

Which HTML to PDF method should you use?

Your situation Best method Cost
One HTML file on your computer Open it in the browser, print to PDF Free
Dozens of files, or a scheduled job Headless Chrome or Edge on the command line Free
No browser at hand, or a URL to grab quickly Online converter Free with limits
HTML generated by your own app Puppeteer, Playwright or WeasyPrint Free, open source
A live page you are signed in to, or a web app Your browser, or an extension that prepares the page Free or paid

Most people searching "html to pdf" have a single file: an exported report, a saved receipt, an email saved as HTML, a page a developer sent them. For that, the browser is all you need.

How to convert an HTML file to PDF in Chrome or Edge

Chrome and Edge share the same rendering engine, so the steps and the result are almost identical. Google documents the shortcuts on its Chrome keyboard shortcuts page and the print steps on Print from Chrome.

Double-clicking an HTML file usually opens it in your default browser as well, but opening it from inside the browser lets you choose which one renders it.

  1. Open Chrome or Edge and press Ctrl + O on Windows or Cmd + O on Mac. Select your .html file and click Open.
  2. Check the page looks right on screen. If images or styling are missing, see the section on paths below before you go further.
  3. Press Ctrl + P (Windows) or Cmd + P (Mac). In Edge you can also right-click an empty part of the page and choose Print.
  4. Set Destination to Save as PDF.
  5. Click More settings. Set Paper size (Letter in the US, A4 almost everywhere else) and Margins.
  6. Under Options, tick Background graphics and untick Headers and footers. The next section explains why both matter.
  7. Click Save, pick a folder and a file name.

Microsoft's own Edge printing help page puts it plainly: if the output looks different from the page you are printing, include the background graphics.

The two settings that change the result

Background graphics is off by default. Chrome's print preview starts with this option unticked, so background colours, coloured table rows, shaded boxes and CSS background images are dropped. For a plain text document that is fine. For an invoice, a styled report or anything with a coloured header, tick it.

Headers and footers is on by default, and it prints more than you might expect. The header carries the date and the page title; the footer carries the address of the page and the page number. When the page is a local file, that address is the full file:/// path, including the names of the folders on your disk. On a Mac that usually includes your user name. If you are sending the PDF to anyone, untick Headers and footers.

Chrome remembers both choices for next time, along with margins, layout, scale and paper size. That is handy, but it also means a setting you changed weeks ago may still be active, so glance at the options before you save.

One more detail from Chrome's source code: headers and footers need some space at the top and bottom of the page, so with Margins set to None the option is unavailable.

Convert HTML to PDF in Firefox and Safari

Firefox uses its own engine, which is useful when a page renders oddly in Chrome.

  1. Press Ctrl + O or Cmd + O, or use File > Open File…, and select the .html file.
  2. Press Ctrl + P or Cmd + P.
  3. Set Destination to Save to PDF.
  4. Open More settings. Under Scale, Fit to page width prevents wide layouts from being cut off.
  5. Tick Print backgrounds if you want colours and background images. Untick Print headers and footers: Firefox's defaults put the page title and the address at the top, and the page number and date at the bottom.
  6. Click Save.

Safari on Mac has a faster route. Choose File > Open File… to load the HTML file, then File > Export as PDF…, name the file and save. If you want control over backgrounds and the header and footer, use File > Print (Cmd + P) instead, click Show Details if the options are hidden, set the options in the Safari section of the dialog, then open the PDF pop-up at the bottom and choose Save as PDF.

For the general version of these steps on every browser and phone, our guide to saving a webpage as PDF on any device has the full rundown.

Why images or CSS are missing when you open an HTML file

An HTML file rarely travels alone. It points to stylesheets, images and scripts, and how it points to them decides whether they show up when you open the file from disk. We tested this in Chrome and Edge with a small test page, and the behaviour is consistent.

Relative paths work. A reference like css/style.css or images/logo.png is resolved against the folder the HTML file sits in. As long as the folders stay next to the file, the browser finds them. Move the HTML file on its own (to your desktop, into an email) and those images and styles are gone.

Root-relative paths break. A reference that starts with a slash, like /assets/logo.png, is resolved against the root of your disk, not the website. The image shows as broken. Pages saved from a website, or built to run on a server, often use this kind of path, which is why they look unstyled when you double-click them.

JavaScript-built pages may come out blank. In our test, a classic script tag ran, but a <script type="module"> did not, and a fetch() call to a file in the same folder failed. Apps built with React or similar frameworks rely on both, so opening their HTML from disk often shows an empty page or a spinner. The usual fix is to serve the folder from a small local web server and open it through http://localhost, then print from there.

If you received the HTML as part of a zip, extract the whole archive and open the file from inside the extracted folder. The HTML file needs its folders next to it on disk.

Convert HTML to PDF from the command line with headless Chrome

When you have many files, or you want the conversion inside a script, Chrome and Edge can print to PDF without opening a window. Google documents the flags on its headless Chrome command line page.

The flags you need:

On a Mac, this command converted a local file in our test (Edge works the same way with its own application path):

"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless --no-pdf-header-footer --print-to-pdf="$HOME/Desktop/page.pdf" "file:///Users/you/site/index.html"

On Linux, following Google's pattern: google-chrome --headless --no-pdf-header-footer --print-to-pdf=page.pdf file:///home/you/site/index.html. On Windows, Google's examples start Chrome with start chrome --headless followed by the same flags.

Do not skip --no-pdf-header-footer. Without it, every page of the PDF carries the date and time, the page title and, in the footer, the full file:/// path of the source file, folder names included. That is the same privacy leak as the print dialog default, except here nobody sees a preview before the file is written.

A few differences from the print dialog are worth knowing. In our test, the command line printed background colours by default, applied the page size set in the CSS (@page { size: A5 landscape }), honoured forced page breaks, and kept links clickable. The text was selectable. To loop over a folder, wrap the command in a shell for loop or a short script; each run produces one PDF.

On company computers this route may be blocked: Edge administrators can switch off headless mode with the HeadlessModeEnabled policy.

Online HTML to PDF converters compared

Online converters dominate the search results for "html to pdf", and they are genuinely convenient. Here is what each one states on its own page (checked October 2026):

Tool What you can give it Free limits stated Deletion stated
iLovePDF URL, HTML/CSS/JS files or a zip, pasted HTML "Limited document processing" on Free; Premium from €5 a month billed yearly After 2 hours (iLovePDF blog)
Sejda Several URLs, HTML files, pasted code 3 tasks per hour "Automatically deleted after 2 hours"
Smallpdf HTML file upload only "Limited usage" "An hour after processing"
PDF24 URL only Free, funded by ads After one hour, servers in Germany
html2pdf.com Up to 20 HTML files or zip archives 20 files per batch After one hour
PDFCrowd URL, HTML file or archive, HTML code Free output carries Pdfcrowd branding Not stated on the page
CloudConvert File upload Not stated on the page Not stated on the page

Some have useful extras. iLovePDF lets you pick the screen width the page is rendered at, choose "One long page" instead of paper pages, and block ads and overlay popups. Sejda offers a delay of up to 5 seconds for slow pages, a choice of US or European servers, and a checkbox to use or ignore the print stylesheet.

What happens to your file

All of these convert on their servers. That has two consequences you should weigh before you upload.

Your content leaves your computer. The file or the page is sent to a third party and kept for one to two hours by the tools that state a figure. For a public blog post, no problem. For a contract, a payslip, a medical letter or an internal report, think twice.

URL mode cannot see what you see. When you paste an address, the converter's server downloads the page itself, without your cookies or your login. Pages behind a login, a paywall or a company intranet come out as the login screen, or not at all.

A single file loses its images. Uploading just the .html file leaves the stylesheets and images behind. iLovePDF and html2pdf.com accept zip archives for exactly this reason: zip the HTML together with its folders and upload that.

Developer libraries for HTML to PDF

If the HTML comes from your own application (invoices, reports, tickets), you will want a library rather than a manual step. Briefly:

For a JavaScript-heavy page, use Puppeteer or Playwright. For documents you design yourself with print CSS, WeasyPrint is lighter.

How to convert HTML to PDF without losing formatting

Most "the PDF looks wrong" complaints come down to a handful of causes. If you can edit the HTML, the CSS fixes below solve them at the source.

Problem Cause Fix
Colours and backgrounds missing Background graphics off by default Tick Background graphics; in CSS, print-color-adjust: exact
Images or styles missing Root-relative paths, file moved away from its folders Keep folders next to the file, use relative paths, or serve locally
Tables or figures split across pages Normal page breaking break-inside: avoid on the element
A section should start on a new page No break defined break-before: page
Wrong paper size or orientation Page size set in the dialog, not the CSS @page { size: A4 landscape; margin: 10mm }
Date, file path or URL at the edges Headers and footers on by default Untick Headers and footers, or --no-pdf-header-footer
Layout looks different from the screen The page's print stylesheet Edit the @media print rules, or render with screen media
Fonts look different Web fonts not loaded from disk Use relative font paths, or let Puppeteer wait for fonts

A note on print-color-adjust: exact: it asks the browser to keep colours and backgrounds, but Mozilla's print-color-adjust reference is clear that the user's own print settings take priority. In practice, tick the box as well.

Links survive. PDFs produced by Chrome and Edge, from the dialog and from the command line, kept clickable links in our test. The text was also real text you can select and search. If your PDF is a picture of the page instead, it did not come from a print engine; our guide to saving a webpage as text explains how to tell and what to do.

Converting a live webpage, not a file

Everything above assumes you have the HTML file. Often you do not: you have a page open in the browser, maybe one you are signed in to, and you want it as a PDF. The print dialog still works there, and it is still free. It fails in the same predictable places: the site's print stylesheet hides parts of the page or squeezes it into a narrow column, images that load on scroll are missing, sticky headers repeat on every page, and web apps that scroll inside a panel come out as a single screen. Our guide to Chrome's Save as PDF cutting off the page goes through each symptom and its free fix.

When the free fixes are not enough, this is where our extension fits. A plain disclosure: TruePage is made by Osabee, the publisher of this guide.

TruePage works in Chrome and Edge on desktop and converts the tab you already have open. It scrolls to the bottom first so lazy-loaded content is present, disables the print-only stylesheet so the PDF matches the desktop layout, neutralises sticky headers, and expands inner scrolling areas in chat apps, webmail and dashboards. Then it asks the browser's own PDF engine, the one behind the print dialog, for the file. The result is the whole page with selectable text and working links. The conversion runs locally with no network request, so pages behind a login work and nothing is uploaded.

  1. Click the TruePage icon in the toolbar.
  2. Choose Full page (everything, images included) or Text only (text and links, no images or embeds).
  3. Click Save this page as PDF. The file lands in your Downloads folder.

While it runs, the browser shows the bar "TruePage started debugging this browser"; that is the browser's safeguard for the API that produces a real PDF, and it disappears when the capture ends.

Be clear about what it is not. TruePage is not a batch converter: it saves one page at a time, and for a folder of HTML files the command line above is the better tool. It produces a PDF with selectable text, not an editable Word document. It is free for 4 conversions, then a one-time $14.99, €12.99 or £10.99 for unlimited use, with no account. Get it from the Chrome Web Store or Microsoft Edge Add-ons.

Chat apps are the most common case where print fails on a live page; our guide to saving a ChatGPT conversation as PDF covers them in detail.

Frequently asked questions

How do I convert my HTML to PDF?

To convert an HTML file to PDF for free, open it in Chrome, Edge, Firefox or Safari with Ctrl + O on Windows or Cmd + O on Mac. Then press Ctrl + P or Cmd + P, choose Save as PDF (Save to PDF in Firefox), tick Background graphics, untick Headers and footers, and click Save. The PDF keeps selectable text and working links, and nothing is uploaded anywhere.

How do I convert HTML to PDF in Chrome?

To convert HTML to PDF in Chrome, open the file with Ctrl + O (Cmd + O on Mac), press Ctrl + P or Cmd + P and set Destination to Save as PDF. Under More settings, tick Background graphics to keep colours and untick Headers and footers so the local file path is not printed. For many files, Chrome's headless mode with --print-to-pdf does the same from the command line.

How do you open an HTML file?

An HTML file opens in any web browser. Double-clicking it usually opens it in your default browser. You can also start Chrome, Edge or Firefox and press Ctrl + O on Windows or Cmd + O on Mac, or use File > Open File… in Safari, then select the file. To see or edit the code instead, open the HTML file in a text editor.

What is the best tool to convert HTML to PDF?

The best tool to convert HTML to PDF depends on the job. For a single file, your browser's print dialog is free and keeps real text and links. For many files, headless Chrome on the command line. For HTML generated by an app, Puppeteer or Playwright, or WeasyPrint for print-designed documents. Online converters are convenient for public content but upload your file to their servers.

How do I convert HTML to PDF without losing formatting?

To convert HTML to PDF without losing formatting, keep the HTML file next to its image and CSS folders, open it in a browser and check it on screen first. In the print dialog, tick Background graphics so colours and shading are kept, and set the right paper size. If you control the CSS, use @page for the page size and break-inside: avoid to stop tables splitting across pages.

Is it safe to convert HTML to PDF online?

Converting HTML to PDF online means uploading the file, or letting the converter's server fetch the URL. Sejda and iLovePDF say files are deleted after 2 hours, Smallpdf, PDF24 and html2pdf.com after one hour. That is fine for public pages. For contracts, payslips or internal documents, convert locally in the browser or on the command line, where the file never leaves your computer.

How can I save an HTML form as a PDF?

To save an HTML form as a PDF, open it in your browser, fill it in, then press Ctrl + P on Windows or Cmd + P on Mac and choose Save as PDF. Check the preview to confirm your entries appear before saving. The result is a static PDF, not a fillable form. Online converters fetch a fresh copy of the page, so anything you typed would be lost.

What is an HTML file?

An HTML file, with the extension .html or .htm, is a web page saved as a text file. It contains the page's text and the tags that describe its structure, and usually points to separate files for styles, images and scripts. Browsers read HTML files and display them as pages, which is why the browser's print dialog is the simplest way to turn one into a PDF.

More guides