Registry / serialization / fpdf
library1.7.2pypypi✓ verified 25d ago

PyFPDF is the original Python library for generating PDF documents, ported from the PHP FPDF project. Its last release (1.7.2) was in January 2015, and it is largely unmaintained. While it provides basic PDF creation functionalities like text, images (JPEG, PNG, GIF), and simple layouts, it is generally considered a legacy library. For active development and modern Python compatibility, its successor, fpdf2, is recommended.

pip install fpdf
INSTALL
IMPORT
SIG · FPDF
F
fpdf
serializationpythonv1.7.2
Install
2.5s avg
Import
145ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.7.2 · 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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.148s · 19.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.142s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

FPDF
from fpdf import FPDF
from fpdf2 import FPDF
This is the correct import for the 'fpdf' (1.7.2) package. However, the actively maintained successor 'fpdf2' also uses 'from fpdf import FPDF', which can lead to confusion if both are not managed carefully within the same environment or project.

This basic example creates a PDF document named 'hello_world.pdf' with a single page, sets the font to Arial bold 16, and prints 'Hello World!' at the default position.

from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font('Arial', 'B', 16) pdf.cell(40, 10, 'Hello World!') pdf.output('hello_world.pdf')
Debug
Known issues
breakingThe `fpdf` library (version 1.7.2) is largely unmaintained, with its last release in January 2015. It primarily targets Python 2.x and has only experimental support for Python versions up to 3.4. It is not officially supported on modern Python 3.x environments.
fix
Migrate to `fpdf2` (`pip install fpdf2`), which is the actively maintained successor designed for modern Python. Be aware of API differences during migration.
affects: All versions of fpdf (including 1.7.2) on Python 3.5+.
gotchaBoth the original `fpdf` (version 1.7.2) and its actively maintained successor `fpdf2` use the same import statement: `from fpdf import FPDF`. This can lead to `ModuleNotFoundError` or unexpected behavior if `fpdf2` is installed but the code expects `fpdf`'s API (or vice-versa).
fix
Ensure only one of the libraries is installed or manage virtual environments carefully. If using `fpdf2`, verify the import is correctly resolving to the `fpdf2` package.
affects: All versions of fpdf (1.7.2) and fpdf2.
gotchaNative Unicode (UTF-8) support in `fpdf` 1.7.2 is limited and often problematic, especially for non-Latin-1 characters. This can result in garbled text or errors when handling international character sets.
fix
For applications requiring robust Unicode support, it is strongly recommended to use `fpdf2`, which has comprehensive UTF-8 TrueType font subset embedding.
affects: All versions of fpdf (including 1.7.2).
gotchaFor GIF image support, the Python Imaging Library (PIL), or its modern fork Pillow, is required. Without it, attempts to use GIF images will fail.
fix
Install Pillow: `pip install Pillow`. PNG and JPG formats generally do not require external dependencies.
affects: All versions of fpdf (including 1.7.2).
Errors
Common errors & fixes
TypeError: must be bytes, not str
The fpdf library (v1.7.2) was designed for Python 2, and its methods often expect byte strings, while Python 3 strings are Unicode by default, leading to a type mismatch.
fix
Encode the string to bytes, typically using `.encode('latin-1')` or `.encode('utf-8')` before passing it to `fpdf` methods.
FPDF error: Undefined font: dejavu
You attempted to use a custom font with `set_font()` (e.g., 'dejavu') that has not been previously registered using `add_font()`, or the font file specified in `add_font()` could not be found or read.
fix
Ensure you call `pdf.add_font()` with the correct font family name and a valid path to the font's `.ttf` file *before* using `set_font()` for that font.
TypeError: cell() missing 3 required positional arguments: 'w', 'h', and 'txt'
The `cell()` method was called without providing its mandatory `w` (width), `h` (height), and `txt` (text) arguments.
fix
Always provide at least the width, height, and text content as the first three arguments to the `cell()` method.
ModuleNotFoundError: No module named 'fpdf'
The `fpdf` library has not been installed in your current Python environment, or the Python interpreter cannot locate it.
fix
Install the library using pip.
Upgrade
Version history
1.7.2latest on PyPI · released Jan 21, 2015
Audit
Dependencies
PillowoptionalRequired for GIF image support.
Agent activity
7 hits · last 30 days
node
6
Resources