{"id":6284,"library":"types-fpdf2","title":"Typing Stubs for fpdf2","description":"This is a type stub package for the fpdf2 package, providing external type annotations for static analysis and type checking. It is part of the `typeshed` project and receives regular, often daily, automated releases to track changes in the upstream `fpdf2` library. This version of `types-fpdf2` aims to provide accurate annotations for `fpdf2==2.8.4`. Note that since `fpdf2` version 2.8.6, the `fpdf2` package itself includes type annotations, rendering `types-fpdf2` unnecessary for newer `fpdf2` versions.","status":"active","version":"2.8.4.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","fpdf2","pdf","typeshed"],"install":[{"cmd":"pip install types-fpdf2","lang":"bash","label":"Install types-fpdf2"}],"dependencies":[{"reason":"Provides type hints for this runtime library. While not a hard runtime dependency, it is a logical dependency for the stubs to be useful.","package":"fpdf2","optional":true}],"imports":[{"note":"This library provides type hints for the `fpdf2` package. You import `FPDF` from `fpdf` in your application code, and type checkers will use `types-fpdf2` if installed.","symbol":"FPDF","correct":"from fpdf import FPDF"}],"quickstart":{"code":"from fpdf import FPDF\n\ndef create_pdf_document(filename: str = \"hello_world.pdf\") -> None:\n    pdf: FPDF = FPDF()\n    pdf.add_page()\n    pdf.set_font(\"Helvetica\", size=12)\n    pdf.cell(200, 10, txt=\"Hello, world!\", align=\"C\")\n    pdf.output(filename)\n    print(f\"PDF saved to {filename}\")\n\nif __name__ == \"__main__\":\n    create_pdf_document()","lang":"python","description":"This quickstart demonstrates a minimal `fpdf2` usage. When `types-fpdf2` is installed in the same environment, type checkers like MyPy or Pyright will use its stubs to provide static analysis for your `fpdf2` code, ensuring type correctness and improving developer experience."},"warnings":[{"fix":"Uninstall `types-fpdf2` if using `fpdf2` version 2.8.6 or newer (`pip uninstall types-fpdf2`).","message":"If you are using `fpdf2` version 2.8.6 or newer, `types-fpdf2` is not needed as `fpdf2` itself provides type annotations. Installing both may lead to redundant or conflicting type information, potentially causing unexpected type checking errors.","severity":"gotcha","affected_versions":"fpdf2 >= 2.8.6"},{"fix":"Explicitly add and set a TrueType font that supports the required Unicode range (e.g., `pdf.add_font(fname='path/to/my_unicode_font.ttf', uni=True)`).","message":"`types-fpdf2` provides type hints for `fpdf2`'s font methods, but cannot guarantee that the fonts themselves support specific Unicode characters at runtime. If you're working with non-Latin characters, ensure you explicitly load a Unicode font with `pdf.add_font()` and set it with `pdf.set_font()` to avoid runtime `UnicodeEncodeError` exceptions.","severity":"gotcha","affected_versions":"All"},{"fix":"For complex RTL layouts, manual text arrangement or external pre-processing might be necessary. Consider checking `fpdf2`'s documentation or community forums for workarounds.","message":"While `types-fpdf2` provides type hints for text rendering functions, `fpdf2` itself has known limitations with right-to-left (RTL) languages, particularly concerning automatic line breaking (`multi_cell`). Text direction and justification may not be handled correctly for all scripts.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}