Best PDF Generation Libraries (2026 Benchmarks) — 22 Engines Ranked

The best PDF library for Python, Node.js, PHP, Rust, Go, C#, Java and Ruby: 22 engines ranked by speed, CPU, peak RAM and file size on one real document.

Disclaimer: All generation times measure pure PDF generation time only — captured inside a warm, already-initialized runtime after project setup, package installation, ahead-of-time compilation (cargo build --release, go build, dotnet build -c Release, javac, esbuild), module imports, and one-time headless browser launch — taking the median of 5 renders on CodePDF’s 26-Component Dynamic Multi-Page Flow suite (18–27 overflowing pages with custom TTF fonts, tables, repeating cards, barcodes, QR codes, AcroForm inputs, and running headers/footers) and a 1-page commercial invoice baseline. CPU time and Peak RAM come from single-shot /usr/bin/time -l runs of the pre-built executable (excluding compiler and package-manager overhead). Actual production latency, RAM, and PDF file size vary with layout complexity, embedded fonts/images, dynamic row counts, and server hardware.

Best PDF Library by Programming Language

Best Python PDF Library

ReportLab was the fastest (170 ms across 22 pages, 1.5 ms single-page) and lowest-RAM (46.4 MB, BSD-3-Clause) Python engine in pure PDF generation. fpdf2 produced the smallest pure-Python PDF (135.0 KB in 389 ms, zero C libs, LGPL-3.0). xhtml2pdf offers pip-only CSS 2.1 HTML conversion (2.06s, 139.0 KB), while WeasyPrint supports modern CSS Paged Media via native Pango/Cairo (144 ms single-page; 4.34s & 1,059.8 KB across 18 dense overflowing pages).

ReportLab (Python) Templates | fpdf2 (Python) Templates | xhtml2pdf (Python) Templates | WeasyPrint (Python) Templates

Best Node.js & JavaScript PDF Library

jsPDF (120 ms, 3.5 ms single-page, 98.3 MB RAM) and PDFKit (140 ms, 2.8 ms single-page) led pure JS generation speed. @react-pdf/renderer generated the #2 smallest multi-page PDF overall (126.8 KB, 12 ms single-page; run server-side in Next.js Route Handlers). pdf-lib works in browsers, Deno, Bun, and Cloudflare Workers and edits existing PDFs (334 ms). pdfmake handles declarative JSON tables (189 ms), and Playwright beat Puppeteer on warm render speed (883 ms vs 1.35s), RAM (204 vs 263 MB), and file size (452 vs 841 KB).

jsPDF Templates | PDFKit (Node.js) Templates | @react-pdf/renderer Templates | pdf-lib Templates | pdfmake Templates | Playwright Templates | Puppeteer Templates

Best PHP PDF Library

FPDF was #4 fastest overall and #1 fastest interpreted engine (37 ms, 0.4 ms single-page, 28.8 MB RAM, MIT, ISO-8859-1 only), TCPDF rendered 22 pages in 176 ms with native UTF-8 and barcodes (41.0 MB RAM), and Dompdf delivered pure-PHP HTML/CSS rendering (17 ms single-page; 1.03s & 140.7 KB across 22 pages).

FPDF (PHP) Templates | TCPDF (PHP) Templates | Dompdf (PHP / Laravel) Templates

Best Rust PDF Library

Once compiled, pdf-writer (Typst’s engine) ranked #1 lowest RAM (5.9 MB) and #2 fastest pure PDF generation overall (16 ms, 0.2 ms single-page). lopdf ranked #2 lowest RAM (9.9 MB), #3 fastest (33 ms), and #3 smallest PDF (132.6 KB) while modifying existing PDFs. printpdf provides a higher-level typed Op-vector API (44 ms, 37.7 MB RAM).

pdf-writer (Rust) Templates | lopdf (Rust) Templates | printpdf (Rust) Templates

Best Go, C# (.NET), Java & Ruby PDF Libraries

