How to convert HTML to PDF
- Paste your markup into HTML source, or press Open HTML file. A fragment such as a heading and a table works, and so does a full page with its own
<style>block. - Check the Preview. It updates as you type.
- Pick Page size, Orientation and Margins, and type a File name.
- Click Save as PDF. In the print dialog choose Save as PDF as the destination, turn off Headers and footers, and save.
How it works
The tool first cleans your markup with DOMPurify, which removes scripts, event handlers, embedded frames and other risky parts. It then places the result in a sandboxed preview frame together with an @page rule built from your page size, orientation and margins. Saving calls your browser's own print engine on that frame, so the PDF has real, selectable text, working links and the layout you see in the preview.
Worked example
The box starts with a sample invoice: a blue heading with a rule, a line naming the client, a three-row table and a total of $390.00. With the defaults (US Letter, Portrait, 0.75 in margins, file name document) the status line under the button reads "Preview ready. Printing will use US Letter, portrait, 0.75 in margins. Nothing was removed." Click Save as PDF, pick Save as PDF, and you get a one-page document.pdf. Change Page size to A4 and the status line and the print layout follow.
Limits and edge cases
- Scripts never run. The notice under the status line tells you what was removed.
- Only images embedded as
data:addresses load. Normal image links are blocked by the site's security policy, and the notice counts them. The Image to Base64 tool makes such an address. - Stylesheet links and web fonts are dropped. Put CSS in a
<style>block and use system fonts. - Backgrounds and colors are printed as written. Use
break-inside: avoidto keep a block on one page. - Links do not open from the preview, but they stay clickable in the saved PDF.
- Some phone browsers print the whole page instead of only the preview frame. Use a desktop browser for dependable results.
Frequently asked questions
Can I convert a web page by typing its URL?
No. A browser page is not allowed to download another site's HTML, so this tool only converts markup you paste or open from a file. To capture a live page, open it, choose View Source, copy the code here, or use your browser's own Print command on that page.
Why does my JavaScript or chart show up blank?
Scripts are removed before the preview is built, and the preview frame is sandboxed so nothing can run. Content that a script draws after the page loads, such as charts, carousels or single-page apps, will not appear. Paste the final rendered HTML instead, or use static images.
How do I get rid of the date, title and web address at the top and bottom of the PDF?
Those lines come from the browser's print dialog, not from this tool. Open More settings in the dialog and turn off Headers and footers, then choose Save as PDF as the destination.
Why are my images and web fonts missing?
For safety the site only lets the preview load images embedded as data: addresses, and stylesheets from its own trusted libraries. An image with a normal https address is blocked, and the tool tells you how many. Convert the picture to a data address first, or rely on system fonts such as Georgia, Arial and Courier New.
Writing in Markdown instead? Use Markdown to PDF. For plain text with no styling, Text to PDF is simpler, and the HTML Beautifier tidies messy markup before you convert it.
Sources: MDN, CSS @page; MDN, Window.print(); MDN, iframe sandbox; DOMPurify.