HTML-to-PDF output becomes predictable when you treat it as paginated print rather than a long browser page: set the paper size and margins with @page, define deliberate break rules, and check the exact renderer and version that creates the PDF. Features such as page numbers and running headers depend on renderer support, so a stylesheet that works in one engine may not work the same way in another.
Why a good-looking web page can break in a PDF
A browser page is usually laid out as a continuous viewport. A PDF is divided into pages. In the paged-media model, each page has a page box with a content area and margins; the document’s content is fragmented across as many pages as necessary. That change affects where text and images split, how much space remains for headers and footers, and whether page-specific content can appear. Chrome’s explanation of printed page margins describes this model and its named margin boxes.
As an Amazon Associate I earn from qualifying purchases.
The practical consequence is that screen CSS alone is not a print layout plan. Set page geometry explicitly, add print-specific rules, decide where content may break, and use only pagination features documented for your chosen output engine.
Set page size and margins with @page
The @page rule controls the printed page’s size and margins. Those margins are not merely blank space around the document: they also determine how much room is available for content such as page numbers and running headers or footers.
#1 Best Overall
- INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
- COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
- ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
- HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
@media print {
@page {
size: A4;
margin: 20mm 18mm 22mm;
}
body {
margin: 0;
}
}
This example specifies A4 paper and top, side, and bottom margins; adjust the dimensions to the paper and layout you need. Resetting the body margin prevents an ordinary screen-layout margin from being added inside the page area. It does not replace the page margins set in @page.
Chrome and Firefox support @page for page size and margins, but that does not mean they support every feature in the paged-media specifications. Confirm support for each feature in the engine and version that will create your PDF.
Coordinate CSS margins with the print dialog
Browser print settings can add their own headers and footers. Chrome’s documentation notes that these browser-generated items may appear when there is room, even when CSS supplies margin content. The print dialog can turn them off; zero or insufficient margins can also leave no room for them. Chrome’s default page-layout behavior may mean that if the first page has no room for automatic content, later pages do not get it either.
Free tools Windows power users keep installed
One-click scans. No signup required.
If the output has duplicate headers, unexpected page numbers, or inconsistent blank space, check both sides of the configuration: the CSS @page margins and the print dialog’s header-and-footer setting. Decide which system owns the page furniture, then leave enough margin for it—or disable the browser-generated items.
Rank #2
- CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
- INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
- PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
- ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴
Add page numbers and other margin content in Chrome 131+
Chrome for Developers says CSS-generated page-margin content is available from Chrome 131. Its documentation demonstrates margin at-rules such as @top-left, @bottom-center, and @bottom-right, as well as the page counter for the current page and the pages counter for the total. The Chrome article also shows different layouts for left and right pages.
@page {
margin: 20mm;
@bottom-right {
content: "Page " counter(page) " of " counter(pages);
}
}
Margin-box rules need room to render, so reserve space with the page margins and avoid leaving browser-generated headers or footers enabled if they would compete with your CSS. This is a Chrome 131-and-later capability described by Chrome for Developers, not a guarantee that all browsers or PDF engines implement the same margin features.
Choose the renderer by the pagination features you need
The renderer is part of the stylesheet’s contract. Chrome and WeasyPrint document different feature sets; neither source establishes that the same CSS will produce identical PDFs in both. Choose the engine based on the required output and runtime, then pin and verify its version.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
| Consideration | Chrome print pipeline | WeasyPrint 70.0 |
|---|---|---|
| Page size and margins | Chrome for Developers documents @page support for page size and margins. |
Its version 70.0 API reference documents @page, page size, and related page features. |
| Margin content and counters | Chrome for Developers documents generated page-margin content from Chrome 131, including page counters. | The version 70.0 documentation lists page-margin boxes and counters, with known limitations. |
| Book-like pagination | The cited Chrome article documents left and right page styling; it does not establish support for every paged-media feature. | The version 70.0 documentation lists named pages, running elements, footnotes, named strings, cross-references, and PDF bookmarks. It notes that the start parameter of element() is unsupported. |
| Integration | Fits a browser-based print flow. | Offers a Python API using HTML(...).write_pdf(...). |
Feature lists are version-specific. For detailed support and limitations, consult the Chrome documentation and the WeasyPrint 70.0 API reference. Do not assume a feature documented for one engine is available in the other.
Rank #3
- SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
- INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
- KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
- PREMIUM SUPPORT - Strong technical expertise to solve issues faster
- THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
Use WeasyPrint’s API carefully when rendering from Python
The WeasyPrint first-steps guide shows the basic Python pattern: create an HTML object and call write_pdf(). CSS can be supplied as a stylesheet. When using @font-face, the guide requires a shared FontConfiguration for the CSS object and PDF generation.
from weasyprint import CSS, HTML
from weasyprint.text.fonts import FontConfiguration
font_config = FontConfiguration()
css = CSS(string="""
@font-face {
font-family: Example;
src: url("/path/to/example.woff2");
}
body { font-family: Example, sans-serif; }
""", font_config=font_config)
HTML(string="<h1>PDF title</h1>").write_pdf(
"output.pdf",
stylesheets=[css],
font_config=font_config,
)
The paths and sample content here are illustrative; use the actual font URL or file location available to your application. The API reference also describes rendering pages individually and exposing information such as page size, links, and bookmarks.
Font behavior deserves a check in the generated PDF. WeasyPrint’s documentation says @font-face is supported, but family resolution goes through Pango and may differ from the CSS recommendation’s matching algorithm. Missing glyphs can fall back to a notdef glyph and produce a warning. A browser preview is therefore not proof that the PDF has the expected font or glyphs.
Make page breaks deliberate
Page fragmentation is inherent to PDF output, so decide which elements should stay together and which sections should begin on a new page. Print-specific break properties let you express those intentions; inspect the result at the actual target engine because support and layout can differ.
Rank #4
- Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
- No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
- Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
- Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
- The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
@media print {
h1, h2 {
break-after: avoid-page;
}
figure, table {
break-inside: avoid-page;
}
.chapter {
break-before: page;
}
}
- Use
break-before: pagewhen a section genuinely needs a fresh page, such as a new chapter or report section. - Use
break-inside: avoid-pagefor compact units that should not split, such as a small table or figure. A block taller than the available page area cannot always be kept intact. - Use
break-after: avoid-pageto reduce the chance of a heading being stranded at the bottom of a page. Check nearby content, since avoiding a break can move more material than the heading alone.
Protect a PDF service that accepts user content
WeasyPrint warns that untrusted HTML or CSS can create security and resource-use problems. Its first-steps guide describes risks including resource access, very long or infinite rendering, high CPU and memory use, and problems caused by huge CSS values. These are operational concerns for services processing user-provided markup or templates, not a claim that ordinary trusted documents have those properties.
For a service that accepts untrusted input, follow the guide’s recommendations: sanitize input and restrict the rendering process’s filesystem, network, time, and memory access. See the WeasyPrint security guidance for details.
Check the PDF from the production path
A browser preview cannot confirm how the final renderer paginates, handles margin boxes, resolves fonts, or applies print-dialog settings. Inspect PDFs generated through the same path—and with the same engine version—that users or production jobs will run.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteQuick Recap
- Confirm the page size, orientation, and margins on the generated pages.
- Look for clipped content, unexpected blank space, awkward splits, and headings separated from their sections.
- Check page numbers, running content, and whether browser-generated headers or footers are duplicated or missing.
- Verify fonts and important glyphs in the PDF, not only in the browser preview.
- Record the renderer and version alongside the CSS so an engine update does not silently change a required feature or layout.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




