Skip to content

Archived project · Final release 0.16.1

Migrate from pylopdf to pyropdf

pylopdf is archived and no longer receives features, bug fixes, or security updates. Development continues in pyropdf, its successor on a rebuilt Rust foundation.

pip install pyropdf

Why pyropdf replaces pylopdf

pylopdf held three separate object models — lopdf's editable graph, hayro's parse of serialized bytes, and the PDFs generated by krilla — and reconciled them after the fact. Every edit dropped hayro's snapshot, transactions cloned the whole graph, and lopdf stored real numbers as 32-bit floats.

pyropdf keeps pylopdf's concept and Python API design on one versioned object store in Rust (foundation design and measurements):

  • Edits cost what they touch. Engines read the current version from the store instead of reserializing the whole document.
  • Versions and undo by construction. Every edit produces an immutable version; failed transactions roll back without copying the document, and doc.history undoes and redoes steps.
  • Lossless saves and change reports. Untouched objects keep their original bytes, incremental saves append only modified objects so existing signatures remain valid, and doc.changes reports broken signatures or PDF/A and PDF/UA claims before saving.
  • Broader PDF support. Digital signing and verification, content sanitizing, recoloring, variable and color fonts on the canvas, and typed objects generated from the Arlington PDF Model.

How to migrate

Replace the package and update your import:

pip uninstall pylopdf
pip install pyropdf
import pyropdf

with pyropdf.open("input.pdf") as doc:
    page = doc.pages[0]
    text = page.text()
    hits = page.search("invoice")
    page.pixmap(dpi=150).save("page.png")

    with doc.transaction("annotate"):
        page.annotations.add(pyropdf.Highlight(hits))
    doc.save("output.pdf", incremental=True)
  • Migrating from pylopdf 0.16: most document, page, reading, rendering, canvas, annotation, form, outline, attachment, and layer calls work unchanged once import pylopdf becomes import pyropdf. Check the differences below.
  • Migrating from pylopdf 0.15 or pymupdf: if you want automated rewrites to the 0.16 API shape first, run python -m pylopdf.migrate src/ with pylopdf[migrate]==0.16.1, then switch imports from pylopdf to pyropdf.

Differences from pylopdf 0.16

Area pylopdf 0.16 pyropdf
Import & warning import pylopdf, PylopdfWarning import pyropdf, PyropdfWarning
Extras ocr, jp, ko, zh-cn, zh-tw, ar, he, hi, th, migrate ocr, jp, ko, zh-cn, zh-tw (reusing the same data packages); load other script fonts with pyropdf.Font.from_file(...)
Page boxes page.boxes.media, .crop, .bleed, .trim, .art (PDF user space) page.media_box, page.crop_box, page.bleed_box, page.trim_box, page.art_box (display space)
New documents pylopdf.Document() or pylopdf.create() doc = pyropdf.Document(), doc.pages.new(...) or doc.pages.new_from_image(...), and page.draw()
doc.save() defaults Compresses streams and prunes unused objects by default (compress=True, prune=True) Preserves untouched objects by default (compress=False, prune=False); pass compress=True, prune=True when rewriting for size, or incremental=True
Untrusted input Nesting scanners + DocumentLimits.web() Check Status and safety and run untrusted files in a bounded worker (Limits and errors) until upstream bounded construction lands
WebAssembly Pyodide 0.28.3 wheel in releases Tracked on the pyropdf roadmap; existing pylopdf 0.16 wheels remain available on PyPI and GitHub Releases