weasyprint
Convert HTML documents to PDF
TLDR
Render an HTML file to PDF
Render an HTML file to PNG, including an additional user stylesheet
Output additional debugging information when rendering
Specify a custom resolution when outputting to PNG
Specify a base URL for relative URLs in the input HTML file
SYNOPSIS
weasyprint [options] INPUT [OUTPUT]
PARAMETERS
INPUT
Path or URL of the HTML input file.
OUTPUT
Path of the PDF output file. If omitted, the PDF is written to standard output.
-e, --encoding ENCODING
Character encoding for the input HTML file. Defaults to UTF-8.
-s, --stylesheet STYLESHEET
Path or URL of a CSS stylesheet to apply.
-m, --media-type MEDIA_TYPE
Media type to use for CSS @media rules (e.g., print, screen).
-u, --base-url BASE_URL
Base URL to use for resolving relative URLs in the HTML.
-w, --presentational-hints
Follow presentational hints, e.g. margin=auto, to be deprecated.
--pdf-variant PDF_VARIANT
PDF variant. Can be: pdf/a-1b (PDF/A level B conformance), pdf/a-3b (PDF/A level B conformance), pdf/ua-1 (PDF/UA conformance), pdfx-1a (PDF/X level 1a conformance), or pdf (default).
--version
Show the version number and exit.
-v, --verbose
Enable verbose output.
-q, --quiet
Suppress all output except errors.
-h, --help
Show help message and exit.
DESCRIPTION
WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing. It's written in Python but relies heavily on external libraries for parsing HTML, CSS, and handling graphics. WeasyPrint excels at generating PDF documents from HTML sources, providing relatively faithful rendering compared to web browsers, especially with print-specific stylesheets. It’s often used in server-side applications for generating invoices, reports, and other documents intended for printing or archival purposes. The command-line tool offers a simple way to convert a single HTML file or a list of files to PDF or to standard output.
It’s designed to be a solid foundation for complex document generation workflows.
CAVEATS
WeasyPrint's CSS support is not 100% complete, so some complex layouts may not render perfectly. Performance can also be a consideration for large or complex documents.
CONFIGURATION
WeasyPrint often needs external libraries to be correctly configured in the system. For example: cffi, Cairo, Pango and GDK. Correct configuration is important for correct PDF generation.
HISTORY
WeasyPrint was created as a project aiming to be a better tool for PDF generation from HTML with focus on web standards and print capabilities. It’s been actively developed and maintained, becoming a popular choice for server-side PDF generation.
SEE ALSO
wkhtmltopdf(1), prince(1)