This is a fork of fpdf2 which contains some changes needed for integration
in reportbro-lib, a reporting framework to generate pdf and xlsx
reports based on report templates. The report template is created visually with a Javascript plugin.
Changes include a setting for encode_error_handling
, image alignment options and an optimized method
to split text into lines.


fpdf2

fpdf2
is a PDF creation library for Python:
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font('helvetica', size=12)
pdf.cell(text="hello world")
pdf.output("hello_world.pdf")
Go try it now online in a Jupyter notebook:
or 
Compared with other PDF libraries, fpdf2
is fast, versatile, easy to learn and to extend (example).
It is also entirely written in Python and has very few dependencies:
Pillow, defusedxml, & fontTools. It is a fork and the successor of PyFPDF
(cf. history).
Development status: this project is mature and actively maintained.
We are looking for contributing developers: if you want to get involved but don't know how,
or would like to volunteer helping maintain this lib, open a discussion!
Installation Instructions
pip install fpdf2
To get the latest, unreleased, development version straight from the development branch of this repository:
pip install git+https://github.com/py-pdf/fpdf2.git@master
Features
- Python 3.7+ support
- Unicode (UTF-8) TrueType font subset embedding
- Internal / external links
- Embedding images, including transparency and alpha channel
- Arbitrary path drawing and basic SVG import
- Embedding barcodes, charts & graphs, emojis, symbols & dingbats
- Tables and also cell / multi-cell / plaintext writing, with automatic page breaks, line break and text justification
- Choice of measurement unit, page format & margins. Optional page header and footer
- Basic conversion from HTML to PDF
- A templating system to render PDFs in batches
- Images & links alternative descriptions, for accessibility
- Table of contents & document outline
- Document encryption & document signing
- Annotations, including text highlights, and file attachments
- Presentation mode with control over page display duration & transitions
- Optional basic Markdown-like styling:
**bold**, __italics__
- Can render mathematical equations & charts
- Usage examples with Django, Flask, FastAPI, streamlit, AWS lambdas... : Usage in web APIs
- 1000+ unit tests running under Linux & Windows, with
qpdf
-based PDF diffing, timing & memory usage checks, and a high code coverage
Our 350+ reference PDF test files, generated by fpdf2
, are validated using 3 different checkers:

Please show the value
Choosing a project dependency can be difficult. We need to ensure stability and maintainability of our projects.
Surveys show that GitHub stars count play an important factor when assessing library quality.
⭐ Please give this repository a star. It takes seconds and will help your fellow developers! ⭐
This library relies on community interactions. Please consider sharing a post about fpdf2
and the value it provides 😊

Documentation
You can also have a look at the tests/
, they're great usage examples!
Developement
Please check the dedicated documentation page.
Contributors ✨
This library could only exist thanks to the dedication of many volunteers around the world:
This project follows the all-contributors specification
(emoji key).
Contributions of any kind welcome!

(screenshot from January 2023, click on the map above to access an up-to-date online version)
More about those in the documentation.