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 →WeasyPrint converts HTML and CSS into paginated PDF files through a Python-based rendering engine. You can run it from the command line or call its Python API, but it does not behave like a full browser: JavaScript-driven interfaces, browser-only CSS, cookies and authenticated assets require extra planning. This guide covers installation, reliable resource loading, styling, fonts, security, troubleshooting and production upgrades for WeasyPrint 70.0, released on September 8, 2026.
What WeasyPrint does—and what it does not
WeasyPrint’s official description calls it “a visual rendering engine for HTML and CSS that can export to PDF.” Its layout engine is written in Python and designed for print pagination rather than interactive browsing. It is free software under a BSD license. Read the official API reference for the version-70.0 behavior.
That distinction determines whether it is a good fit. WeasyPrint is effective for invoices, reports, certificates, books, statements and other documents whose content is available as HTML and CSS before rendering. It does not execute a web application as a user’s browser would. A page that needs JavaScript to insert text, open a menu or complete a login may produce an incomplete PDF unless you supply the final HTML yourself or use a browser-rendering service.
Core capabilities
- HTML files, file objects and absolute URLs can be rendered.
- CSS print rules, page sizes, margins, counters, generated content and many selectors are supported.
- PDFs can include hyperlinks, bookmarks, attachments and forms.
- SVG images remain vector content in the PDF.
- PDF/A and PDF/UA output can be requested, but generated files are not guaranteed to pass those standards’ validators.
Important differences from a browser
- Interactive pseudo-classes such as
:hoverand:focusdo not match in a normal non-interactive PDF. - Some bidirectional-text, selector and table cases are documented as unsupported or limited.
- JavaScript is not a general solution for populating the document.
- Rendering can change between major releases even when the Python API remains compatible.
Install WeasyPrint 70.0
The current documentation lists Python 3.10 or newer and native dependencies such as Pango and pydyf. Start in an isolated virtual environment:
Recommended Free Tools
#1 Best Overall
- Confirm your interpreter:
python3 --version. Use Python 3.10 or later. - Create and activate an environment:
python3 -m venv venv, thensource venv/bin/activateon macOS/Linux orvenvScriptsactivateon Windows. - Install the package:
pip install weasyprint. - Verify the installation and native libraries:
weasyprint --info.
Operating-system packages may be required for Pango and related libraries. If installation fails after pip install, check the platform installation instructions in the project documentation and inspect the output of weasyprint --info before changing Python code.
Convert HTML to PDF from the command line
The command-line form is:
weasyprint [options] <input> <output>
Input and output can be filenames, URLs or - for standard input/output. A local conversion is therefore:
weasyprint report.html report.pdf
For a remote document:
weasyprint https://example.com/report.html report.pdf
Use an external stylesheet and a base URL
weasyprint
--stylesheet print.css
--base-url /srv/reports/
report.html report.pdf
The base URL is essential when HTML contains relative paths such as images/logo.svg or fonts/report.woff2. You can also set a <base href="..."> element in the document. Without a correct base, the HTML may render while images, stylesheets or fonts silently fail.
Options that matter in automation
--media-typechooses the CSS media type; it defaults toprint.--timeoutlimits network retrieval time.--allowed-protocolsrestricts URL schemes.--no-http-redirectsdisables HTTP redirects.--fail-on-http-errorsmakes HTTP failures terminate the command instead of producing a partial document.--stylesheetadds one or more user stylesheets.
See the command-line reference for the exact options available in your installed release.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Convert HTML to PDF with Python
The basic API imports HTML and writes a PDF target:
from weasyprint import HTML
HTML(filename="report.html").write_pdf("report.pdf")
You can render an absolute URL or a file-like object instead:
Rank #2
from weasyprint import HTML
HTML(url="https://example.com/report.html").write_pdf("report.pdf")
Return PDF bytes
Omit the target to receive bytes, which is useful in a web response or object-storage upload:
from weasyprint import HTML
pdf_bytes = HTML(string="""
<!doctype html>
<html><body><h1>Monthly report</h1></body></html>
""").write_pdf()
with open("report.pdf", "wb") as output:
output.write(pdf_bytes)
Supply a reliable base URL for HTML strings
from weasyprint import HTML
html = HTML(
string=html_text,
base_url="/srv/reports/"
)
html.write_pdf("report.pdf")
This lets relative images, CSS and fonts resolve exactly as they do for a file-based document.
Custom CSS and fonts
When CSS uses @font-face, create a FontConfiguration and reuse the same instance for the stylesheet and document:
from weasyprint import CSS, HTML
from weasyprint.text.fonts import FontConfiguration
font_config = FontConfiguration()
css = CSS(
filename="print.css",
font_config=font_config,
)
HTML(filename="report.html").write_pdf(
"report.pdf",
stylesheets=[css],
font_config=font_config,
)
Check font coverage for every language you output. If a glyph is missing, WeasyPrint may emit a warning and place the font’s .notdef glyph instead.
Design HTML and CSS for pagination
Use print-oriented CSS rather than copying assumptions from a responsive web page:
@page {
size: A4;
margin: 18mm 16mm 20mm;
}
body {
font-family: "Noto Sans", sans-serif;
font-size: 10.5pt;
line-height: 1.45;
color: #222;
}
h1, h2, h3 {
break-after: avoid;
}
table {
width: 100%;
border-collapse: collapse;
}
thead {
display: table-header-group;
}
tr, img {
break-inside: avoid;
}
Choose a page size and margins explicitly, keep wide tables within the content box, and test long headings, repeated table headers, footnotes and images at page boundaries. A browser preview is not proof that the PDF will paginate identically.
Images, links and remote resources
WeasyPrint’s URL handling supports file, HTTP, FTP and data URLs by default. Relative resources depend on the document base URL. The default HTTP client does not support cookies or authentication; pages that require either need a custom URL fetcher or pre-fetched assets embedded in the document.
For predictable builds, download authenticated images and stylesheets in your application, store them in an accessible directory, and render with a controlled base URL. Use --allowed-protocols or an API URL fetcher to prevent unexpected schemes. Hyperlinks in the resulting PDF can remain clickable even though the source page was not rendered by a browser.
Security for untrusted HTML
Do not treat WeasyPrint as a sandbox. The official security guidance warns: “When used with untrusted HTML or untrusted CSS, WeasyPrint can meet security problems.” Malicious input can cause excessive render time, high CPU or memory use, or access to local files available to the process. Untrusted SVG requires the same care because it uses the URL fetcher.
- Run the renderer as a non-root user.
- Restrict filesystem and network permissions.
- Set process, memory and time limits.
- Use a custom URL fetcher that allows only approved paths and protocols.
- Separate conversion workers from application credentials and sensitive files.
For a public conversion endpoint, isolate each job in an appropriate container or sandbox and reject oversized HTML, CSS, images and SVG before rendering.
Version 70.0 and upgrade discipline
WeasyPrint 70.0 was released on September 8, 2026 and is recorded as a security update associated with CVE-2026-55073 and GHSA-r543-q48m-4c9j. The changelog recommends upgrading for deployments that embed untrusted images or use the URL fetcher to filter metadata or stylesheets passed as Python parameters.
Pin the version in production, read the changelog before upgrades, and keep representative PDFs as regression fixtures. Compare page count, text placement, font selection, links and bookmarks after every major-version change; API compatibility does not guarantee identical rendering.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common failures
“cannot load library” or Pango errors
Cause: a missing native dependency or incompatible system library. Fix: install the platform’s Pango and related packages, recreate the virtual environment if necessary, then run weasyprint --info.
Images or CSS are missing
Cause: relative URLs resolve against the wrong directory. Fix: set --base-url, pass base_url to HTML, or add an HTML <base> element; verify the file is readable and the URL scheme is allowed.
PC 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 & 11Crashes, 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 minuteAuthenticated resources return 401 or 403
Cause: the default HTTP client does not send your browser cookies or login headers. Fix: fetch the resources yourself, embed them, or implement a custom URL fetcher with tightly scoped credentials.
Text displays as empty boxes
Cause: the selected font lacks required glyphs. Fix: install a font covering the language, declare it with @font-face, provide FontConfiguration, and inspect warnings.
JavaScript content is absent
Cause: the document depends on browser-side execution. Fix: render the final HTML before calling WeasyPrint, or choose a browser-based capture workflow for pages whose content exists only after scripts run.
Output changed after an upgrade
Cause: rendering behavior can change across major versions. Fix: compare regression PDFs, review the changelog and update CSS or pinned dependencies deliberately.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
Or skip the browser setup
When your input is a live website rather than a prepared HTML document, ScreenshotNeo provides a single-request capture API and PDF output. It accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each 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. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For API parameters and PDF options, see the ScreenshotNeo documentation. One thousand screenshots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
When to choose each approach
- Choose WeasyPrint when you control the HTML, need repeatable print CSS, want a Python or CLI workflow, and can provide resources without browser cookies or JavaScript.
- Choose a live-site capture API when the target is an interactive website, consent handling, lazy loading or browser execution is central, or you need an MCP workflow for AI agents.
- Validate either output by opening the PDF, checking fonts and links, testing representative page breaks and enforcing resource and time limits in production.
Frequently Asked Questions
Does WeasyPrint require a browser such as Chrome?
No. WeasyPrint has its own Python-based HTML/CSS layout engine and does not require Chrome, WebKit or Gecko. Browser-only behavior, including JavaScript-rendered content, is therefore not automatically reproduced.
Can WeasyPrint generate PDF/A or PDF/UA files?
It can generate output intended for those standards, but the documentation does not guarantee that every generated file will pass PDF/A or PDF/UA conformance validation. Validate files with the tool required by your workflow.
Is WeasyPrint suitable for converting arbitrary public URLs?
Only when the URL’s content and resources are accessible without unsupported browser behavior, cookies or authentication. For untrusted URLs, apply strict network, filesystem, CPU and memory isolation.
The Bottom Line
WeasyPrint is a strong choice for controlled, print-focused HTML and CSS: install version 70.0, set a correct base URL, configure fonts, sandbox untrusted input and regression-test PDFs after upgrades. Use a browser-based capture service instead when the source depends on JavaScript, login state or live-site interaction.
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.

