fpdf2 is a Python library for generating PDF documents and the successor to PyFPDF. It exposes operations for pages, text, tables, graphics and other PDF features, with automatic page breaks and a basic HTML input path. Its role is programmatic generation; workflows that incorporate an existing PDF may combine it with a separate manipulation library.[1][5]
Page and content generation
The library provides text cells, multi-line text, tables and automatic page breaks alongside image and path-drawing operations. Page dimensions, units, margins and optional headers or footers can be controlled in code. It also exposes document features such as links and outlines. These facilities allow an application to turn its own data into a document; they do not define the business logic or provide a graphical authoring interface.[1]
HTML input is a subset
The write_html interface handles selected HTML constructs through Python's HTML parser. The manual explicitly states that full HTML5 and CSS are not implemented, while documenting narrower styling controls and selected page-break properties. It also lists limitations for nested tags in table cells. A template written for a browser or a full HTML-to-PDF renderer should therefore be checked against this supported subset rather than assumed to transfer unchanged.[3]
Unicode and shaping
Unicode font handling and shaping are related but separate requirements. The shaping documentation makes uharfbuzz optional and leaves shaping disabled by default; enabling it supports the library's bidirectional-text handling. Type 1 fonts are excluded from this shaping path. For Arabic, Indic scripts or mixed-direction text, the font and shaping configuration are part of the workflow rather than a consequence of merely passing a Unicode string.[4]
Working with existing documents
The project's integration examples combine generated fpdf2 content with pypdf. One pattern produces a new overlay and merges it onto an existing page; another inserts a generated page into an existing document. These examples show complementary responsibilities: fpdf2 creates the new material, and pypdf reads and manipulates the existing PDF. They do not establish that fpdf2 itself imports arbitrary PDFs as an editable native document.[5]
Licensing and substitution
The package metadata specifies LGPL-3.0-only and Python 3.10 or later, with Pillow, fontTools and defusedxml dependencies. fpdf2 can substitute for ReportLab Toolkit for suitable Python-generated documents, but their layout APIs differ. Choose around the required tables, typography and page behavior, and preserve output checks when translating code. The PyFPDF lineage does not make this a drop-in implementation of another toolkit's document templates.[1][2][6]
Capabilities & limitations
Programmatic PDF generation
supported
Provides text, tables, images, drawing and automatic page breaks.[1]
Generating PDF documents from Python · Python 3.10+; OS-independent base · Version, build and integration requirements apply