Skip to main content
WeasyPrint ships with the pdf extra and converts HTML and CSS to PDF.

Basic usage

Build the document from a Jinja template, the same way you build a page. It escapes what people typed, so a card titled <img src=...> prints as text instead of becoming markup.
Return it from a route as a download:
Don’t build the HTML with an f-string. Nothing is escaped, and anything a user typed becomes markup in the PDF, including tags that make WeasyPrint fetch URLs.
Keep the stylesheet free of template variables too. A running footer that repeats the title takes it from the page with string-set, so nothing a user typed is ever parsed as CSS:
The Docker image Feather generates installs fonts-inter and fonts-dejavu-core. The slim base image has no fonts of its own, so without them a PDF rendered in production has no typeface for its text. Name a font the image has (font-family: "Inter", "DejaVu Sans", sans-serif) or bundle your own.

Saving to storage

Generating in the background

Rendering is slow enough to be worth moving off the request.