talira

WeasyPrint

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 toolplan not known
Has official SDKsplan not known

Alternatives

The same job

These do what WeasyPrint does.

  1. ironpress HTML to PDF. In process. In pure Rust.
  2. DocRaptor The World's Most Advanced HTML to PDF API
  3. ReportLab The print button for eBusiness
  4. Prince Convert HTML to PDF. Beautiful printing with simple CSS.
  5. Gotenberg A Docker-based API for PDF
  6. Puppeteer JavaScript API for Chrome and Firefox

Compare WeasyPrint with the top 3