Free Python fpdf2 Templates (Pure Python, 2.7 KB Output)
100% pure-Python top-left coordinate writer with zero C or OS binaries — zips cleanly into AWS Lambda and runs on Pyodide. Produced the smallest Python PDF in our 22-page stress test (135.0 KB in 389 ms; 2.0 KB in 3.5 ms single-page; LGPL-3.0).
Install: pip install fpdf2==2.8.3 | Runtime: Python (Python 3) | Version: 2.8.3 | Popularity: 1.25M/mo installs
Works with: AWS Lambda, FastAPI, Flask, Serverless Python, Pyodide
How fpdf2 (Python) Templates Work in CodePDF
Maps CodePDF's top-left point coordinates directly onto fpdf2's FPDF(unit='pt') API (set_xy, multi_cell, rect, line, image) with runtime dynamic flow-block offsets.
- 100% pure Python — deploys effortlessly on AWS Lambda, Cloud Functions, and Pyodide
- Top-left coordinate system matches CodePDF's visual canvas 1:1
- Ultra-small 2.7 KB generated PDF files for email attachments and high-volume archiving
Quick Start: Generate PDFs with fpdf2
Install fpdf2 (Python) (Python 3), then run the code CodePDF exports for any template:
pip install fpdf2==2.8.3
- Save the generated file as my_document.py.
- Run python my_document.py to produce the PDF.
- Units are millimetres by default; the generated code sets points explicitly.
- Add Unicode fonts with pdf.add_font(family, style, ttf_path).
Example fpdf2 Output (Professional Invoice)
Compiled directly from the Professional Invoice template (Python 3):
from fpdf import FPDF # fpdf2 (LGPL-3.0-only)
# This code is generated using codepdf.dev
def _clean_text(val) -> str:
if val is None:
return ""
text = str(val).replace("\u00a0", " ")
return text.encode("cp1252", "replace").decode("cp1252")
class PDF(FPDF):
def cell(self, *args, **kwargs):
if len(args) > 2 and isinstance(args[2], str):
args = (args[0], args[1], _clean_text(args[2]), *args[3:])
elif "text" in kwargs and isinstance(kwargs["text"], str):
kwargs["text"] = _clean_text(kwargs["text"])
elif "txt" in kwargs and isinstance(kwargs["txt"], str):
kwargs["txt"] = _clean_text(kwargs["txt"])
return super().cell(*args, **kwargs)
def multi_cell(self, *args, **kwargs):
if len(args) > 2 and isinstance(args[2], str):
args = (args[0], args[1], _clean_text(args[2]), *args[3:])
elif "text" in kwargs and isinstance(kwargs["text"], str):
kwargs["text"] = _clean_text(kwargs["text"])
elif "txt" in kwargs and isinstance(kwargs["txt"], str):
kwargs["txt"] = _clean_text(kwargs["txt"])
return super().multi_cell(*args, **kwargs)
def text(self, *args, **kwargs):
// … (517 more lines in full generated file)
Custom Fonts in fpdf2
Call pdf.add_font() with any Unicode .ttf/.otf file before invoking pdf.set_font().
- Keep .ttf/.otf font binaries in ./fonts/ on disk.
- Call pdf.add_font('{{FONT_FAMILY}}', '', '{{FONT_LOCAL_PATH}}') and style='B' for bold.
- Select the registered family via pdf.set_font('{{FONT_FAMILY}}', size=12).
Official documentation: fpdf2 docs
fpdf2 Benchmark Results
Measured on CodePDF’s 26-component, 22-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).
| Metric | fpdf2 | Rank (of 22) |
|---|---|---|
| Wall-clock time | 389 ms | 14th fastest |
| CPU time | 0.71 s | 12th lowest |
| Peak RAM | 81.8 MB | 9th lowest |
| PDF file size | 135 KB | 4th smallest |
- Engine type
- Coordinate Canvas
- Under the hood
- 100% pure-Python top-left coordinate PDF writer (zero C/OS binaries)
- Runs in
- Python 3 (AWS Lambda, FastAPI, Flask, Pyodide)
- Verdict
- Smallest-PDF Python engine (135.0 KB across 22p; 2.0 KB / 3.5 ms single-page) in 389 ms with 100% pure Python (zero C libs; LGPL-3.0).
Under the Hood & Benchmark Highlights
- 100% pure Python with zero native C extensions — zips effortlessly into AWS Lambda or even runs inside WebAssembly via Pyodide.
- Beat ReportLab on both wall-clock time (623 ms vs. 1,411 ms) and file size (100.6 KB vs. 135.7 KB) in our 11-page 26-component stress test, and emits 2.7 KB single-page PDFs.
- Top-left coordinate system maps 1:1 to CodePDF’s visual canvas.
Good to Know (fpdf2 Caveats)
- Coordinate-based engine: Uses explicit set_xy/multi_cell point positioning rather than HTML/CSS reflow; CodePDF emits cursor-offset loops for repeating tables.
- Unicode requires a TTF font: Built-in core fonts (Helvetica, Times, Courier) only support Latin-1 — call pdf.add_font() with a Unicode .ttf/.otf file for international text or symbols.
- Weak copyleft license (LGPL-3.0): Fine for server-side/SaaS apps, but review LGPL obligations before distributing inside closed-source desktop binaries.
Popular fpdf2 PDF Templates
- Professional Invoice fpdf2 template — Line-item invoice with billing details, totals and payment terms.
- Payment Receipt fpdf2 template — Clean transaction receipt with payment method details, item breakdown and verified badge.
- Standard Medical Prescription (Rx Pad) fpdf2 template — Authentic e-prescribing Rx pad with DEA/NPI letterhead, Code-128 barcode, allergy pills, repeating SIG cards, and DAW controls.
- Standard Straight Bill of Lading (BOL) fpdf2 template — Uniform Domestic Straight Bill of Lading with SCAC/PRO Code-128 barcode, DOT HazMat controls, NMFC class table, and CDL sign-off.
- Standard Monthly Payslip fpdf2 template — Itemized monthly payroll slip reconciling gross earnings, statutory tax withholdings, and direct-deposit net pay.
- Business Letter fpdf2 template — Formal letterhead with sender block, subject line and signature area.
All 100 CodePDF templates export to fpdf2 (Python). Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.
fpdf2 Template FAQs
Why use fpdf2 instead of old PyFPDF?
fpdf2 is the actively maintained modern successor to PyFPDF with Python 3.10+ support, Unicode TTF fonts, SVG/barcode support, and fast pure-Python output.
Does fpdf2 work in serverless AWS Lambda functions without Docker layers?
Yes! Because fpdf2 has zero C/system library dependencies, it zips into standard Lambda deployment packages effortlessly.
How are tables rendered in exported fpdf2 code?
CodePDF emits clean Python loops drawing styled table headers, alternating row fills, cell borders, and dynamic pagination.
fpdf2 vs Other Python PDF Libraries
- ReportLab (Python) — 170 ms, 46.4 MB RAM, 179.5 KB PDF. Fastest & lowest-RAM Python engine (170 ms for 22p, 1.5 ms single-page, 46.4 MB RAM, 0.29s CPU) with BSD-3-Clause license.
- WeasyPrint (Python) — 4.34 s, 188.2 MB RAM, 1059.8 KB PDF. Modern CSS Paged Media without Chromium via Pango/Cairo: 144 ms single-page, 4.34s & 1,059.8 KB across 18 dense overflowing pages.
- xhtml2pdf (Python) — 2.06 s, 159.6 MB RAM, 139 KB PDF. Pip-only pure-Python HTML/CSS 2.1 on ReportLab (61 ms single-page; 2.06s & 139.0 KB across 23p) — zero Pango/Cairo OS dependencies.
See the full 22-library benchmark rankings · Compare all supported PDF libraries