Python PDF generation libraries

Updated Nov 2026

Python PDF generation libraries create PDF documents from code, templates, or HTML. An HTML renderer lays out each page from markup and CSS rather than from drawing commands at fixed coordinates. These libraries let apps generate invoices, reports, and certificates as PDF files.

Popularity

PyMuPDF has the most monthly downloads in this comparison, at 168.7M, a count that covers all its PDF work.

LibraryMonthly downloadsStarsLast releaseLicense
PyMuPDF
168.7M
11.2KNov 2026AGPL-3.0 or commercial
ReportLab
90.0M
88Oct 2026BSD
WeasyPrint
44.5M
9.8KSep 2026BSD
pydyf
42.5M
158Oct 2026BSD
fpdf2
22.7M
1.6KOct 2026LGPL-3.0-only
pdfkit
5.0M
2.0KNov 2021MIT
xhtml2pdf
4.3M
2.4KOct 2026Apache-2.0
borb
377.1K
3.6KAug 2026AGPL-3.0-or-later
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Extracts, analyzes, converts, and edits PDF and other documents.

Downloads / mo
168.7M
Stars
11.2K
Last release
2.1
License
AGPL-3.0 or commercial

Quickstart

From recipes-text.rst
$ python3 -m pip install PyMuPDF
import pymupdf
document = pymupdf.open()
page = document.new_page()
page.insert_text((72, 72), 'Hello World!')
document.save('hello.pdf')

PyMuPDF examples

From open-source projects on GitHub

Creates PDF documents with drawing APIs and a page-layout engine for report content.

Downloads / mo
90.0M
Stars
88
Last release
5.1.0
License
BSD

Strengths

  • Separates report content from layout. Build reports from paragraph styles, page templates, and flowing content.
  • Repeats table headers across pages. Split long tables across pages and repeat their header rows.

Limitations

  • Frames reject oversized content. Resize or split elements that cannot fit inside a frame.

Quickstart

From README.md
$ python3 -m pip install reportlab
from reportlab.pdfgen import canvas
def hello(c):
    c.drawString(100,100,"Hello World")
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()

ReportLab examples

From open-source projects on GitHub

WeasyPrint

Produces documents.

Downloads / mo
44.5M
Stars
9.8K
Last release
70.0
License
BSD

Quickstart

From first_steps.rst
$ pip install weasyprint
from weasyprint import HTML
HTML('https://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')

Writes PDF objects and content streams through a low-level Python interface.

Downloads / mo
42.5M
Stars
158
Last release
0.13.0
License
BSD

Strengths

  • Builds PDF objects directly. Construct dictionaries, arrays, streams, and page resources explicitly.
  • Draws vector paths and graphics. Control rectangles, line styles, transforms, and fills through a content stream.

Limitations

  • Text needs explicit font resources. Supply font dictionaries and page resources when constructing text streams.

Quickstart

From common_use_cases.rst
$ python3 -m pip install pydyf
import pydyf
document = pydyf.PDF()
document.add_page(pydyf.Dictionary({
    'Type': '/Page',
    'Parent': document.pages.reference,
    'MediaBox': pydyf.Array([0, 0, 200, 200]),
}))
with open('document.pdf', 'wb') as f:
    document.write(f)

pydyf examples

From open-source projects on GitHub

Builds PDF documents with text, images, tables, font embedding, and page-break controls.

Downloads / mo
22.7M
Stars
1.6K
Last release
2.9.0
License
LGPL-3.0-only

Strengths

  • Breaks flowing text across pages. Cells and write text trigger page breaks at the configured bottom margin.
  • Builds tables from row data. Add rows and cells through the table context manager.

Limitations

  • Complex scripts need shaping setup. Install uharfbuzz and enable set_text_shaping for complex script rendering.
  • Opening restrictions need user passwords. Set a user password when opening the document must require authentication.

Quickstart

From Tables.html
$ python3 -m pip install fpdf2
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica", style="B", size=16)
pdf.cell(40, 10, "Hello World!")
pdf.output("tuto1.pdf")

fpdf2 examples

From open-source projects on GitHub

Converts HTML to PDF through wkhtmltopdf and the WebKit rendering engine.

Downloads / mo
5.0M
Stars
2.0K
Last release
1.0.0
License
MIT

Quickstart

From README.rst
$ python3 -m pip install pdfkit
import pdfkit
pdfkit.from_string('Hello!', 'out.pdf')

pdfkit examples

From open-source projects on GitHub

Generates PDF from HTML and CSS.

Downloads / mo
4.3M
Stars
2.4K
Last release
0.2.28
License
Apache-2.0

Quickstart

From quickstart.rst
$ pip install xhtml2pdf[all]
import io

from xhtml2pdf import pisa

output = io.BytesIO()

pisa.CreatePDF(
    "<html><body><p>To PDF or not to PDF</p></body></html>",  # page data
    dest=output,                                              # destination "file"
)

# You can get the PDF file bytes with `.getbuffer()`
print(len(output.getbuffer()))

xhtml2pdf examples

From open-source projects on GitHub

Reads, creates, and edits PDF files.

Downloads / mo
377.1K
Stars
3.6K
Last release
3.0.9
License
AGPL-3.0-or-later

Quickstart

From README.md
$ python3 -m pip install borb
from pathlib import Path
from borb.pdf import Document, Page, PageLayout, SingleColumnLayout, Paragraph, PDF
d: Document = Document()
p: Page = Page()
d.append_page(p)
l: PageLayout = SingleColumnLayout(p)
l.append_layout_element(Paragraph('Hello World!'))
PDF.write(what=d, where_to="assets/output.pdf")

FAQ

ReportLab suits reports with flowing layouts, tables, and page templates. WeasyPrint suits documents written as HTML and CSS. fpdf2 suits pages built from text, tables, and images in Python.

PyMuPDF creates, converts, and edits PDF documents and lays out HTML and CSS through its Story feature. It also extracts and analyzes content from existing PDFs.

WeasyPrint renders HTML and CSS to PDF, including paged media layout. It relies on system libraries for rendering.

ReportLab draws PDF pages on a canvas and builds flowing reports with tables, page templates, and styles through its Platypus layer.

xhtml2pdf generates PDF from HTML and CSS on top of ReportLab. It supports a documented subset of markup and styles rather than full browser CSS.

For coding agents

Found your PDF generation library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official