TL;DR
If you have an .html or .htm file sitting on your disk and you want a PDF of it, you have four sensible options: drag it into Chrome and hit Ctrl+P, drop it on a local-only converter extension, use the VS Code Print extension, or run wkhtmltopdf from the command line. All four keep the file on your machine — no upload, no signup, no watermark. For one file, the drag-into-Chrome method takes ten seconds. For twenty files, use a batch tool. If you want a drop-zone extension that handles .html, .htm, and 40+ other formats in one place, use Convert: Anything to PDF.
Method 1: drag into Chrome + Ctrl+P
This is the fastest way to convert a single HTML file, and it works on every operating system Chrome runs on. No installs, no accounts, no upload.
The exact steps:
- Open Chrome (or Edge, or any Chromium-based browser).
- Drag your
.htmlor.htmfile from Finder / File Explorer directly onto a Chrome tab. The URL bar will showfile:///Users/you/path/to/file.html. - Press
Cmd+Pon Mac orCtrl+Pon Windows / Linux. - In the destination dropdown, choose Save as PDF.
- Click Save.
That's it. Chrome renders the HTML using its normal engine, then prints the rendered page to a PDF file. Because the file is loaded via file://, nothing leaves your machine — no upload, no telemetry beyond Chrome's usual footprint.
What works well:
- CSS styling (as long as the stylesheets are linked with relative paths that resolve on disk)
- Images stored alongside the HTML (again, relative paths)
- Fonts loaded via Google Fonts or embedded as
@font-face - Standard HTML including tables, lists, forms, and semantic layouts
- Clickable links — Chrome preserves
<a href>as PDF annotations by default
What breaks:
- CSS with
background-image— by default Chrome's print dialog does not print backgrounds. Fix it: expand More settings in the print dialog and tick Background graphics. - Anything loaded from a CDN behind a login (rare, but happens on scraped pages)
- JavaScript that runs only after user interaction — the print dialog captures the current DOM, so scripts that require a click first will not have rendered yet. Trigger them before pressing Ctrl+P.
Where it gets awkward: Chrome adds a header and footer with the URL and page number by default. Turn those off in More settings > Headers and footers. Layout controls are limited to margins and paper size — for anything more nuanced, use one of the methods below.
Method 2: Convert: Anything to PDF (drop zone)
If you have more than a handful of files, or files in mixed formats (HTML plus PNG plus DOCX plus JSON), the drag-and-drop-into-Chrome dance gets tedious fast. This is what a local drop-zone extension solves.
Convert: Anything to PDF is a Chrome extension that opens a full-tab drop zone. You drag files onto it — one at a time or in a batch — and it converts each to PDF. The whole conversion happens locally in the extension's isolated tab; nothing uploads. The result appears as a download in your browser.
How it handles HTML specifically:
- Drag a
.htmlor.htmfile onto the drop zone. The extension parses it, renders it in an offscreen frame, and rasterizes / structures the result into a PDF. - Linked stylesheets and relative-path images work as long as they sit in the same folder — the extension resolves them against the HTML file's own path.
- External CSS on remote CDNs will not load (extensions cannot fetch arbitrary origins under Manifest V3's default CSP), so bundle your CSS or use inline styles if the page depends on remote resources.
- Base64-embedded images work perfectly. If your HTML has
<img src="data:image/png;base64,...">, that renders directly.
Why bother with an extension instead of Method 1:
- Batch. Drop 20 HTML files at once, get 20 PDFs. No repeating Ctrl+P.
- Format mixing. The same drop zone accepts
.html,.htm,.md,.txt,.docx,.rtf,.png,.jpg,.webp,.svg,.csv,.json,.xml, and more. If you have a folder of scraped pages plus screenshots plus a CSV of metadata, one tool converts all of them. - No print-dialog artifacts. No headers, no footers, no page-number cruft to disable each time.
- Persistent settings. Set your preferred page size and margins once instead of adjusting the print dialog every conversion.
If you only ever convert one HTML file, the drag-into-Chrome method is fine. If you do this weekly or convert mixed folders, an extension pays for itself in saved clicks.
Method 3: VS Code Print extension
If you already live in VS Code — writers, developers, technical writers — this is genuinely the least-friction option. The Print extension (by pdconsec) adds a right-click Print command that opens a syntax-highlighted preview and offers Save as PDF.
Setup:
- In VS Code, open the Extensions panel (
Cmd+Shift+X/Ctrl+Shift+X). - Search for
pdconsec.vscode-print. Install it. - Open your
.htmlor.htmfile in VS Code. - Right-click in the editor, choose Print.
- A new browser tab opens with a rendered preview. Press
Ctrl+P/Cmd+Pand save as PDF.
Where this shines:
- Handles HTML source view (syntax-highlighted) and rendered view. Only method here that does both cleanly for a code review or archive.
- Batches at the folder level: right-click a folder in the Explorer sidebar and pick Print folder.
- Respects your VS Code color theme.
Where it falls short:
- The rendered-HTML mode still uses your browser's print dialog, so it inherits Chrome's header / footer / background quirks.
- No control over page breaks between files in folder mode — you get one PDF per file, then merge them manually.
- Extension development stalled in 2023 — still works, but occasional bugs on the newest VS Code versions.
Best fit: someone already in VS Code who wants source view. Otherwise skip to Method 4 or back to Method 2.
Method 4: wkhtmltopdf CLI
For scripting, automation, cron jobs, or CI pipelines, the command line beats every GUI. wkhtmltopdf is a mature, single-binary tool that renders HTML with an embedded WebKit engine and writes a PDF. It has no dependency on your desktop browser, and it runs on macOS, Linux, and Windows.
Install:
- macOS:
brew install --cask wkhtmltopdf - Ubuntu / Debian:
sudo apt install wkhtmltopdf - Windows: download from wkhtmltopdf.org
Basic use:
wkhtmltopdf input.html output.pdf
That's the whole command. It reads input.html, renders it, writes output.pdf.
Useful flags:
--enable-local-file-access— required in recent versions to allow the HTML file to reference local images and CSS via relative paths.--page-size A4(orLetter) — set paper size.--margin-top 15mm --margin-bottom 15mm --margin-left 15mm --margin-right 15mm— set margins.--print-media-type— render using the CSS@media printrules instead of screen rules.--enable-javascript --javascript-delay 1000— wait a second for JS to run before rendering. Useful for pages that populate content dynamically.--footer-center "[page]/[topage]"— add a page-number footer.
A complete example for a scripted archive:
wkhtmltopdf \
--enable-local-file-access \
--print-media-type \
--page-size A4 \
--margin-top 15mm --margin-bottom 15mm \
--footer-center "Page [page] of [topage]" \
--footer-font-size 8 \
invoice.html invoice.pdf
Known limits:
wkhtmltopdfuses an older QtWebKit fork. Modern CSS (grid, some flexbox edge cases) can render differently than in Chrome — test on your input.- Development is in maintenance mode — the project archived in 2023 but binaries still work. For long-term automation, consider
puppeteeror headless Chrome. - Remote resources require network access at conversion time.
For one-off use, Method 1 is faster. For scripts you run daily, wkhtmltopdf or headless Chrome (chrome --headless --print-to-pdf) is the right choice.
Batch conversion of many .html files
If you have a folder of 20, 50, or 500 HTML files, running Ctrl+P on each one is not the answer. Here are three ways to batch-convert.
Option A: extension drop zone. Open Convert: Anything to PDF, select all the HTML files in Finder / Explorer, and drag them onto the drop zone in one go. Each file becomes its own PDF, downloaded to your Downloads folder. No scripting required. This is the right choice if you do this monthly and don't want to maintain a shell script.
Option B: shell loop with wkhtmltopdf. For anyone comfortable with the terminal:
for f in *.html; do
wkhtmltopdf --enable-local-file-access "$f" "${f%.html}.pdf"
done
This iterates every .html file in the current directory and produces a matching .pdf. Add --print-media-type and margin flags for consistent output. Runs in seconds even for hundreds of files.
Option C: headless Chrome. Modern Chrome / Chromium can convert HTML to PDF from the command line without any extension:
chrome --headless --disable-gpu --print-to-pdf=output.pdf input.html
Wrap it in a loop and you have the same batch behavior as wkhtmltopdf, but with the exact rendering engine your desktop Chrome uses. This is what most modern automation setups actually do.
Merging the batch into one PDF. All three options above produce one PDF per input file. If you want them combined, use pdftk *.pdf cat output combined.pdf (install pdftk first), or drag the resulting PDFs into a merge tool. See our batch conversion guide for the full workflow, including sorting and naming conventions.
Preserving CSS, images, and links
The biggest complaint people have after saving an HTML file as PDF is: "the CSS is broken" or "images are missing." These are almost always fixable. The failure modes are predictable.
CSS not applying. Three usual causes: (1) the stylesheet is loaded from a remote CDN and the converter blocks external requests; (2) the stylesheet uses a relative path that doesn't resolve when the file is loaded via file://; (3) the CSS uses @media screen rules that get overridden by @media print. Fix: inline your critical CSS with <style> tags, or use --print-media-type in wkhtmltopdf to force print rules. If you're using a converter extension, make sure the stylesheet sits in the same folder as the HTML file.
Images not showing. Same causes as CSS. Relative paths break when the extension can't access the file's original location, and remote images may be blocked by the converter's CSP. Fix: convert images to data: URIs and embed them directly in the HTML, or make sure the images sit next to the HTML file when using wkhtmltopdf --enable-local-file-access.
Background images / colors not printing. Chrome's print dialog turns off background graphics by default because most people printing a receipt don't want to burn through a whole ink cartridge. Fix: in the print dialog, expand More settings and tick Background graphics. Web fonts and gradients need this too.
Links not clickable in the PDF. Chrome's Save-as-PDF preserves <a href> as clickable annotations, but only for http:// and https:// targets — not for mailto: links in all cases, and not for file:// links. Fix: use Chrome (Method 1) rather than wkhtmltopdf if clickable links matter to you. See saving a webpage as PDF with clickable links for a detailed diagnosis.
Fonts falling back to Times New Roman. Custom fonts loaded via @font-face from a remote URL require the converter to fetch the font. Chrome does this fine. wkhtmltopdf does it only if the URL is accessible. Extensions may block external font requests. Fix: base64-encode your font files and embed them in the CSS, or ship the fonts alongside the HTML file and reference them with a relative path.
Long tables cut off between pages. A print-CSS problem, not a converter problem. Add tr { page-break-inside: avoid; } and thead { display: table-header-group; }. All four methods respect these hints.
Comparison table
| Method | Best for | Cost | Batch | Watermark | Preserves links |
|---|---|---|---|---|---|
| Chrome drag + Ctrl+P | One file, fast | Free | No | No | Yes |
| Convert: Anything to PDF extension | Many files, mixed formats | Free | Yes | No | Yes |
| VS Code Print extension | Devs, source view too | Free | Folder-level | No | Yes |
| wkhtmltopdf CLI | Scripting, automation | Free | Shell loop | No | Yes |
| Online converters (typical) | Emergencies only | Free tier | Usually paid | Often | Sometimes |
Every method above keeps the file local. Online converters upload your HTML — fine for a public page, a real problem if the file contains anything you'd rather not hand to a third party. See file converter that never uploads your files for the privacy argument.
Frequently asked questions
How do I save an .html file as PDF without opening a browser?
Use wkhtmltopdf or headless Chrome from the command line: wkhtmltopdf input.html output.pdf or chrome --headless --print-to-pdf=output.pdf input.html. Both convert an HTML file to PDF entirely in a background process — no browser window appears, no dialog boxes, nothing on screen. This is the right approach for cron jobs, CI pipelines, server-side rendering, or any scripted workflow. On macOS the command-line tool cupsfilter can also convert HTML to PDF using the system print engine, though its output is less predictable than wkhtmltopdf.
How do I save multiple HTML files as one PDF?
Two approaches. First: convert each HTML file to its own PDF using any of the methods in this guide, then merge the resulting PDFs with pdftk *.pdf cat output combined.pdf or a drag-and-drop merge tool. Second: concatenate the HTML files into a single big HTML file first (with <div style="page-break-before: always"> between them), then convert that one file to a PDF — the page breaks in the source produce clean page breaks in the output. The first approach is more reliable; the second gives you finer control over layout.
Why does my saved HTML PDF have broken CSS?
Three common causes. First, the stylesheet is loaded from a remote CDN and the converter can't reach it — bundle the CSS inline with <style> tags to fix this. Second, the stylesheet uses relative paths that resolve to nothing when the HTML is loaded via file:// or inside a converter — put the CSS file in the same folder as the HTML. Third, Chrome's print dialog is applying @media print rules that override the on-screen styles you were expecting. Uncheck the print media type or add explicit print styles to your CSS.
How do I save an HTML file as PDF on Mac?
Same as any OS: drag the .html file onto a Chrome tab, press Cmd+P, choose Save as PDF, click Save. macOS Preview can also print some HTML files to PDF via Cmd+P > PDF > Save as PDF, but it's less reliable than Chrome for anything but the simplest markup. For batch on Mac, install wkhtmltopdf via Homebrew (brew install --cask wkhtmltopdf) and use a shell loop. See our Mac-specific guide for the full workflow.
How do I save htm as PDF?
Exactly the same as .html. The .htm extension is a legacy leftover from Windows systems that limited extensions to three characters — the file contents are identical. Every method in this guide handles .htm files without any change to the workflow. If you find a tool that treats .htm and .html differently, that's a bug in the tool, not a real distinction. Rename the file to .html if you hit any awkwardness, and it will behave exactly as expected.
Bottom line
For one HTML file, drag it into Chrome and press Ctrl+P. Ten seconds, no install, no upload. For a folder of files or mixed formats, use a local extension so you can drag the whole batch onto a drop zone. For automation, use wkhtmltopdf or headless Chrome in a shell script. Everything above stays on your machine — no uploads, no signups, no watermarks. If you want the batch-friendly extension option, install Convert: Anything to PDF or read more about it on the tool page — one drop zone, forty-plus formats, all local.