Registry / serialization / fpdf2
library2.8.8pypypi✓ verified 31d ago

fpdf2 is a simple and fast Python library for generating PDF documents, actively maintained as a modern fork of the original FPDF. It supports a wide range of features including text, images, shapes, tables, and SVG rendering. The current version is 2.8.7, and it has a rapid release cadence with frequent updates adding new features and bug fixes.

pip install fpdf2
INSTALL
IMPORT
SIG · FPDF2
F
fpdf2
serializationpythonv2.8.8
Install
3.4s avg
Import
1151ms
Disk
63MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.8.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.222s · 61.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.4s · import 1.080s · 66MB
63MB installed
● package 63MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FPDF
✓ from fpdf import FPDF
✗ from fpdf2 import FPDF
While the package name is `fpdf2`, the main class `FPDF` is imported from the `fpdf` module to maintain compatibility with the original FPDF library API.

This quickstart code generates a simple PDF document named 'hello_world.pdf' containing the text 'Hello, World!' using the FPDF class.

from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=12) pdf.cell(txt="Hello, World!") pdf.output("hello_world.pdf")
Debug
Known issues
breakingfpdf2 dropped support for Python 3.8. Users on Python 3.8 or older must upgrade their Python version to 3.9+ or pin fpdf2 to a version prior to 2.8.4.
fix
Upgrade Python to 3.9 or newer. Alternatively, if Python 3.8 must be used, restrict fpdf2 to `<2.8.4` (e.g., `pip install 'fpdf2<2.8.4'`).
affects: >=2.8.4
gotchafpdf2 is a modern, maintained fork of the original `fpdf` library (which had its last release in 2013). New users might accidentally follow outdated tutorials or install the original `fpdf` package, leading to missing features or compatibility issues.
fix
Always install with `pip install fpdf2` and ensure your code uses `from fpdf import FPDF`. Refer to the official `fpdf2` documentation for current API details.
affects: All versions
gotchaThe default unit for measurements in FPDF (e.g., `FPDF` constructor, `cell`, `line`) is millimeters (mm). This can be a source of confusion for users accustomed to points (pt) or inches (in).
fix
Specify the desired unit in the `FPDF` constructor (e.g., `pdf = FPDF(unit='pt')` or `pdf = FPDF(unit='in')`). All subsequent measurements will use the chosen unit. You can also convert units manually if needed.
affects: All versions
gotchaThe `txt` parameter in methods like `cell()` has been renamed to `text` in fpdf2 version 2.7.6. Using `txt` will issue a `DeprecationWarning`.
fix
Update your code to use `text` instead of `txt` for parameters in affected methods (e.g., `pdf.cell(text="Hello, World!")`).
affects: >=2.7.6
gotchaThe parameter `txt` in `FPDF.cell()` has been renamed to `text`. Using `txt` will issue a `DeprecationWarning` and will eventually be removed.
fix
Update calls to `pdf.cell()` (and potentially other methods) to use `text=` instead of `txt=` (e.g., `pdf.cell(text="Hello, World!")`). This change was introduced in `fpdf2` version 2.7.6.
affects: >=2.7.6
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fpdf'
This error occurs because `fpdf2` uses the `fpdf` namespace for its main class (`FPDF`), so users expect to import from `fpdf`. However, if the older, unmaintained `fpdf` library is installed instead of `fpdf2`, or both are installed, Python might resolve to the wrong package.
fix
Ensure only `fpdf2` is installed and the correct package is being used. First, uninstall any conflicting `fpdf` package: `pip uninstall fpdf`. Then, if `fpdf2` is not already installed, install it: `pip install fpdf2`. The import statement `from fpdf import FPDF` is correct for `fpdf2`.
AttributeError: 'FPDF' object has no attribute 'table'
This error typically arises when attempting to use the `with pdf.table():` syntax, which is a feature of `fpdf2`, but an older version of `fpdf2` (pre-table feature) or the original `fpdf` library (which lacks table support) is being used. This often happens due to version conflicts or outdated installations.
fix
Upgrade `fpdf2` to the latest version, as table support was added in a newer release. Run `pip install --upgrade fpdf2`. If the original `fpdf` package is also installed, uninstall it first using `pip uninstall fpdf` to prevent conflicts.
FPDFUnicodeEncodingException: Character "€" at index X in text is outside the range of characters supported by the font used: "helvetica". Please consider using a Unicode font.
This error occurs when attempting to render text containing Unicode characters (like '€', 'é', 'ñ', etc.) with a font that only supports a limited character set (e.g., Latin-1 encoded fonts like 'helvetica', 'courier', 'times'). These built-in fonts do not have glyphs for many Unicode characters.
fix
Add and use a Unicode (TrueType) font that supports the required characters. First, download a suitable `.ttf` font (e.g., from Google Fonts). Then, add it to `fpdf2` and set it as the current font: `pdf.add_font('DejaVuSans', fname='DejaVuSans.ttf')` followed by `pdf.set_font('DejaVuSans')`.
TypeError: 'numpy.int64' object has no attribute 'encode'
This error happens when a non-string data type, such as a NumPy integer (`numpy.int64`), is passed directly to an `fpdf2` text method (like `pdf.cell()` or `pdf.multi_cell()`) that expects a string. These methods attempt to call `.encode()` on the input, which fails for numerical types.
fix
Explicitly convert the numerical data to a string before passing it to `fpdf2` text methods: `str(numpy_int_variable)`. For example, `pdf.cell(0, 10, str(value))` instead of `pdf.cell(0, 10, value)`.
Upgrade
Version history
2.8.8latest on PyPI · released Aug 9, 2026
Audit
Dependencies
numpyoptionalOptional dependency to improve performance for some internal calculations (e.g., `pack_codes_into_bytes()`).
Agent activity
24 hits · last 30 days
node
22
Resources
fpdf2 — pip install fpdf2 · libregistry