Preview HTML as a printed page and save it as PDF

Paste HTML, pick A4, US Letter or A5, portrait or landscape and a margin, and see how it will look on paper; the Print / Save as PDF button then turns it into a PDF with your browser's own print dialog.

Live demo · real result from this tool
Page size
Orientation

Print preview

Print-ready HTML

<!doctype html><html><head><meta charset="utf-8"><style>@page { size: A4 portrait; margin: 18mm; }body{font:11pt/1.5 Georgia,"Times New Roman",serif;color:#000;background:#fff;margin:0 auto;max-width:180mm}table{border-collapse:collapse;width:100%}th,td{border:1px solid #999;padding:4px 8px;text-align:left}tr,img,pre,blockquote{break-inside:avoid}h1,h2,h3{break-after:avoid}a{color:inherit}@media screen{body{padding:18mm;box-shadow:0 0 0 1px #ddd}}</style></head><body><h1>Invoice INV-2026-014</h1><p><strong>Billed to:</strong> Asha Rao, Bengaluru</p><table>  <tr><th>Item</th><th>Qty</th><th>Amount</th></tr>  <tr><td>Design review</td><td>2</td><td>₹12,000</td></tr>  <tr><td>Hosting (12 months)</td><td>1</td><td>₹6,000</td></tr></table><p>Total: <strong>₹18,000</strong></p></body></html>

Use the Print button and choose “Save as PDF” to create the PDF in your browser. Scripts in your HTML do not run in the preview.

Processed on your device — nothing is uploaded.

How to use the HTML preview

  1. Paste your HTML into the HTML box: a fragment, such as the sample invoice, or a full document.
  2. Choose the Page size (A4, US Letter or A5) and the Orientation.
  3. Set the Margins in millimetres, from 0 to 50. The default is 18 mm.
  4. Leave Add print-friendly styles ticked unless your HTML already has its own print CSS.
  5. Check the Print preview, then press Print / Save as PDF. You can also copy the Print-ready HTML or download it as print.html.

What it does and when to use it

Plain HTML has no idea of paper. Printed straight from a browser, it uses the default page size of your printer settings, splits table rows across pages and often prints at a font size that is too small. This tool adds the CSS rules that control printing, so an invoice, a receipt, a report or a set of notes comes out on the page size you chose.

It suits HTML that is generated by a script or a template, HTML from an email, or a table you built with the HTML Table Generator. If the markup is minified and hard to read, open it in the HTML Formatter first.

How it works

The tool adds one style block. It always contains an @page rule with your size, orientation and margin. With print-friendly styles on, it also sets 11 pt Georgia text in black on white, limits the width to 180 mm in portrait or 260 mm in landscape, gives tables collapsed borders, and asks the browser not to break inside table rows, images, pre blocks or quotes, or straight after a heading.

If your HTML has a head, the block goes just before </head>. If it has only an html tag, a head is added. A fragment is wrapped in a complete document with <meta charset="utf-8">. Everything happens in your browser.

Worked examples

A5 landscape with narrow margins. For <h1>Report</h1>, A5, landscape and 10 mm, the style block starts with:

@page { size: A5 landscape; margin: 10mm; }

Page rules only. Untick print-friendly styles and the fragment <p>x</p> becomes a full document whose only CSS is @page { size: A4 portrait; margin: 18mm; }.

A complete document. In <html><head><title>T</title></head><body>x</body></html> with US Letter, the styles are placed right after the title, inside the existing head, so nothing else in your document changes.

Limits and tips

  • Page breaks follow CSS. To force a new page before a section, add style="break-before: page" to it.
  • Browsers differ slightly in how they honour @page; Chromium-based browsers follow it most closely.
  • Long tables still split across pages between rows. Put the header row in a thead so most browsers repeat it on each page.
  • For a plain-text version of the same content, use HTML to Text.

Frequently asked questions

Does the tool create the PDF itself?
No. It prepares the page and shows a preview; the PDF is made by your browser. Press Print / Save as PDF and choose "Save as PDF" (or "Microsoft Print to PDF") as the printer. That way the text in the PDF stays selectable and searchable.
Why do my scripts not run in the preview?
The preview frame is sandboxed without script permission, so pasted HTML cannot run code on this site. Content that JavaScript would build, such as a chart, will be missing. Paste the finished HTML instead, for example copied from your browser's developer tools.
My PDF has a date and URL at the top. How do I remove it?
Those are the browser's headers and footers. In the print dialog, open "More settings" and untick "Headers and footers".
Why are my colours or backgrounds missing in the PDF?
Browsers skip background colours when printing to save ink. Tick "Background graphics" in the print dialog. With print-friendly styles on, the text is also set to black on white.
Do images from my own computer appear?
Only if the image address can be loaded from the web or is a data URI. A path such as C:/photos/logo.png in the HTML will not load in the browser preview.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close