fpdf2¶
fpdf2
is a library for simple & fast PDF document generation in Python. It is a fork and the successor of PyFPDF
(cf. history).
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
Main features¶
- Easy to use, with a user-friendly API, and easy to extend
- Python 3.8+ support
- Unicode (UTF-8) TrueType font subset embedding (Central European, Cyrillic, Greek, Baltic, Thai, Chinese, Japanese, Korean, Hindi and almost any other language in the world)
- Internal / external links
- Embedding images, including transparency and alpha channel, using Pillow (Python Imaging Library)
- 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 batchs
- 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__
- It has very few dependencies: Pillow, defusedxml, & fonttools
- Can render mathematical equations & charts
- Many example scripts available throughout this documentation, including usage examples with Django, Flask, FastAPI, streamlit, AWS lambdas... : Usage in web APIs
- more than 1300 unit tests with
qpdf
-based PDF diffing, and PDF samples validation using 3 different checkers:
Tutorials¶
- English
- Deutsch
- Italian
- español
- français
- हिंदी
- português
- Русский
- Ελληνικά
- עברית
- 简体中文
- বাংলা
- ភាសាខ្មែរ
- 日本語
- Dutch
- Polski
- Türkçe
- Indonesian
Installation¶
From PyPI:
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
Developement: check the dedicated documentation page.
Displaying deprecation warnings¶
DeprecationWarning
s are not displayed by Python by default.
Hence, every time you use a newer version of fpdf2
, we strongly encourage you to execute your scripts with the -Wd
option (cf. documentation) in order to get warned about deprecated features used in your code.
This can also be enabled programmatically with warnings.simplefilter('default', DeprecationWarning)
.
Community¶
Support¶
For community support, please feel free to file an issue or open a discussion.
They use fpdf2¶
Online classes & open source projects:
- Harvard University uses
fpdf2
in their CS50 introductory class - Undying Dusk : a video game in PDF format, with a gameplay based on exploration and logic puzzles, in the tradition of dungeon crawlers
- OpenDroneMap : a command line toolkit for processing aerial drone imagery
- OpenSfM : a Structure from Motion library, serving as a processing pipeline for reconstructing camera poses and 3D scenes from multiple images
- RPA Framework : libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework : rpa-pdf package
- Concordia : a platform developed by the US Library of Congress for crowdsourcing transcription and tagging of text in digitized images
- wudududu/extract-video-ppt : create a one-page-per-frame PDF from a video or PPT file.
fpdf2
also has a demo script to convert a GIF into a one-page-per-frame PDF: gif2pdf.py - Planet-Matriarchy-RPG-CharGen : a PyQt based desktop application (=
.exe
under Windows) that provides a RPG character sheet generator
Usage statistics¶
- PyPI download stats - Downloads per release on Pepy
- pip trends: fpdf2 VS other PDF rendering libs
- packages using
fpdf2
can be listed using:
Related¶
- Looking for alternative libraries? Check out pypdf, borb, pikepdf, WeasyPrint, pydyf and PyMuPDF: features comparison, examples, Jupyter notebooks. We have some documentations about combining
fpdf2
withborb
&pypdf
. - Create PDFs with Python : a series of tutorial videos by bvalgard
- GitHub gist providing borders around any fpdf2 area, by @hyperstown
- digidigital/Extensions-and-Scripts-for-pyFPDF-fpdf2 : scripts ported from PHP to add transpareny to elements of the page or part of an image, allow to write circular text, draw pie charts and bar diagrams, embed JavaScript, draw rectangles with rounded corners, draw a star shape, restrict the rendering of some elements to screen or printout, paint linear / radial / multi-color gradients gradients, add stamps & watermarks, write sheared text...
Misc¶
- Release notes: CHANGELOG.md
- This library could only exist thanks to the dedication of many volunteers around the world: list & map of contributors
- You can download an offline PDF version of this manual: fpdf2-manual.pdf