HTML files turn up as saved web pages, exported reports, email templates and invoices generated by software. Opening them depends on a browser and often on files that are no longer next to them. HTML to PDF renders an HTML file into fixed pages, honoring its CSS and print styles, so the document can be archived, printed or sent as one self-contained file.
How to use HTML to PDF
- Add the .html or .htm file.
- Select Convert to PDF.
- Download the PDF.
- Check for images or fonts that the HTML loaded from elsewhere and may be missing.
How the HTML is rendered
- The engine: VelloDoc uses WeasyPrint, a layout engine built specifically to turn HTML and CSS into paged documents.
- Print rules are applied: It applies the page's stylesheets, including print rules like @page size and margins, page-break controls and @media print styles.
- Good for invoices and reports: This makes it well suited to invoices and reports designed for printing.
- Inline styles and data URIs: Styles written inside the file, and images embedded as data URIs, render normally.
What's removed for safety
Uploaded HTML can contain code and references that should never run on a server.
- Scripts are stripped: Script tags are stripped before rendering, WeasyPrint doesn't execute JavaScript at all, and requests to remote web addresses and local files are blocked.
- Remote resources aren't fetched: So images, fonts and stylesheets that the HTML loads from the internet will be missing from the PDF.
- To keep them, embed them in the file, or use Web Page to PDF for pages that are publicly online.
HTML file or web page?
- Which tool for which source: Use HTML to PDF for files you have, like exported reports or saved templates, and Web Page to PDF when the content lives at a public address.
- JavaScript-built pages: Pages that build their content with JavaScript render poorly with both, because neither runs scripts. Printing to PDF from your own browser is the better choice there.
- For Markdown sources, Markdown to PDF is simpler.
- Where to read more: The format guide covers the wider choice of formats.
When people use HTML to PDF
Generated invoices and receipts
Turn HTML invoices produced by billing software into PDFs for customers and accounting records.
Saved web pages for records
Convert a page saved from your browser into a single file that's easier to archive than HTML plus a folder.
Email and report templates
Preview how an HTML template prints, or share it with reviewers who don't work with HTML.
Limitations to know
HTML to PDF removes scripts and doesn't run JavaScript. For uploaded or pasted HTML, remote and local resources are blocked, so externally loaded images, fonts and stylesheets will be missing, and some browser-specific CSS renders differently. WeasyPrint must be installed on the server.
HTML to PDF: common questions
Why are images missing from my PDF?
Images loaded from web addresses, or from files stored next to the HTML, aren't available: remote requests are blocked and only the HTML file is uploaded. Embed images as data URIs to include them.
Does JavaScript run?
No. Script tags are removed and the renderer doesn't execute JavaScript, so content created by scripts won't appear.
Can I control page size and margins?
Yes. Choose the paper size, orientation and margins in the settings, or leave them to an @page rule in the file's own CSS. You can also lay the page out at a desktop screen width, or as one long page.
Why does the layout differ from my browser?
WeasyPrint is a print layout engine instead of a web browser, so some browser-specific or very new CSS features render differently. Print-focused CSS gives the most predictable results.
Why is this tool unavailable on some servers?
It needs the WeasyPrint library. When a server doesn't have it installed, the tool reports that clearly.