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 fpdfVerified import paths — ran on the pinned version, not inferred.
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.
Migrate to `fpdf2` (`pip install fpdf2`), which is the actively maintained successor designed for modern Python. Be aware of API differences during migration.
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.
For applications requiring robust Unicode support, it is strongly recommended to use `fpdf2`, which has comprehensive UTF-8 TrueType font subset embedding.
Install Pillow: `pip install Pillow`. PNG and JPG formats generally do not require external dependencies.
Encode the string to bytes, typically using `.encode('latin-1')` or `.encode('utf-8')` before passing it to `fpdf` methods.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.
Always provide at least the width, height, and text content as the first three arguments to the `cell()` method.
Install the library using pip.