PyFPDF (Original fpdf Library)
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.
Warnings
- breaking The `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.
- gotcha Both 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).
- gotcha Native 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.
- gotcha For GIF image support, the Python Imaging Library (PIL), or its modern fork Pillow, is required. Without it, attempts to use GIF images will fail.
Install
-
pip install fpdf
Imports
- FPDF
from fpdf import FPDF
Quickstart
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')