fastpdfium adds a small ergonomic layer over
pypdfium2, the Python binding for
PDFium, the PDF engine Chrome uses. It gives you page-tagged text
extraction, content-based search whose hits carry their matched text and
surroundings, previews with matches highlighted on the rendered page,
and simple authoring (text, boxes, images) that pypdfium2 alone doesn’t
expose. Pages get a _repr_png_, so a bare PdfPage expression
displays itself in any rich frontend: Jupyter, solveit, or an AI-driven
kernel.
PDFium and pypdfium2 are permissively licensed, so fastpdfium is plain Apache-2.0. If you need structured layout extraction, redaction, or richer authoring, PyMuPDF does more at the cost of AGPL; see fastfitz.
pip install fastpdfiumfastpdfium also registers a pyskill, so AI kernels with pyskills discovery gain PDF reading and editing automatically when fastpdfium is installed.
import pypdfium2 as pdfium
from fastpdfium.core import *
pdf = pdfium.PdfDocument('some.pdf')
print(pdf.text(pages=[0])) # cheap first: page-tagged text
ms = pdf.search('Delaware') # content-based matches across the document
ms[0].ctx() # the hit marked inline: '...a **Delaware** corporation...'
ms[0].page.preview('Delaware', crop=True) # see it highlighted on the page
pdf[0] # bare page displays itself
doc = pdfium.PdfDocument.new() # authoring from nothing
pg = doc.new_page()
pg.insert_text('Hello PDF', 72, 92, size=14)
doc.save('hello.pdf')