Renders HTML and CSS to PDF, from Python or the command line
open sourceBSD-3-Clauseself-hostablefree
WeasyPrint is a Python library and command-line tool that renders HTML and CSS to PDF. It is not built on a browser engine such as WebKit or Gecko: its CSS layout engine is written in Python and designed for pagination, aiming to support the web standards for printing (paged media). It suits reports, invoices, tickets, books and letters made from HTML you control. It was created by Kozea, and CourtBouillon provides maintenance and paid professional support.
Ways to install
Package managers
Problems it solves
- generate invoice PDFs from Django templates without running a headless browser
- I need running page headers, footers and page X of Y using CSS @page rules
- Python HTML to PDF that doesn't need Chrome installed on the server
- our xhtml2pdf output ignores half of our CSS
- build a printable report with a table of contents and different layouts per page
- make print-ready books and booklets from HTML with a separate print stylesheet
- turn a Flask view into a downloadable PDF in a few lines of code
- need hyphenation and proper page breaks in long documents generated from HTML
- render PDFs inside a slim Python container where Chromium is too heavy
- replace wkhtmltopdf in our Python app now that it's no longer maintained
- print event tickets with barcodes from HTML templates
Features
- HTML and CSS to PDF
- CSS layout engine designed for pagination
- headers, footers and page layouts via CSS paged media
- table of contents
- PDF form inputs
- alternate print stylesheets
- command-line interface
Limitations
- Doesn't run JavaScript in the HTML it converts2
- Doesn't output images (PNG): PDF is its only output format3
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Has official SDKs | plan not known |
Alternatives
The same job
These do what WeasyPrint does.