pdfboss.dev

Compare

pdfboss vs pypdf.

pypdf, the continuation of PyPDF2, is the pure-Python library for working on documents as documents: splitting, merging, cropping, transforming, encrypting. pdfboss is a Rust engine for reading what is on the pages (text, Markdown, images, rendered pixels, forms and bookmarks) that also merges, splits, rotates and encrypts. Both are permissively licensed.

At a glance
pdfbosspypdf
LicenseMIT OR Apache-2.0BSD-3-Clause
EngineWritten from scratch in safe Rust; no C dependenciesPure Python; optional extras for AES and images
Text extractionLayout analysis (columns, reading order, word spacing); 10,312 pages/s over 40 PDFsextract_text() per page, in pure Python
Rendering to PNG, PPM, BMP or JPEG161.9 pages/s (38 certified files, 888 pages)Not provided
PDF to Markdownpdfboss md, from layoutNot provided
Splitting and mergingmerge, split, rotate, overlay, metadata; incremental updates or a full rewriteSplitting, merging, cropping, transforming
Encrypted PDFsOpens RC4 and AES-128/256 files; encrypts with AES-256 and decryptsDecrypts and encrypts documents
Embedded imagesextract_images() at native size, alpha appliedImage extraction with the Pillow extra
Async and remoteAsyncDocument over files and HTTP range requestsSynchronous API
Installabi3 wheels for CPython 3.12+Pure Python, Python 3.9+, no compiled extension

pdfboss throughput rows come from the pdfboss benchmark harness. The pdfboss README publishes no pypdf figure, so this page states no number for it. License and dependency statements come from each project’s PyPI metadata.

Migration

The reading path, side by side.

Both index pages 0-based. pdfboss’s extract_text() on the document covers all pages with layout analysis applied and spreads them across cores, and extract_markdown() adds headings, lists and tables detected from the page geometry.

before.py · pypdf
from pypdf import PdfReader

reader = PdfReader("report.pdf")
print(len(reader.pages), "pages")

text = "\n".join(page.extract_text() for page in reader.pages)
first = reader.pages[0].extract_text()
after.py · pdfboss
import pdfboss

doc = pdfboss.Document("report.pdf")
print(doc.page_count, "pages")

text = doc.extract_text()
markdown = doc.extract_markdown()
first = doc[0].extract_text()

Where pypdf is ahead

What pypdf does that pdfboss does not.

  • Cropping and transforming pages, filling form fields, and creating annotations. pdfboss merges, splits, rotates, overlays and re-encrypts, but does not crop, fill or annotate.
  • Pure-Python portability: no compiled extension, so it installs anywhere Python 3.9 or later runs.
  • History: pypdf continues PyPDF2, and a large body of existing code, answers and documentation targets its API.

Where pdfboss is ahead

What pdfboss does that pypdf does not.

  • A compiled-Rust extractor with layout analysis that spreads pages across cores: 10,312 pages per second over the 40-file corpus.
  • Rendering: pages rasterize to PNG, PPM, BMP or JPEG through an anti-aliased rasterizer with its own JPEG 2000, JBIG2, CCITT and ICC decoders.
  • Markdown output with headings, lists and tables, and styled spans carrying font, weight, decorations and color.
  • Embedded images at native size with alpha applied, with no extras to install.
  • Async reading over HTTP range requests, and a per-page report of everything dropped or approximated.
  • A jq-style query language and a terminal explorer over the document's element tree (pdfboss q, hex, json, tui).

Questions

Is pdfboss a drop-in replacement for pypdf?
Not as a drop-in: the APIs differ. pdfboss covers the reading side (text, Markdown, rendering, image extraction, forms and bookmarks) and document assembly (merge, split, rotate, encrypt, decrypt, watermark), each migrating in a few lines per call site. It does not crop or transform pages, fill forms or write annotations. The two coexist fine in one project.
Is pdfboss faster than pypdf at extracting text?
The pdfboss README publishes no pypdf figure, so no ratio is claimed here. pdfboss measures 10,312 pages per second over its 40-file corpus, from compiled Rust that runs layout analysis and spreads pages across cores; pypdf extracts in pure Python through a per-page extract_text() call, which is CPU-bound in the interpreter.
Can pypdf render a PDF page to an image?
No. pypdf works on documents as documents: splitting, merging, cropping, transforming, encrypting and decrypting, plus text and image extraction. It does not rasterize pages. pdfboss renders to PNG, PPM, BMP or JPEG at 161.9 pages per second over 888 certified pages on the measured corpus.
Do the licenses differ in practice?
Barely. pypdf is BSD-3-Clause and pdfboss is MIT OR Apache-2.0, all permissive licenses with attribution requirements and no copyleft. Both ship in commercial and closed-source software without a license to buy, so the choice is technical.