A layout-surgery engine for PDFs on a fully permissive stack (pypdfium2 · pikepdf · reportlab · pdfplumber · Pillow · fontTools). Read a page's text, vector art, and images with coordinates; erase text and art out of the content stream; draw replacements; subset and save.
Status: v0.2.0. Installable from source; live coverage suite; glyph-precision text erasure (simple and CID fonts); per-glyph font fallback; pdfium thread-lock.
pip install .Python 3.11+. Fonts are not bundled — supply your own (see NOTICE).
import paw
doc = paw.open("form.pdf")
page = doc.pages[0]
# read
page.text_spans() # text with font, size, colour, bbox
page.strokes(); page.fills() # vector art (gridlines, highlight bars)
page.images() # placed images with bboxes
page.raster(dpi=200) # a PIL image of the page
# write — region is (x0, y0, x1, y1) in points, origin top-left, y down
region = (72, 100, 300, 130)
page.erase_text(region) # text out of the content stream
page.erase_art(region) # covered rules and highlights out
page.draw_text("Hello", at=(72, 118), font=paw.Font.load("Noto.ttf"), size=12)
page.draw_box(region)
page.place_image(pil_image, region)
doc.save("form.out.pdf")Coordinates are points, origin top-left, y growing down; draw_text(at=…) positions the
baseline start.
| Call | Does |
|---|---|
paw.open · paw.blank · doc.save · doc.subset |
open · create · write · keep only some pages |
page.text_spans · page.text_lines |
text with font, size, colour, bbox |
page.strokes · page.fills · page.images · page.links |
vector art · fills · images · links |
page.raster(dpi) |
render the page to a PIL image |
page.erase_text · page.erase_art |
remove text · path objects inside a region |
page.draw_text · page.draw_box · page.draw_rule · page.place_image |
draw onto the page |
paw.Font.load |
load a TTF for measuring and drawing |
python tests/coverage_check.pyExercises every public call against a synthetic document and prints the status report.
Third-party component licences are listed in NOTICE.
