How to Convert an HTML File to PDF (With Working Page Breaks)
Turn a saved web page, email template, or report into a PDF, control paper size and page breaks with CSS, and avoid missing images and fonts.
By DocConvo Editorial TeamPublished
To convert an HTML file to PDF, open HTML to PDF, add the .html or .htm file, and download the PDF. Your own browser lays out the page, so CSS, tables, flex and grid layouts, lists, and embedded images come out the way they look on screen. Text stays selectable and links stay clickable.
When HTML to PDF is useful
- Reports and invoices generated as HTML by a script, a database, or an accounting tool
- Email templates you want to share for review or keep as a record
- Saved web pages you need to archive, print, or attach to a ticket
- Documentation written in HTML or exported from Markdown
- Simple designs such as certificates, tickets, or menus built with HTML and CSS
How to convert HTML to PDF with DocConvo
- Open the HTML to PDF converter.
- Add your
.htmlor.htmfile. - Run the conversion. The page is rendered in a sealed-off frame inside your browser.
- Download the PDF and check the page breaks.
The file is not uploaded. That matters for invoices and reports that contain customer names, prices, or account numbers.
Make sure images and fonts appear
For safety, the converter blocks network access while it renders your page. Anything the HTML tries to load from another website is not fetched. This is the most common reason a PDF looks different from the page in your browser.
To make the file self-contained:
- Images: embed them as data URLs (
<img src="data:image/png;base64,...">) or use inline<svg>. - CSS: put styles in a
<style>tag in the file instead of linking to an external stylesheet. - Fonts: embed a web font with
@font-faceand a data URL, or rely on common system fonts. - Scripts: scripts written inside the file can run briefly, but scripts loaded from a URL, such as a charting library from a CDN, are blocked. Paste the library into the file, or save the final HTML after the chart has been drawn.
Many tools have an option such as "Save page as: Web page, single file" or "inline images" that produces a self-contained file.
Control paper size, margins, and page breaks
The PDF follows the same rules as printing a page from a browser, so standard print CSS works.
Paper size and margins
@page {
size: A4 portrait;
margin: 20mm;
}
Use size: letter for US Letter, or landscape for wide tables. Without an @page rule, you get A4 (Letter in the US) with standard margins, and pages wider than the paper automatically switch to landscape.
Page breaks
h2 { break-before: page; } /* start each section on a new page */
table, figure { break-inside: avoid; } /* keep a table or figure together */
The older page-break-before and page-break-after properties also work. Table header rows repeat on every page automatically, which keeps long tables readable.
Hide things that only belong on screen
@media print {
nav, .cookie-banner, .no-print { display: none; }
}
Navigation bars, buttons, and banners rarely belong in a PDF.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| Images are blank | Loaded from a URL | Embed as data URLs or inline SVG |
| Wrong font | Web font loaded from a URL | Embed the font or use a system font |
| A table is split awkwardly | No break rules | Add break-inside: avoid |
| Page is tiny or cut off | Fixed-width layout | Add an @page size or use a fluid width |
| Chart missing | Charting script loaded from a URL | Inline the script, save the rendered HTML, or use SVG |
Free plan limits
On the free plan, HTML to PDF accepts files up to 15 MB and produces up to 10 pages per conversion within the standard credit. Longer outputs cost an extra credit, and the converter shows the cost first. See the free plan page for every limit.
Related tasks
If your content is plain text rather than HTML, TXT to PDF is simpler. To combine several converted pages into one document, use Merge PDF, and if the result is large because of embedded images, run it through Compress PDF.
FAQs
Why are images missing from my PDF?
DocConvo renders your HTML in a sealed frame with network access blocked, so images, fonts, and stylesheets loaded from other websites are not fetched. Embed images as data URLs or inline SVG, and put CSS in a style tag.
How do I set the paper size and margins?
Use a CSS @page rule, for example @page { size: A4 portrait; margin: 20mm; }. Without one, the PDF uses A4 (Letter in the US) with standard margins, and pages wider than the paper switch to landscape.
Is the text in the PDF selectable?
Yes. Text stays selectable and searchable, and links stay clickable, because the PDF is built from the page layout rather than a screenshot.
Does JavaScript run when converting?
Scripts written inside the HTML file can run for a short time, so simple script-built tables or charts usually appear. Scripts loaded from other websites are blocked, and a script that runs too long is stopped. For reliable results, save the final rendered HTML.
Related tools
Jump straight into a converter - files stay on your device.
Related articles
- How to Convert TXT to PDFTurn a plain text file into a printable PDF, including line wrapping, languages, and why a photo of a page will not work.
- How to Merge Multiple PDF FilesJoin several PDFs into one file in exactly the order you want, and what to check before you send the merged document.
- PDF to PNG: Export Pages as Sharp Images (and When JPG Is Better)Save each PDF page as a PNG for sharp text and diagrams. How it works, what you lose, why transparency can appear, and when JPG is the smarter choice.
- How to Convert Excel to PDF Without Cut-Off ColumnsTurn an Excel or ODS spreadsheet into a clean PDF, keep every sheet and merged cell, and prepare the workbook so the PDF is easy to read and print.
Explore PDF Tools
Part of our PDF Tools.
See the full category on PDF Tools & PDF Converter Online.