fpdf2
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.
Warnings
- breaking fpdf2 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.
- gotcha fpdf2 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.
- gotcha The 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).
Install
-
pip install fpdf2
Imports
- FPDF
from fpdf import FPDF
Quickstart
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")