fpdf2

A pure-Python library for generating and manipulating PDF documents, with text, images, tables, barcodes, SVG, and digital signing built in.

Library
PyPI
v2.8.8
1,537stars
LGPL-3.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
90/100Excellent
Development Activity96
Maintenance84
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
87/100Excellent
Architecture88
Code Quality92
Innovation78
Learning Curve90

fpdf2 is a PDF generation library for Python, forked from the original PyFPDF and now its actively maintained successor. It lets you build documents programmatically — pages, fonts, text blocks, images, tables, vector drawings — using a straightforward object-oriented API, without needing a browser, a rendering engine, or any binary dependency beyond Pillow, fontTools, and defusedxml.

Beyond basic page layout, fpdf2 covers a wide surface of real-world PDF needs: Unicode TrueType font subset embedding, internal and external links, alpha-channel image embedding, arbitrary path drawing with basic SVG import, barcodes, math/chart embedding, tables with automatic page breaks, HTML-to-PDF conversion, a batch templating system, accessibility metadata, tables of contents, document encryption, and digital signing. The project ships more than 1,300 unit tests and validates every generated PDF against multiple external checkers (qpdf, VeraPDF, Datalogics PDF Checker) in CI, which is unusual rigor for a document-generation library.

What You Get

  • A simple, chainable FPDF object model for adding pages, setting fonts, and placing content
  • Unicode TrueType font subset embedding for full international text support
  • Arbitrary vector path drawing plus a basic SVG-to-PDF importer
  • A table API with automatic page breaks, cell styling, and multi-cell text layout
  • Barcode generation (Code128, Code39, QR-adjacent formats) and chart/equation embedding
  • Basic HTML-to-PDF conversion for quick templated documents
  • Document encryption, digital signing, and accessibility metadata (alt text, tagging)
  • A batch templating system for generating many similar documents (invoices, certificates) from one layout

Common Use Cases

  • Generating invoices, receipts, and certificates in a Django, Flask, or FastAPI backend
  • Producing reports with embedded charts and tables from pandas/matplotlib data
  • Converting simple HTML or Markdown content into downloadable PDF documents
  • Building PDF forms and templated documents at scale via the templating system
  • Embedding barcodes and QR-adjacent codes into shipping labels or tickets
  • Digitally signing and encrypting generated PDFs for compliance workflows

Under The Hood

Architecture fpdf2 centers on the FPDF class in fpdf/fpdf.py, which composes behavior through mixins (GraphicsStateMixin from graphics_state.py, TextRegionMixin from text_region.py) rather than one monolithic class, letting graphics-state stacking (colors, transforms, clipping) and multi-column text layout evolve independently of page/document management. Output generation is a separate concern: output.py defines a full hierarchy of PDF object types (PDFPage, PDFCatalog, PDFResources, PDFXObject, PDFFontStream, PDFXrefAndTrailer, and more) that assemble the final byte-for-byte PDF structure, while syntax.py and linearization.py handle low-level PDF syntax and optional linearized (“fast web view”) output. Higher-level features — svg.py for SVG import, html.py for HTML-to-PDF, table.py for table layout, template.py for batch document templating, encryption.py and sign.py for security — are each isolated modules that call into the core FPDF API rather than reaching into its internals, so removing or replacing any one feature module has limited blast radius on the rest of the document pipeline.

Tech Stack The library is pure Python (3.10+) with a deliberately small dependency footprint: Pillow for image decoding, fontTools for font subsetting/embedding, and defusedxml for safe SVG/XML parsing. Optional extras pull in endesive and cryptography for digital signing, uharfbuzz for advanced text shaping, and brotli/qrcode/pypdf for testing and comparison. Packaging uses a standard setuptools + pyproject.toml build with a dynamic version pulled from fpdf.FPDF_VERSION, and documentation is built with MkDocs Material plus a custom mkdocs-with-pdf-based pipeline that renders the docs site itself into a PDF.

Code Quality The test suite spans 146 files with well over a thousand tests, most of which render an actual PDF and diff it against a checked-in reference file using qpdf-based structural comparison (falling back to hashing when qpdf is unavailable) — a much stronger guarantee than typical snapshot testing. CI runs mypy --strict and pyright --strict type checking, pylint, black formatting, and security scanners (bandit, semgrep, zizmor, guarddog), and separately validates every reference PDF used in tests against qpdf, VeraPDF, and the Datalogics PDF Checker. Custom exceptions (FPDFException and subclasses like FPDFPageFormatException, FPDFSvgLimitExceeded) give callers typed, catchable failure modes instead of bare exceptions.

What Makes It Unique Most Python PDF-generation options either wrap a browser/headless-Chrome rendering pipeline (heavy, slow, hard to sandbox) or offer only low-level page-drawing primitives. fpdf2 instead provides a single, dependency-light, pure-Python API that spans the practical range from basic page/text layout up through SVG import, HTML conversion, tables, forms, encryption, and digital signing — while validating its own output against multiple independent PDF conformance checkers in CI, which is a level of output-correctness rigor rarely seen in document-generation libraries at any language.

Used by 5 apps in this directory

TypeScript
60%
Other

agenta

Developer Tools · Devops · AI Development

4,640

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript60%
Python37%
Updated today
Python
67%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,997

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python67%
TypeScript31%
Updated today
Python
37%
Other

Open WebUI

AI Assistants · AI Agents

150,393

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
67
Dependency
Built with
Python37%
Svelte34%
JavaScript21%
Updated yesterday
Python
74%
AGPL 3.0

OpenViking

Databases · AI Development

34,389

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
84
Repo Health
75
Technical
65
Dependency
Built with
Python74%
Rust14%
Updated today
Python
66%
Apache 2.0

Polar

Ecommerce · Developer Tools · Invoicing Finance

10,216

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
70
Dependency
Built with
Python66%
TypeScript27%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search