pyropdf
Read, render, and edit PDFs in Python. Undo your edits.
pyropdf combines a Python API with a Rust core: extract text and tables,
render pages, fill forms, and annotate documents in one package.
Transactions group edits into one undoable step; a failed transaction
leaves the document as it was.

Documentation ·
Recipes ·
API reference ·
Choosing a PDF library ·
Japanese docs
See it work
| Read an invoice |
Highlight, fill, and stamp it |
|
|
These are real pyropdf renders. Walk through the four steps,
open the resulting PDF,
or reproduce the images.
Try it
Python 3.11–3.15 on Linux, macOS, and Windows, including free-threaded
CPython. No required dependencies; OCR and CJK fallback fonts are optional
extras.
pip install pyropdf
Run this in an empty directory. It creates its own PDF, highlights the
total, renders a preview, undoes and redoes the highlight, and saves the
result. No sample download or account is needed.
import pyropdf
with pyropdf.Document() as doc:
page = doc.pages.new((360, 240))
with page.draw() as canvas:
canvas.text("Invoice total: $42", (30, 60),
font=pyropdf.Font.standard("Helvetica"), size=20)
source = doc.to_bytes()
with pyropdf.open(source) as doc:
page = doc.pages[0]
print(page.text().strip())
with doc.transaction("highlight total"):
page.annotations.add(pyropdf.Highlight(page.search("$42")))
page.pixmap(dpi=144).save("reviewed.png")
doc.history.undo()
print("After undo:", len(page.annotations))
doc.history.redo()
doc.save("reviewed.pdf", incremental=True)
Output:
Invoice total: $42
After undo: 0
Open reviewed.png or reviewed.pdf to see the highlighted total.
For an existing file, use pyropdf.open("input.pdf").
What can I build?
| Task |
Start here |
| Extract text, words, tables, Markdown, or retrieval chunks |
Reading content |
| Turn PDF pages into PNG, JPEG, or SVG |
Rendering |
| Fill forms, highlight text, stamp pages, or draw content |
Editing |
| Read scanned documents with offline OCR |
OCR |
| Undo/redo edits, save incrementally, encrypt, or sign |
Versions and saving |
Why pyropdf?
- Reversible edits. Group changes in a named transaction and undo or
redo them through
doc.history. Exceptions discard the whole transaction.
- One document for reading, rendering, and editing. All engines read
the same versioned object store. Preview an edit before saving it.
- Incremental saves. Append changed objects while keeping the original
file's bytes intact. Inspect
doc.changes() before saving.
- MIT licensed. Use it in open-source or commercial applications.
Choosing pyropdf compares capabilities
and limitations with PyMuPDF, pypdf, and pikepdf.
DESIGN.md explains the architecture.
Status and limits
0.4 series, alpha. The API may change between minor versions.
Release notes
describe each release. See status and safety
for current coverage and limitations.
No pyropdf release claims safety for untrusted input before hayro's bounded
construction (I2, #15) is
released. DocumentLimits bounds the work of an operation, but it is not
that claim.
Contributing
For your first contribution, browse the available good first issues
and leave a comment on the one you would like to take.
CONTRIBUTING.md
explains how to build, test, and propose a change, and
SECURITY.md
how to report a vulnerability.
If pyropdf is useful to you, star the repository
to find it again. A small reproducible example in an
issue helps improve it for your use case.