HTML to PDF (print prep)
Prepare a print layout: page sizes for A4 / A5 / Letter in 96dpi pixels, a page count estimated from block elements and text lines, and a full document string carrying `@page{size:…;margin:48px}`. The real PDF comes from the browser print dialog and the page count is an estimate.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Result
The result can be copied directly.
Paste HTML to see the print pagination estimate
Characters: 0 · Lines: 0 · Estimated pages: 0 · Block elements: 0
What this tool does
- Check pagination and paper size before printing so tables are not split.
- Get a document string with `@page` rules to send to the browser print dialog.
- Estimate the page count of a long document for layout or print quotes.
Example
Input
<h1>Title</h1><p>Body text</p>
Output
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML to PDF</title>
<style>@page{size:A4 portrait;margin:48px}
html,body{margin:0;padding:0}
body{width:698px;font:12pt/1.6 system-ui,"PingFang SC",sans-serif}
h1,h2,h3{break-after:avoid;page-break-after:avoid}
table,figure,pre{break-inside:avoid;page-break-inside:avoid}
img{max-width:100%;height:auto}
@media print{body{padding-bottom:24px}}</style>
</head>
<body>
<h1>Title</h1><p>Body text</p>
</body>
</html>
`@page` and the page count are estimates; real pagination comes from the browser print preview.
Frequently asked questions
Does it produce a PDF file?
No. It emits HTML with `@page` rules plus a page estimate; the actual PDF comes from the browser print / save-as-PDF dialog.
How is the page count estimated?
Block elements and text lines are folded into print lines (46 characters each) and divided by lines-per-page, rounded up with a floor of one page. Font metrics belong to the browser.
Which papers are supported?
A4 (794x1123px), A5 (559x794px) and Letter (816x1056px) at 96dpi; anything else throws `invalid-paper`.
What does the footer switch do?
It adds bottom padding in `@media print` to leave room for page numbers; the numbers themselves come from the browser print settings.
Keywords:html2pdf@pageprint to pdfdeveloper