Go: gofpdf / go-pdf/fpdf ranked #1 fastest overall in pure PDF generation (15 ms across 22 pages, 0.7 ms single-page, 15.6 MB RAM). Java: Apache PDFBox 3.0 generated 22 pages in 48 ms on a warm JVM (2.8 ms single-page, Apache-2.0) and edits existing PDFs. C# / .NET: QuestPDF rendered 24 pages in 214 ms via Skia (free Community tier under $1M revenue). Ruby / Rails: Prawn produced the #1 smallest PDF across all 22 libraries (79.0 KB in 537 ms, 34.0 MB RAM).

gofpdf (Go) Templates | QuestPDF (C# / .NET) Templates | Apache PDFBox (Java) Templates | Prawn (Ruby / Rails) Templates

All-Components Dynamic Multi-Page Flow Benchmark (26 Components, 18–27 Pages — Pure PDF Generation Time)

22 PDF libraries measured on pure PDF generation time (project setup, compilation & cold browser launch excluded)
Library Runtime Engine PDF Gen Time CPU Time PDF Size Peak RAM
gofpdf (Go)GoCoordinate Canvas15 ms0.03 s149.8 KB15.6 MB
pdf-writer (Rust)RustLow-Level / Object Editor16 ms0.04 s157.2 KB5.9 MB
lopdf (Rust)RustLow-Level / Object Editor33 ms0.03 s132.6 KB9.9 MB
FPDF (PHP)PHPCoordinate Canvas37 ms0.09 s140.1 KB28.8 MB
printpdf (Rust)RustCoordinate Canvas44 ms0.08 s154.2 KB37.7 MB
Apache PDFBox (Java)JavaLow-Level / Object Editor48 ms0.98 s148.2 KB117.6 MB
jsPDFNode.jsCoordinate Canvas120 ms0.44 s157.4 KB98.3 MB
PDFKit (Node.js)Node.jsCoordinate Canvas140 ms0.52 s162.6 KB125.5 MB
ReportLab (Python)PythonCoordinate Canvas170 ms0.29 s179.5 KB46.4 MB
TCPDF (PHP)PHPCoordinate Canvas176 ms0.26 s195.9 KB41 MB
pdfmakeNode.jsCustom Layout Engine189 ms0.85 s165.5 KB183.7 MB
QuestPDF (C# / .NET).NETCustom Layout Engine214 ms0.59 s403.2 KB130.8 MB
pdf-libNode.jsLow-Level / Object Editor334 ms1.09 s203.8 KB209.7 MB
fpdf2 (Python)PythonCoordinate Canvas389 ms0.71 s135 KB81.8 MB
Prawn (Ruby / Rails)RubyCoordinate Canvas537 ms0.65 s79 KB34 MB
HTML5 & CSS Paged MediaNode.jsBrowser (Chromium)818 ms1.22 s453.6 KB196.3 MB
PlaywrightNode.jsBrowser (Chromium)883 ms2.13 s452.2 KB203.8 MB
Dompdf (PHP / Laravel)PHPCSS-to-PDF1032 ms1.13 s140.7 KB103.2 MB
@react-pdf/rendererNode.jsCustom Layout Engine1058 ms2.79 s126.8 KB237.3 MB
PuppeteerNode.jsBrowser (Chromium)1346 ms4.40 s841.2 KB263.2 MB
xhtml2pdf (Python)PythonCSS-to-PDF2059 ms2.62 s139 KB159.6 MB
WeasyPrint (Python)PythonCSS-to-PDF4337 ms4.74 s1059.8 KB188.2 MB

Frequently Asked Questions: Choosing the Best PDF Library

What is the best Python library to generate PDFs?

It depends on your layout style and deployment target. Measuring pure PDF generation time (excluding interpreter/import setup), ReportLab was the fastest and lowest-RAM Python library on our 26-component multi-page benchmark (170 ms across 22 pages, 1.5 ms single-page, 46.4 MB RAM, permissive BSD-3-Clause). fpdf2 produced the smallest Python PDF with 100% pure Python and zero C dependencies (135.0 KB in 389 ms; 3.5 ms single-page; LGPL-3.0). Choose WeasyPrint when you need modern @page CSS Paged Media without Chrome (144 ms single-page, 4.34s across 18 dense overflowing pages via native Pango/Cairo), or xhtml2pdf for pip-only CSS 2.1 HTML conversion (61 ms single-page, 2.06s stress test).

What is the best JavaScript or Node.js library to generate PDFs?

Measuring pure PDF generation time without CLI/transpiler overhead, jsPDF (120 ms across 22 pages, 3.5 ms single-page, 98.3 MB RAM) and PDFKit (140 ms across 22 pages, 2.8 ms single-page) are the fastest pure-JS vector engines. For browsers, Deno, Bun, or Cloudflare Workers — or when you need to edit or fill existing PDFs — pdf-lib is the best choice (334 ms stress, 5.3 ms single-page). For React teams who want Flexbox JSX without a browser, @react-pdf/renderer produced the #2 smallest multi-page PDF overall (126.8 KB across 18 pages, 12 ms single-page; run server-side in Next.js Route Handlers). Choose pdfmake (189 ms) for declarative JSON tables, or Playwright over Puppeteer (883 ms vs. 1.35s warm render) if you need full Chromium HTML/CSS.

What is the best PHP library to generate PDFs?

FPDF ranked #4 fastest overall and #1 fastest among all interpreted languages in pure PDF generation (37 ms for 22 pages, 0.4 ms single-page, 28.8 MB RAM, MIT), though it only supports ISO-8859-1 (no native UTF-8). TCPDF finished 22 pages in 176 ms (2.7 ms single-page, 41.0 MB RAM) and adds native UTF-8 and built-in barcodes (LGPL-3.0). For Laravel or PHP teams rendering HTML/CSS templates without Node or Chrome, Dompdf generated 1-page invoices in 17 ms (2.2 KB) and 22 stress-test pages in 1.03s (140.7 KB, LGPL-2.1).

What is the best Rust library to generate PDFs?

Once compiled (excluding cargo build time), Rust dominated memory, CPU, and latency. pdf-writer (the typed serializer crate powering Typst) ranked #1 lowest Peak RAM (5.9 MB) and #2 fastest pure PDF generation overall (16 ms across 22 pages, 0.2 ms single-page). Choose lopdf (#2 lowest RAM at 9.9 MB, #3 fastest at 33 ms, #3 smallest PDF at 132.6 KB) if you also need to load, merge, or stamp existing PDFs, or printpdf (44 ms, 0.3 ms single-page) for a higher-level Op-vector drawing API.

What are the best PDF libraries for C# (.NET), Java, Go, and Ruby?

For Go, gofpdf (or its actively maintained MIT fork go-pdf/fpdf) ranked #1 fastest overall in pure PDF generation (15 ms across 22 pages, 0.7 ms single-page, 15.6 MB RAM) and compiles with zero CGO into static containers. For Java / Spring Boot, Apache PDFBox 3.0 generated 22 pages in just 48 ms on a warm JVM (2.8 ms single-page, permissive Apache-2.0) and edits existing PDFs. For C# / .NET, QuestPDF rendered 24 pages in 214 ms (4.3 ms single-page) via Google Skia (free Community tier under $1M revenue). For Ruby on Rails, Prawn produced the #1 smallest PDF of all 22 libraries (79.0 KB across 22 pages in 537 ms, 7.5 ms single-page).

Should I use Puppeteer or Playwright (headless Chrome) instead of a native PDF library?

Use Playwright or Puppeteer when you need full modern browser CSS (Grid, complex Flexbox, web fonts, SVG) and keep a warm Chromium instance pooled — note Playwright beat Puppeteer on pure PDF render speed (883 ms vs. 1.35s), RAM (204 vs. 263 MB), and file size (452 vs. 841 KB) on the exact same 19-page document. For high-throughput billing, serverless functions, or smaller email attachments, native engines like gofpdf, pdf-writer, PDFBox, FPDF, jsPDF, PDFKit, ReportLab, QuestPDF, or Prawn generate PDFs 4x–90x faster with 3x–10x smaller files and zero Chromium binary overhead.

Inspect All-Components Benchmark Template | Compare All 22 Libraries | Browse 100 Free Templates