{"id":1483,"library":"fpdf2","title":"fpdf2","description":"fpdf2 is a simple and fast Python library for generating PDF documents, actively maintained as a modern fork of the original FPDF. It supports a wide range of features including text, images, shapes, tables, and SVG rendering. The current version is 2.8.7, and it has a rapid release cadence with frequent updates adding new features and bug fixes.","status":"active","version":"2.8.7","language":"python","source_language":"en","source_url":"https://github.com/py-pdf/fpdf2","tags":["pdf","document generation","report generation","pdf/a"],"install":[{"cmd":"pip install fpdf2","lang":"bash","label":"Install fpdf2"}],"dependencies":[{"reason":"Optional dependency to improve performance for some internal calculations (e.g., `pack_codes_into_bytes()`).","package":"numpy","optional":true}],"imports":[{"note":"While the package name is `fpdf2`, the main class `FPDF` is imported from the `fpdf` module to maintain compatibility with the original FPDF library API.","wrong":"from fpdf2 import FPDF","symbol":"FPDF","correct":"from fpdf import FPDF"}],"quickstart":{"code":"from fpdf import FPDF\n\npdf = FPDF()\npdf.add_page()\npdf.set_font(\"helvetica\", size=12)\npdf.cell(txt=\"Hello, World!\")\npdf.output(\"hello_world.pdf\")\n","lang":"python","description":"This quickstart code generates a simple PDF document named 'hello_world.pdf' containing the text 'Hello, World!' using the FPDF class."},"warnings":[{"fix":"Upgrade Python to 3.9 or newer. Alternatively, if Python 3.8 must be used, restrict fpdf2 to `<2.8.4` (e.g., `pip install 'fpdf2<2.8.4'`).","message":"fpdf2 dropped support for Python 3.8. Users on Python 3.8 or older must upgrade their Python version to 3.9+ or pin fpdf2 to a version prior to 2.8.4.","severity":"breaking","affected_versions":">=2.8.4"},{"fix":"Always install with `pip install fpdf2` and ensure your code uses `from fpdf import FPDF`. Refer to the official `fpdf2` documentation for current API details.","message":"fpdf2 is a modern, maintained fork of the original `fpdf` library (which had its last release in 2013). New users might accidentally follow outdated tutorials or install the original `fpdf` package, leading to missing features or compatibility issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Specify the desired unit in the `FPDF` constructor (e.g., `pdf = FPDF(unit='pt')` or `pdf = FPDF(unit='in')`). All subsequent measurements will use the chosen unit. You can also convert units manually if needed.","message":"The default unit for measurements in FPDF (e.g., `FPDF` constructor, `cell`, `line`) is millimeters (mm). This can be a source of confusion for users accustomed to points (pt) or inches (in).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update your code to use `text` instead of `txt` for parameters in affected methods (e.g., `pdf.cell(text=\"Hello, World!\")`).","message":"The `txt` parameter in methods like `cell()` has been renamed to `text` in fpdf2 version 2.7.6. Using `txt` will issue a `DeprecationWarning`.","severity":"gotcha","affected_versions":">=2.7.6"},{"fix":"Update calls to `pdf.cell()` (and potentially other methods) to use `text=` instead of `txt=` (e.g., `pdf.cell(text=\"Hello, World!\")`). This change was introduced in `fpdf2` version 2.7.6.","message":"The parameter `txt` in `FPDF.cell()` has been renamed to `text`. Using `txt` will issue a `DeprecationWarning` and will eventually be removed.","severity":"gotcha","affected_versions":">=2.7.6"}],"env_vars":null,"search_vec":"'2.8.7':43 'activ':14 'ad':54 'bug':58 'cadenc':50 'current':40 'document':13,61 'fast':7 'featur':30,56 'fix':59 'fork':19 'fpdf':23 'fpdf2':1,2 'frequent':52 'generat':11,62,64 'imag':33 'includ':31 'librari':9 'maintain':15 'modern':18 'new':55 'origin':22 'pdf':12,60 'pdf/a':65 'python':8 'rang':28 'rapid':48 'releas':49 'render':38 'report':63 'shape':34 'simpl':5 'support':25 'svg':37 'tabl':35 'text':32 'updat':53 'version':41 'wide':27","created_at":"2026-04-09T03:49:52.785888+00:00","updated_at":"2026-04-16T15:11:02.706493+00:00","problems":[{"fix":"Ensure only `fpdf2` is installed and the correct package is being used. First, uninstall any conflicting `fpdf` package: `pip uninstall fpdf`. Then, if `fpdf2` is not already installed, install it: `pip install fpdf2`. The import statement `from fpdf import FPDF` is correct for `fpdf2`.","cause":"This error occurs because `fpdf2` uses the `fpdf` namespace for its main class (`FPDF`), so users expect to import from `fpdf`. However, if the older, unmaintained `fpdf` library is installed instead of `fpdf2`, or both are installed, Python might resolve to the wrong package.","error":"ModuleNotFoundError: No module named 'fpdf'"},{"fix":"Upgrade `fpdf2` to the latest version, as table support was added in a newer release. Run `pip install --upgrade fpdf2`. If the original `fpdf` package is also installed, uninstall it first using `pip uninstall fpdf` to prevent conflicts.","cause":"This error typically arises when attempting to use the `with pdf.table():` syntax, which is a feature of `fpdf2`, but an older version of `fpdf2` (pre-table feature) or the original `fpdf` library (which lacks table support) is being used. This often happens due to version conflicts or outdated installations.","error":"AttributeError: 'FPDF' object has no attribute 'table'"},{"fix":"Add and use a Unicode (TrueType) font that supports the required characters. First, download a suitable `.ttf` font (e.g., from Google Fonts). Then, add it to `fpdf2` and set it as the current font: `pdf.add_font('DejaVuSans', fname='DejaVuSans.ttf')` followed by `pdf.set_font('DejaVuSans')`.","cause":"This error occurs when attempting to render text containing Unicode characters (like '€', 'é', 'ñ', etc.) with a font that only supports a limited character set (e.g., Latin-1 encoded fonts like 'helvetica', 'courier', 'times'). These built-in fonts do not have glyphs for many Unicode characters.","error":"FPDFUnicodeEncodingException: Character \"€\" at index X in text is outside the range of characters supported by the font used: \"helvetica\". Please consider using a Unicode font."},{"fix":"Explicitly convert the numerical data to a string before passing it to `fpdf2` text methods: `str(numpy_int_variable)`. For example, `pdf.cell(0, 10, str(value))` instead of `pdf.cell(0, 10, value)`.","cause":"This error happens when a non-string data type, such as a NumPy integer (`numpy.int64`), is passed directly to an `fpdf2` text method (like `pdf.cell()` or `pdf.multi_cell()`) that expects a string. These methods attempt to call `.encode()` on the input, which fails for numerical types.","error":"TypeError: 'numpy.int64' object has no attribute 'encode'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.8.8","cli_name":"","cli_version":null,"type":"library","homepage":"https://py-pdf.github.io/fpdf2/","github":"https://github.com/py-pdf/fpdf2","docs":"https://py-pdf.github.io/fpdf2/","changelog":null,"pypi":"https://pypi.org/project/fpdf2/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}