Write PDF-specific rules in your template’s stylesheet, put print-only styling inside @media print, and use @page for page size, orientation, and margins. Then verify the result in the exact PDF renderer and version you plan to deploy: HTML-to-PDF engines do not all support the same CSS or pagination behavior.
Where to put the CSS
A code-based PDF template can receive CSS in the HTML document, from an external stylesheet, or from a renderer-level global stylesheet. Choose the location that matches how the template is assembled and reused:
- Styles in the HTML template: useful when the markup and its PDF styling should travel together. Keep the rules in a
<style>element or an inline stylesheet source supported by your renderer. - External stylesheet: useful when several templates share a design system. Confirm the renderer can resolve the stylesheet path or URL in its runtime environment.
- Renderer-level global stylesheet: useful when your PDF library exposes a global CSS cascade. For example, TCPDF documents
setGlobalCSS,addGlobalCSS, andresetGlobalCSS; its global CSS is parsed with document CSS.
Use stable class names for template components—such as .invoice__total or .report-table—rather than styling around incidental markup. This makes changes easier to isolate and helps you distinguish template rules from library-wide defaults.
Separate screen and print presentation
If the same HTML is viewed in a browser and converted to PDF, put PDF-only adjustments in @media print. MDN describes the print media type as applying styles to printed content, and documents @page for page dimensions, orientation, and margins.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
@page {
size: A4 portrait;
margin: 16mm 14mm 18mm;
}
@media print {
.screen-only {
display: none !important;
}
a {
color: #000;
text-decoration: none;
}
}
This is a starting point, not a guarantee that every engine will honor every declaration. If the PDF API has its own page-layout setting, determine whether it takes precedence over CSS or is needed in addition to it.
Set page geometry before tuning individual elements
Page size and margins establish the usable content area. A template that looks balanced on a wide browser window can overflow or paginate awkwardly when constrained to a paper page. Start with the intended page dimensions and orientation, then adjust the content width, typography, and spacing against that page.
Choose a page size and orientation
Use @page when the engine supports CSS paged-media rules. For example, size: A4 portrait requests portrait A4 pages; a landscape document can use size: A4 landscape. Managed conversion APIs may instead expose dimensions as request settings. Adobe PDF Services’ HTML-to-PDF example uses a pageLayout with page width and height, so check the specific interface you use rather than assuming CSS is its only source of page geometry.
Set margins deliberately
The printable content area is the page minus its margins. The three-value margin in the example sets top, left-and-right, and bottom margins respectively. Reserve enough room for any content that must appear at page edges, and check whether your renderer supports margin boxes or requires headers and footers through a separate API option. CSS margin boxes are not uniformly supported across engines.
When a CSS page size appears to be ignored, compare the rendered page dimensions with the renderer’s request options. A renderer-level page layout can be the controlling setting. Keep a known-good fixture and change one geometry input at a time so you can identify which setting governs the output.
Rank #2
Control pagination with the renderer you deploy
PDF layout is paged layout, not simply a screenshot sliced at page boundaries. Long content must be fragmented; headings, rows, and paragraphs can land near page edges. The precise effect of page-break and fragmentation rules depends on the engine’s supported CSS subset.
Keep related content together where possible
For a heading that should remain with the following content, try a break-avoidance rule and inspect the output:
@media print {
h1, h2, h3 {
break-after: avoid;
page-break-after: avoid;
}
.keep-together {
break-inside: avoid;
page-break-inside: avoid;
}
}
These declarations are requests to the renderer, not a promise that an oversized block can fit on one page. If an element is taller than the available page area, the engine may still split it or move it. Test the actual content lengths your application generates.
Recommended Free Tools
Test long tables and repeated headings
Tables are a common source of pagination surprises. Check a short table, a table that crosses a page boundary, and a table with unusually long cells. If column headers must repeat, verify that behavior in your engine; do not infer it from how a browser displays the table. Also inspect borders, row backgrounds, and cell padding after a page break.
Use widows and orphans only after testing
TCPDF documents support for widows and orphans, as well as page-break controls and the print media type. These properties can influence how many lines remain at the top or bottom of a page, but their actual effect is renderer-specific. Treat them as layout controls to validate, not universal guarantees.
Fonts, images, links, and accessibility are part of the template
A PDF can have correct page dimensions and still be wrong because a font fell back, an image failed to load, or an important link became unusable. Include asset and accessibility checks in the template workflow.
- Fonts: load approved fonts using a format and loading method supported by the renderer. Test every required writing system and verify fallback behavior; one successful Latin-script sample does not establish support for other scripts.
- Images: verify that the renderer can reach each image in its execution environment. Check scaling, clipping, transparency, and alternative text in the final PDF.
- Links: inspect whether links remain clickable and whether their visual styling is legible in print. The baseline example turns link text black and removes underlines, but that may make links less obvious to readers; choose a style appropriate to the document.
- Generated content: test counters, pseudo-elements, and other generated content in the PDF itself. Do not depend on a browser preview as proof that the renderer will produce the same result.
- Semantic markup: use meaningful heading levels, paragraphs, lists, and table structure. TCPDF documents that PDF/UA mode maps heading levels, tags text runs, and converts image
alttext into/Altentries. Semantic HTML and useful alternative text therefore belong in the template contract, not just its visual styling.
Check the renderer’s CSS contract
Choose CSS based on the PDF engine’s documented support, not on what works in a modern browser. iText’s documentation for pdfHTML 6.3.3 with iText Core 9.7.0 provides a feature matrix. Its documented paged-media support includes @page, page size, margins, page-break controls, counters, colors, and some margin-box features; it also identifies unsupported features, including named strings. Those version-specific details should not be generalized to other releases or engines.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
TCPDF documents support for type, class, and ID selectors and several combinators, along with box-model properties, typography, page-break controls, orphans, widows, and the print media type. That list is a useful starting point for TCPDF templates, not a statement about every HTML-to-PDF library.
Until support is confirmed, keep selectors simple and avoid making a document depend on browser-specific JavaScript layout, CSS Grid, advanced generated content, or a particular font format. If the design requires one of those features, make a small test document first and render it with the pinned engine version.
A reliable implementation workflow
- Define semantic HTML and stable classes. Separate document structure from visual styling so a layout fix does not require rewriting content.
- Add the base stylesheet. Set readable typography, widths, colors, and spacing for the document’s content.
- Add a print layer. Place rules that apply only to PDF or print output inside
@media printwhen the template also serves screen content. - Set page size and margins. Use
@pagewhere supported, and check whether your renderer’s API requires or overrides page-layout options. - Load fonts and assets. Confirm that the rendering environment can access them and test fallback behavior for every required script.
- Add pagination rules. Test page breaks, long tables, headings near page bottoms, and widows or orphans using representative content.
- Inspect the resulting PDF. Check geometry, clipping, images, generated content, links, reading structure, and accessibility tags that matter to your output.
- Pin the renderer version and retain regression fixtures. Keep representative short and long documents, including edge cases, and compare their PDFs after changes to the template or rendering stack.
Or skip the browser setup
If your task is to capture a rendered webpage rather than maintain a custom HTML-to-PDF template, ScreenshotNeo is a website screenshot API and MCP server. It can return PNG, JPEG, WebP, or PDF output; it is a capture service, not a substitute for testing CSS support in your chosen code-based PDF renderer.
Rank #4
- Format: Comb Bound Book & Online PDF/Audio
- Version: Book & Online PDF/Audio
- Category: General Music and Classroom Publications
- Contributors: By Sally K. Albrecht
- Pub Date: 5/2012
For a one-call screenshot, use the API’s documented request form below. See the ScreenshotNeo documentation for PDF options and the current request parameters; this example requests a WebP screenshot and does not invent PDF parameter syntax.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common PDF CSS problems
The PDF ignores my @page size or margins
Check the renderer’s page-layout request options and its documented paged-media support. An API-level width and height may govern the page, as in Adobe PDF Services’ example. Test one setting at a time and inspect the actual PDF page dimensions.
A browser preview looks right, but the PDF does not
The browser and PDF engine may support different CSS features or apply pagination differently. Reduce the example to the affected element, use simpler selectors and properties, and compare against the engine’s supported-feature documentation. Confirm the exact renderer version as well as the CSS rule.
A heading is stranded at the bottom of a page
Try a break-avoidance rule on the heading, then test it with short and long following content. If the block cannot fit in the remaining space, it may move to the next page or still split; confirm which behavior your engine implements.
Rows split or table headers do not repeat
Use a fixture with enough rows to cross a page boundary. Test the engine’s documented page-break behavior on rows and header groups, and avoid assuming a browser table’s behavior will carry over to the PDF. If the output is still unsuitable, consider changing the table’s structure or page layout.
Best Value
- 3.7" Pocket eBook Reader, Only Approx. 58g: Take your library anywhere with the XTEINK X3, a compact 3.7-inch lightweight eReader designed for everyday portability. Weighing approximately 58g and measuring just 5.1mm thin, it easily slips into your pocket or bag, making it ideal for reading during commutes, while traveling, or during quick breaks.
- Paper-feel E-Ink Reading, Made for Focus: Enjoy a clean, paper-feel E-Ink reading experience that feels gentle on the eyes and helps you stay focused. No constant notifications, no social media distractions—just a simple mini eReader built for books, manga, notes, and quiet reading time.
- Gyroscope Page-Turn + Physical Buttons: Read comfortably with one hand using gyroscope page-turn control and responsive physical buttons. Whether you are standing, commuting, or relaxing, XTEINK X3 makes page turning smoother, easier, and more intuitive than traditional touch-only reading devices.
- Personalized Features & Long-Lasting Battery:Switch between reading, photos, clock, and more for a customizable experience beyond traditional eReaders. Designed for everyday portability, XTEINK X3 delivers up to 10 hours of reading time, supporting about a week of casual reading on a single charge. For safe charging, use a locally certified charger and keep conductive objects away from the charging pin contacts during charging to help prevent short circuits.
- Magnetic-Ready Design with Pogo-Pin Charging: XTEINK X3 includes an Adhesive Metal Ring to enable magnetic attachment on compatible non-magnetic phone cases or surfaces, expanding compatibility for everyday use. The magnetic pogo-pin charging design maintains a clean, minimalist appearance while supporting convenient daily charging.
Text changes shape or characters disappear
Check whether the intended font loaded and whether it covers the affected script. Verify the renderer’s supported font formats and fallback behavior, then test with a sample containing the actual characters your users need.
Images or external styles are missing
Check asset paths and access from the renderer’s runtime environment, not only from your local browser. Confirm that the renderer can retrieve the resource and that the chosen format is supported. A small self-contained fixture can help isolate loading from layout problems.
Compare engines on the requirements that matter
CSS coverage is only one selection criterion for an HTML-to-PDF engine. Compare the properties and operational constraints your documents actually need:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →- CSS and pagination: required selectors, page geometry, fragmentation, generated content, and repeated table headings.
- Assets and scripting: font and image loading, external resource access, and whether JavaScript-driven layout is necessary.
- Accessible output: whether the engine supports tagged output or PDF/UA workflows needed for your documents. iText documents PDF/UA and PDF/A support; TCPDF documents tagged output in PDF/UA mode.
- Deployment and licensing: whether its runtime, licensing, and hosting model suit your application.
- API ergonomics: how page dimensions, headers, footers, and conversion options are configured, and how easily the renderer fits your existing template pipeline.
The primary documentation for the engines describes features, not a comparable renderer-neutral performance benchmark. There is no sound basis here for claiming one engine is universally faster; measure your own representative documents if throughput is a deciding factor.
Quick Recap
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.

