To convert HTML to PDF, open the webpage or the .html file in a browser and print it to PDF. On a Mac, choose File > Print, then PDF > Save as PDF. On iPhone and iPad, Safari's Share menu has Markup, which saves the page as a PDF file. In Chrome on any computer, press Command-P or Ctrl-P and choose Save as PDF. For many files or automated jobs, use headless Chrome or WeasyPrint from the command line.
Updated 7 November 2026. Apple steps were checked against Apple's Mac User Guide and iPhone User Guide (iOS 27) on 7 November 2026. The command-line tests below were run that day with Google Chrome 156 and WeasyPrint 68.1 on macOS 15.6.
Webpage or HTML file: which one do you have?
- A webpage (a URL you can open in a browser): print it to PDF from Safari, Chrome or Edge. The browser renders the page with its own CSS, then prints it.
- An .html file (an email template, an export, a report): open the file in a browser first (drag it onto a browser window, or open it from Files on iPhone), then print it to PDF. Images only appear if the file can reach them, so keep the images folder next to the file.
- Many files, or HTML made by your own code: use a command-line converter. That gives you the same result every time.
How to convert HTML to PDF on Mac
Safari (or any Mac app): Print > Save as PDF
- Open the webpage in Safari, or open the .html file in Safari (File > Open File).
- Choose File > Print.
- Click the PDF pop-up menu at the bottom of the dialog and choose Save as PDF.
- Enter a name and a location, then click Save.
Apple's Mac User Guide documents this route for any app. In the same dialog, Security Options sets a password to open, copy or print the PDF, and Save to Web Receipts files the PDF in Documents > Web Receipts, handy for order confirmations. Safari's print options include a Print backgrounds checkbox; turn it on if coloured boxes or background images are missing.
Safari: File > Export as PDF
Safari also has File > Export as PDF in its menu. It saves the page without the print dialog. Apple's Safari guide does not describe this command (its "Save part or all of a webpage" page only lists Web Archive and Page Source), so check the result before you rely on it. For more Mac detail, see how to save a webpage as a PDF on Mac and how to print to PDF on Mac.
Chrome on Mac
- Open the page in Chrome and press Command-P (or File > Print).
- Set Destination to Save as PDF.
- Under More settings, set paper size, margins, scale and Background graphics.
- Click Save.
How to convert a webpage to PDF on iPhone and iPad
Safari Markup (Apple's documented method)
- Open the page in Safari.
- Tap the Page Menu button, then tap Share. (With the Bottom or Top tab layout, tap the Share button.)
- Tap Markup. Add highlights or notes if you like.
- Tap Done, then choose Save File To.
- Name the file and tap Save.
Apple documents these steps in the iPhone User Guide for iOS 27. The result is a PDF of the page.
The print preview shortcut
Another route many people use: in Safari, tap Share, then Print, and spread two fingers on the page preview. The preview opens as a PDF that you can share or save to Files. This is not in Apple's guide, so treat it as a shortcut that may change between iOS versions. It is useful for HTML files in other apps that have a Print option but no Markup.
An .html file in the Files app
Tap the file in Files to open its preview. If the page renders, use Share > Print and the pinch shortcut above. If it shows raw code, open the file in a browser app instead.
For iPhone PDF basics, see how to make a PDF on iPhone.
Limits of the browser methods
- The browser decides page breaks. Tables and images can be split across pages.
- Pages with endless scrolling or images that load as you scroll may print with blank areas.
- Sticky headers, cookie banners and chat bubbles can repeat on every page.
- You get little control over margins and page size on iPhone.
- Many files mean many manual saves.
How to convert HTML to PDF on Windows
- Open the page or the .html file in Chrome or Edge.
- Press Ctrl-P.
- Choose Save as PDF (Chrome) or Microsoft Print to PDF.
- Check More settings for margins, scale and background graphics, then save.
Google's Chrome help lists Ctrl-P (Command-P on Mac) or File > Print as the way in.
How to convert HTML to PDF from the command line
For developers and anyone with many files, three tools cover most needs.
Headless Chrome
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless --no-pdf-header-footer --print-to-pdf=page.pdf "file:///path/to/page.html"
On Windows and Linux, call chrome or google-chrome with the same flags. A URL works in place of the file path. Chrome renders the page exactly as the browser would, JavaScript included. Puppeteer and Playwright wrap the same engine for scripts.
WeasyPrint
weasyprint page.html page.pdf
WeasyPrint is built for documents: it follows CSS paged media rules such as @page size and margins. It does not run JavaScript. Install it with Homebrew (brew install weasyprint) or pip.
Pandoc
pandoc page.html -o page.pdf --pdf-engine=weasyprint
Pandoc converts between document formats and hands the layout to a PDF engine. Without --pdf-engine it uses LaTeX, which most Macs do not have.
wkhtmltopdf
Older guides recommend wkhtmltopdf. Its own status page (checked 7 November 2026) says not to use it with untrusted HTML and points to WeasyPrint, Prince or Puppeteer instead.
Our test: one HTML file, two converters
On 7 November 2026 we converted the same small HTML page (heading, bold text, a link, a table, a code block and a list) with headless Chrome 156 and WeasyPrint 68.1, then checked each PDF with pdftotext and PyMuPDF.
| Converter | Command | Pages | Text selectable | Link clickable | File size |
|---|---|---|---|---|---|
| Headless Chrome 156 | --headless --print-to-pdf | 1 | Yes | Yes | 41.7 KB |
| WeasyPrint 68.1 (via Pandoc) | --pdf-engine=weasyprint | 1 | Yes | Yes | 15.3 KB |
| Pandoc default | pandoc page -o page.pdf | none | Failed: "pdflatex not found. Please select a different --pdf-engine or install pdflatex" | ||
Both working converters kept the text as real text and the link as a live link. Chrome embedded more font data, which explains the larger file.
Online HTML to PDF converters: the privacy trade-off
Online converters ask for a URL or an uploaded file and send back a PDF. For a URL, their server visits the page, so it only works for public pages: anything behind a login prints as the login screen. For an uploaded file, your HTML leaves your device. As of 7 November 2026, CloudConvert's security page says files are "kept only for processing and deleted immediately afterwards", and iLovePDF says it keeps files for a maximum of 2 hours. Invoices, statements and internal reports are better converted locally. See are online PDF editors safe.
Methods compared
| Method | Devices | Handles logged-in pages | Runs JavaScript | Batch | File leaves the device |
|---|---|---|---|---|---|
| PDF Opus (top pick) | iPhone, iPad, Mac | Saved HTML files | No | Per file | No |
| Safari or Chrome print to PDF | Mac, Windows | Yes | Yes | No | No |
| Safari Markup > Save File To | iPhone, iPad | Yes | Yes | No | No |
| Headless Chrome | Mac, Windows, Linux | With a script | Yes | Yes | No |
| WeasyPrint | Mac, Windows, Linux | No | No | Yes | No |
| Online converters | Any browser | No | Usually | Some | Yes |
How to get a better-looking PDF from HTML
- Use the page's print layout. Many sites have print CSS that hides menus and ads. Reader view in Safari (the Reader button in the address bar) gives a clean article layout before you print.
- Scroll to the bottom first. Lazy-loaded images only load once they appear on screen.
- Turn on background graphics if colours or shaded boxes are missing.
- Scale down (90 or 80 percent) if wide tables are cut at the right edge.
- Write print CSS for your own HTML:
@page { size: A4; margin: 2cm; }andbreak-inside: avoid;on tables and figures. - Keep links clickable by printing from a browser or a converter that writes link annotations (both in our test did).
Troubleshooting
The PDF is missing images
The images loaded from a path the converter can't reach, or they lazy-load. Keep image files next to the .html file, use full paths, or scroll the whole page before printing.
Text is cut off at the right edge
The page is wider than the paper. Choose landscape, reduce the scale, or add print CSS that lets wide elements wrap.
Backgrounds and colours are gone
Browsers skip backgrounds by default to save ink. Turn on Print backgrounds (Safari) or Background graphics (Chrome).
Every page repeats a header or banner
Sticky elements print on each page. Close the banner first, use Reader view, or use print CSS (position: static).
Pandoc says "pdflatex not found"
Pandoc's default PDF engine is LaTeX. Add --pdf-engine=weasyprint, or install a LaTeX distribution.
The PDF shows the login page
The converter could not use your session. Print from your own browser while logged in.
PDF Opus: the best app for converting HTML to PDF (top pick)
The best app for converting HTML to PDF is PDF Opus. It converts HTML files (with a subset of CSS) to PDF on your iPhone, iPad and Mac, alongside Word, Excel, PowerPoint, Markdown and images. Flex and grid layouts are laid out as blocks, and right-to-left scripts are not shaped, so check pages built that way. After the conversion, the same app compresses the PDF, merges it with other files, adds page numbers or a watermark, and signs it. PDF Opus runs on its own PDF engine, written from scratch. Your documents are processed on your device. The app only goes online for purchases, licence checks (direct version) and update checks (direct version).
Frequently asked questions
How do I convert an HTML file to PDF?
Open the .html file in Safari, Chrome or Edge, then print it and choose Save as PDF. For many files, use headless Chrome or WeasyPrint from the command line.
How do I turn a webpage into a PDF?
On Mac, File > Print > PDF > Save as PDF. On iPhone and iPad, Safari > Share > Markup > Done > Save File To. On Windows, Ctrl-P > Save as PDF.
How do I save a website as a PDF on iPhone?
In Safari, open the Share menu, tap Markup, tap Done and choose Save File To. The page is saved as a PDF in Files.
Is there a free HTML to PDF converter?
Yes. Every browser's print dialog is free, and so are headless Chrome, WeasyPrint and Pandoc. Online converters have free tiers but upload your file.
Do links still work in a PDF made from HTML?
With Chrome and WeasyPrint they did in our test. Some print paths flatten links, so click one in the finished PDF to check.
Can I convert HTML to PDF without losing formatting?
Browsers keep most formatting, but page breaks and wide elements change because paper has a fixed width. Print CSS gives you control over both.
How do I convert HTML to PDF in code?
Call headless Chrome (directly or through Puppeteer or Playwright) when the page needs JavaScript, or WeasyPrint for document-style HTML with paged CSS.
Why does my PDF have blank pages?
A forced page break in the CSS, a tall element that doesn't fit, or a trailing empty container. Remove the break or the element, or delete the blank page afterwards.