WeasyPrint

KozeaBSD-3-Clause活跃维护

用 HTML 和 CSS 直接生成 PDF 的 Python 库,支持分页、页眉页脚和复杂排版,适合做报表、发票和电子书导出。

The awesome document factory

v70.0发布于 2026-09-08 12:31 UTC9,779star +17 / 7 天901fork同步于 2026-11-10 17:30 UTC

怎么上手

由 README 提炼,执行前请确认
pip install weasyprint
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把 HTML/CSS 渲染成 PDF 的 Python 排版引擎,适合生成报表、发票和票据

用 HTML 和 CSS 直接生成 PDF 的 Python 库,支持分页、页眉页脚和复杂排版,适合做报表、发票和电子书导出。

核心能力

  • 用 Python 编写的 CSS 布局引擎,专为分页设计
  • 将简单 HTML 页面导出为 PDF 文档
  • 不依赖 WebKit 或 Gecko 等完整渲染引擎
  • 支持打印相关的 Web 标准
  • 采用 BSD 许可,代码易于修改

容易踩的坑

需要 Python 3.11 及以上版本;README 未说明其他依赖或额外模型下载要求

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v70.0
  1. v70.0最新正式版2026-09-08 · 2026-09-08 12:31 UTC

    Read about this release on our blog.

    This is a security update (CVE-2026-55073, GHSA-r543-q48m-4c9j).

    We strongly recommend to upgrade WeasyPrint to the latest version if you: * embed untrusted images, or * rely on the URL fetcher to filter metadata or stylesheets passed as Python parameters.

    Security

    • Don’t render EPS images.
    • Always use original URL fetcher when available.

    Features

    • #2905: Add initial support of CSS Notes, with financial support from NLnet
    • #2731, #2781: Log an error on unknown render and write_pdf options
    • #2802, #2805: Create immutable releases on GitHub
    • #2809, #2810: Switch to MSYS2 UCRT64 environment for Windows tests and executables
    • #2777, #2814: Support COLR emoji fonts
    • #2667, #2744: Support context paint in SVG markers
    • #1862, #2844: Improve filename detection for attachments
    • #2816, #2827: Set SVG title as alternative text
    • #2718: Provide a 'onedir' Windows executable
    • #2863: Support box-shadow
    • #2755: Support RTL SVG text anchoring
    • #2866: Don’t use f-strings in logs

    Bug fixes

    • #2799: Keep HarfBuzz font faces alive during PDF subsetting
    • #2764, #2793: Accept Path as base URL in CSS
    • #2800, #2801: Fix position of raster emojis
    • #2782, #2807: Use POSIX paths in Fontconfig
    • #2766, #2779: Use response bytes when image file path doesn’t exist
    • #2277, #2728: Honor page breaks on floated elements
    • #2789, #2818: Use base URL when solving pending properties
    • #2820: Ignore unresolvable math in image slices
    • #2901, #2825: Transform SVG size into CSS to apply CSS sizing algorithm
    • #2819: Resolve calc() division by zero to infinity
    • #2824: Remove old deprecation warnings
    • #2762, #2780: Set SVG gradient color before path construction
    • #2761: Handle split tables with captions
    • #2215, [#2747](https://github.com/Ko
  2. v69.02026-06-02 · 2026-06-02 14:42 UTC
    查看更新说明

    This is a security update (CVE-2026-49452).

    We strongly recommend to upgrade WeasyPrint to the latest version if you use the --presentational-hints option and render untrusted HTML with restricted CSS properties.

    Read about this release on our blog.

    Security

    • Avoid CSS injection with HTML presentational hints.

    Command-line API

    • The --srgb option has been replaced by --output-intent=srgb. Other values are possible: device-cmyk for CMYK documents with no ICC profile, or the CSS identifier of a @color-profile rule.

    Python API

    • The output_intent string entry replaces the srgb boolean in default options.

    Features

    Bug fixes

    • #2697, #2691: Avoid endless loops in grids
    • #2709: Be less strict for gradient rasterization in tests
    • #2683: Fix rendering of emojis in SVG
    • #2688: Always describe font using absolute sizes
    • #2676: Fix inheritance for svg/symbol tags referenced by use tags
    • #2681: Add dc:description field to PDF/A metadata
    • #2680: Force first grid row rendering on empty pages
    • #2690: Compute units in gradients used in border background
    • #2689: Cut flex elements with fixed height and overflowing children
    • #2651, #2696: Fix tests on Debian
    • #2698, #2699: Fix alignment of right-to-left elements with auto width and set min/max-width
    • #2556: Apply presentational hints to svg tags
    • #2706: Handle infinite border radii
    • #2707, #2708, #2710: Get mimetypes from Python code instead of various third-party files
    • #2717, #2580, #2740: Fix table break retry after padding overflow
    • #2769: Add year in PDF/UA-2 metadata
    • #2768: Allow SVG lists of numbers to be sp
  3. v68.12026-02-06 · 2026-02-06 15:03 UTC
    查看更新说明

    Bug fixes

    • #2662: Don’t crash when SVG clip paths are not in defs tags
    • #2665: Fix position of box bounding box
    • #2663: Fix transparency with Acrobat and Edge
    • #2666: Don’t rely on random default font to define test page size
    • #2670: Fix pattern detection of URL schemes
    • #2671: Improve API compatibility between URLFetcherResponse and addinfourl
    • #2672: Fix charset for old URL fetcher requests
    • #2675, #2673: Fix calc for many properties

    Contributors

    • Guillaume Ayoub

    Backers and sponsors

    • Spacinov
    • Syslifters
    • Kobalt
    • Simon Sapin
    • Grip Angebotssoftware
    • Manuel Barkhau
    • Simonsoft
    • KontextWork
    • Menutech
    • TrainingSparkle
    • Healthchecks.io
    • Method B
    • FieldHub
    • Hammerbacher
    • Yanal-Yves Fargialla
    • Morntag
    • Piloterr
    • Xavid
    • Charlie S.
    • Prothesis Dental Solutions
    • Kai DeLorenzo
  4. v68.02026-01-19 · 2026-01-19 14:54 UTC
    查看更新说明

    This is a security update (CVE-2025-68616).

    We strongly recommend to upgrade WeasyPrint to the latest version if you use the default_url_fetcher function in your custom URL fetcher, or if you use the allowed_protocols parameter of the default_url_fetcher function.

    Read about this release on our blog.

    Security

    • Always use URL fetcher for HTTP redirects

    Python API

    • default_url_fetcher() is deprecated, use the new URLFetcher class instead, see URL Fetchers for more information about URL fetchers
    • DocumentMetadata.generate_rdf_metadata is now a method that can be overridden instead of a parameter, see Factur-X / ZUGFeRD (Electronic Invoices) for examples to create e-invoices

    Features

    • #2609, #2603, #351: Refactor URL fetcher API
    • #2632: Support legacy 0 value for angles
    • #2627: Add font-face support to SVG
    • #2646, #2255: Add font shorthand support for SVG text elements
    • #2590, #1749: Honor language-specific rules for text-transform
    • #2645, #2613: Improve SVG and SVG emojis rendering
    • #2658, #2583: Add CLI for Factur-X / ZUGFeRD e-invoices

    Bug fixes

    • #2649: Refactor URL fetcher API
    • #2643, #2628: Handle box-sizing: border-box in grid layout
    • #2641, #1875: Process whitespace after checking all pending targets
    • #2488, #2485: Preserve page groups during layout repagination
    • #2642, #2631: Don’t use isolated transparency groups
    • #2637: Fix repeating radial gradients rendering
    • #2622: Fix validation of colors
    • #2626: Share grid items rendering advancement between a box and its copies
    • #2621: Correctly handle fallback values of attr()
    • #2619: Fix SVG fonts
    • #2629: Always define extra skip height that may be used after
    • #2648: Fix numbers validation in font-feature-settings
    • #2648: Fix keyword values for text-decoration-thickness
    • #2661: Respect inline images when defining minimum table width

    Documentation

    • #2638: Update Python command for Windows installation steps

    Contributors

    • Guillaume Ayoub
    • Jurriaan Pruis
    • Mohamed Hamed
    • Alexandra Usatenko
    • Andrea Corna
    • Aoishik Khan
    • Joe

    Backers and sponsors

    • Spacinov
    • Syslifters
    • Kobalt
    • Simon Sapin
    • Grip Angebotssoftware
    • Manuel Barkhau
    • Simonsoft
    • KontextWork
    • Menutech
  5. v67.02025-12-02 · 2025-12-02 16:11 UTC
    查看更新说明

    Read about this release on our blog.

    Dependencies

    • Python 3.10+ is now needed, Python 3.9 is not supported anymore
    • tinycss2 1.5.0+ is now needed
    • fontTools 4.59.2+ is now needed

    Features

    • #2560, #640, #844, #1091, #2517: Support CMYK colors, PDF/X, color profiles and light-dark() function
    • #2558, #1175: Support ::first-line, with financial support from Karte Technology
    • #2552: Support CSS layers, with financial support from Code & Co.
    • #2564, #2599, #2397: Allow page breaks in grid rows, with financial support from Ocean Recap
    • #2568, #357: Support calc() and other mathematical functions
    • #2575, #2574: Support PDF/A-1a, PDF/A-2a and PDF/A-3a
    • #2611, #2573: Support PDF/A-4e and PDF/A-4f
    • #2523: Display tofu for missing glyphs
    • #2581: Add option to disable protocols in URL resolution
    • #2570: Support rch, cap, rcap, rex, ic and ric font-relative units
    • #2547, #2140: Support "only" keyword in media queries

    Bug fixes

    • #2516, #1510: Fix rendering of first line of text with nested right float
    • #2510, #1073, #2507: Avoid Pango crashes and font mismatches with @font-face rules referencing local fonts
    • #2532, #2531: Use fonttools instancer instead of deprecated mutator API
    • #2541: Fix syntax of functions
    • #2543: Allow font-related units to access @font-face fonts
    • #2525: Respect top margins and avoid overlapping footnotes for columns, with financial support from Code & Co.
    • #2536: Remove Subtype key from font descriptor
    • #2539: Fix min width for SVGs with intrinsic ratio but no intrinsic size
    • #2537, #2533: Fix order of operators when drawing SVGs
    • #2538: Don’t crash with nested unknown functions
    • #2542: Don’t crash when lh and rlh are used for line height or font size
    • #2540, #2528: Use locale encoding instead of filesystem encoding for font paths
    • #2563, [\

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    The Awesome Document Factory

    WeasyPrint is a smart solution helping web developers to create PDF documents. It turns simple HTML pages into gorgeous statistical reports, invoices, tickets…

    From a technical point of view, WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing. WeasyPrint is free software made available under a BSD license.

    It is based on various libraries but not on a full rendering engine like WebKit or Gecko. The CSS layout engine is written in Python, designed for pagination, and meant to be easy to hack on.

    WeasyPrint has been created and developed by Kozea (https://kozea.fr/). Professional support, maintenance and community management is provided by CourtBouillon (https://www.courtbouillon.org/).

    Copyrights are retained by their contributors, no copyright assignment is required to contribute to WeasyPrint. Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion is licensed under the BSD 3-clause license, without any additional terms or conditions. For full authorship information, see the version control history.