Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsContext-aware PDF styling means applying presentation rules to a document’s structure, position, and page context—not merely assigning a font to every paragraph. In an HTML/CSS workflow, you can change page size and margins, place content in running headers and footers, style the first or blank page differently, control page breaks, and reduce awkward orphaned lines. WeasyPrint documents these features through CSS paged media, while also documenting important limits that you must verify against the version installed in your project.
What context-aware styling changes
A generated PDF has at least two kinds of context:
- Content context: a heading, table, warning, image, or code block may need a different treatment from ordinary prose.
- Page context: the first page, a blank page, an odd or even page, or a page reached after a forced break may need different margins, headers, or footers.
CSS paged media connects those contexts to print layout. The CSS Paged Media specification is described by WeasyPrint as a working draft, so support is implementation-specific rather than a guarantee shared by every PDF generator.
Choose the rendering model first
HTML and CSS with WeasyPrint
WeasyPrint is a practical example when your source is semantic HTML and your design can be expressed with CSS. Its documentation covers @page, page-margin boxes, page counters, named pages, running elements, and selectors such as :first and :blank. The stable API documentation can represent a different release from the one installed in your environment; check the version-specific documentation before depending on a feature.
Programmatic drawing with ReportLab
ReportLab takes a different approach: Python code places text, graphics, and flowables on a canvas or through its document templates. It can expose options for language, image descriptions, and title metadata, but those options do not by themselves prove accessibility conformance. A useful principle from ReportLab documentation is that “A large part of the accessibility score depends on the scripts you use to generate them and the content you put in.”
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Do not assume that a CSS rule accepted by WeasyPrint will work in ReportLab, or that a ReportLab feature exists in an HTML renderer. Compare engines by the paged-media features you actually need, their documented limitations, integration requirements, font and asset behavior, and required output variants.
Build a semantic source document
Context-aware rules are easier to maintain when the HTML identifies meaning rather than appearance. Use h1 through h3 for headings, table for tabular data, figure and figcaption for illustrations, and lists for lists. Give recurring elements classes that describe their role, such as running-header, cover, warning, or appendix.
Keep content and presentation separate. The template supplies the structure and data; the stylesheet supplies page geometry, typography, flow, and page-specific decoration. This makes it possible to change a report from A4 portrait to US Letter landscape without rewriting the content.
Control page size, orientation, and margins
WeasyPrint’s use-case documentation recommends CSS @page for page size and margins. A minimal stylesheet is:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →@page {
size: A4 portrait;
margin: 22mm 18mm 24mm;
}
body {
font-family: "DejaVu Sans", sans-serif;
font-size: 10.5pt;
line-height: 1.45;
color: #202124;
}
Replace A4 portrait with Letter landscape when that is your target. Keep the physical units explicit. A change in page size affects line wrapping, table width, image scaling, and therefore the number of pages.
Different geometry for a cover
Named pages let an element request a page definition. For example:
@page cover {
size: A4 portrait;
margin: 0;
}
.cover {
page: cover;
min-height: 297mm;
display: flex;
align-items: center;
justify-content: center;
}
@page {
size: A4 portrait;
margin: 22mm 18mm 24mm;
}
Named-page behavior and interactions with forced breaks are renderer features; verify the result with the release you deploy.
Rank #2
Style the first, blank, and subsequent pages
First-page selector
Use :first for a first-page margin or header difference:
Recommended Free Tools
@page :first {
margin-top: 30mm;
margin-bottom: 25mm;
}
@page :first {
@top-center { content: none; }
}
Page-margin boxes such as @top-center, @bottom-right, and related positions are where running content and counters are placed. Margin-box syntax and supported combinations should be checked in the WeasyPrint documentation because paged-media support has boundaries.
Blank pages
Blank pages can appear when a chapter is required to begin on a right-hand page or when a forced break interacts with named pages. A :blank rule can suppress decoration:
@page :blank {
@top-left { content: none; }
@top-center { content: none; }
@top-right { content: none; }
@bottom-center { content: none; }
}
Do not hide content accidentally: confirm whether the page is truly blank and whether your renderer supports the selector as written.
Add running headers, footers, and page numbers
Running elements allow a heading or other element to be collected and displayed in a page-margin box. A common pattern is:
header.running-header {
position: running(doc-header);
font-size: 8.5pt;
color: #5b6470;
}
@page {
@top-center { content: element(doc-header); }
@bottom-right {
content: "Page " counter(page) " of " counter(pages);
font-size: 8pt;
}
}
Put <header class="running-header">Project status report</header> in the document. The counter(page) value is the current page; counter(pages) requires support for the total-page counter in the renderer version you use.
For alternating pages, define separate rules when your implementation supports page-side selectors, and test the first, odd, and even pages. A header that is too wide can collide with the content area, so reserve space through the page margins rather than relying on overlap.
Rank #3
Make content flow predictably
Keep headings with the following content
h1, h2, h3 {
break-after: avoid;
}
h2 + p,
h2 + ul,
h2 + table {
break-before: avoid;
}
Use the break properties documented for your renderer. Older or partial implementations may support legacy aliases differently.
Prevent bad row and paragraph splits
table, figure, .callout {
break-inside: avoid;
}
p, li {
orphans: 3;
widows: 3;
}
These declarations are preferences, not an absolute promise that every complex object will stay together. A table longer than a page must split somewhere; design a repeating header row and make each row understandable when separated.
Force a deliberate section break
.chapter {
break-before: page;
}
.keep-with-next {
break-after: avoid;
}
Use forced breaks sparingly. Overuse produces nearly empty pages when a preceding block already ends near a page boundary.
Style by content type
Tables
Set column widths, borders, and a repeating header row. Avoid fixed widths that exceed the printable area.
table {
width: 100%;
border-collapse: collapse;
font-size: 9pt;
}
thead { display: table-header-group; }
th, td {
border: 0.2mm solid #b9c0c8;
padding: 2mm;
vertical-align: top;
}
Code and long tokens
Long URLs, hashes, and source lines can force overflow. Allow breaking where your renderer supports it, reduce the code font slightly, and provide a wrapping alternative rather than clipping text.
pre, code {
font-family: "DejaVu Sans Mono", monospace;
}
pre {
white-space: pre-wrap;
overflow-wrap: anywhere;
background: #f3f5f7;
padding: 3mm;
}
Images and captions
Use explicit dimensions or a maximum width, preserve aspect ratio, and provide meaningful alternative text in the source. Large raster images increase memory use and can move nearby content across page boundaries.
Fonts, glyphs, and assets
Font availability is part of layout correctness. WeasyPrint’s API documentation notes that unsupported glyphs may fall back to a “notdef” glyph and produce a warning. Package the fonts your deployment is licensed to use, declare a deterministic fallback stack, and test representative multilingual text, symbols, and emoji separately. A missing glyph can change line width or make a document unreadable even when the CSS is valid.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Resolve images, stylesheets, and fonts through a controlled base URL or asset resolver. A file that loads in a browser from a relative path may fail when the PDF process runs from a worker directory.
Generate a PDF with WeasyPrint
Install WeasyPrint according to its platform documentation, then render a complete HTML document. This example uses Python and a local stylesheet:
from pathlib import Path
from weasyprint import HTML, CSS
html_path = Path("report.html").resolve()
css_path = Path("print.css").resolve()
HTML(filename=str(html_path), base_url=str(html_path.parent)).write_pdf(
"report.pdf",
stylesheets=[CSS(filename=str(css_path))],
)
The base_url is important for relative images, fonts, and linked assets. In a web application, pass a controlled base URL and sanitize user-provided content; do not allow arbitrary local-file access.
Accessibility is more than visual styling
Language metadata, image descriptions, document title, heading order, table headers, link text, and reading order all affect usability. ReportLab documents language, image-description, and title options, while WeasyPrint’s current stable API documents PDF tagging as an output option. Neither a metadata field nor a tagging flag alone establishes conformance. Inspect the generated PDF with an accessibility checker and review it with assistive technology when accessibility is a requirement.
Validate representative pages before shipping
- Render a short document and a document long enough to create several page transitions.
- Check the cover, first content page, odd and even pages, and any intentionally blank page.
- Include a long table, a multi-paragraph section, a large image, and a forced chapter break.
- Use multilingual text and characters outside your primary font’s coverage.
- Confirm that headers, footers, counters, links, metadata, and tagged output match your requirement.
- Open the PDF in more than one viewer and archive the renderer version with the build.
This validation is especially important because WeasyPrint documents limitations and does not guarantee valid PDF output for every combination of HTML, CSS, and PDF features.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting context-aware PDF layouts
Header or footer overlaps body text
Increase the corresponding @page margin, reduce the running element’s height, and verify that the margin box is supported. Do not solve overlap by adding arbitrary padding to every paragraph.
A chapter starts on an unexpected blank page
Inspect the interaction between break-before, named pages, and a right-hand-page requirement. Remove redundant forced breaks and test @page :blank only after confirming which page is blank.
Best Value
Page numbers show the wrong total
Check whether your installed WeasyPrint release supports the pages counter in the location where it is used. If it does not, show the current page only or generate totals through a supported post-processing step.
Text contains empty boxes or warnings
The selected font lacks a glyph. Install or embed a font that covers the character set, define a fallback, and inspect renderer logs. Do not treat a successful process exit as proof that every glyph rendered correctly.
Images or fonts disappear
Fix the HTML base URL or asset resolver, use readable file permissions, and ensure worker environments contain the same assets as development. Avoid untrusted URLs when your renderer can access local files.
The PDF is valid but not accessible
Check document language, title, heading hierarchy, alternative text, table structure, link destinations, and tagging with a dedicated checker. Appearance alone cannot establish accessibility.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Or skip the browser setup
If your immediate need is a clean visual capture of an HTML page for review, documentation, or an approval workflow, ScreenshotNeo provides a one-request screenshot API. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.
Use the same URL with the language that fits your build:
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the ScreenshotNeo documentation for output and option details. Its MCP server lets Claude, Cursor, and other MCP clients use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account to try it.
Frequently Asked Questions
Can CSS choose a different header for every section?
It can when the renderer supports running elements, named pages, or equivalent mechanisms. Define the section semantics in the source, then verify the exact behavior in your installed version rather than assuming browser CSS support.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Why does the same HTML produce a different page count after deployment?
Page count depends on renderer version, available fonts, asset loading, page dimensions, and content. A fallback font or missing image can change line wrapping and page breaks; keep these inputs consistent and record the renderer version.
Is a PDF with tags automatically accessible?
No. Tags or metadata are only part of accessibility. Language, title, headings, alternative text, table structure, reading order, and actual content still need review and testing.
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.




