pdfedit
A command-line tool that finds and edits any text in a PDF while matching the original font, size, and color — not a fixed find-and-replace on known form fields. It walks every text span via PyMuPDF, resolves each span's real font (embedded extraction, or the closest Base-14 fallback), then redacts the old glyphs and redraws the replacement in the same font, size, and color at the same position.
The original file is never modified — every edit writes <name>_edited.pdf
next to the input.
Status: alpha, pre-1.0 — the API and CLI may still change. White-fill redaction only (colored backgrounds not yet sampled); no paragraph reflow; scanned pages are detected and warned about, not OCR'd.
Install
pip install pdfedit
This puts a pdfedit command on your PATH. You can also run it as
python -m pdfedit.
From source (for development):
git clone https://github.com/sachinpandey22/pdfedit && cd pdfedit
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]" # editable install + pytest
Usage
pdfedit inspect your-document.pdf # read-only: list every text span with its id, font, size, color
pdfedit edit your-document.pdf # interactive: pick a span id, type a replacement, `save`
pdfedit batch your-document.pdf edits.json # non-interactive: apply a list of edits
inspect
Prints one row per span. The ID (p<page>-b<block>-l<line>-s<span>) is the
handle you pass to edit or a batch file.
edit
A small REPL. Enter a span id, then the replacement text; the edit is
queued with a before/after preview (and the resolved font, and an
auto-shrink note if the text had to be made smaller to fit). save applies
every queued edit at once and writes the output. quit discards everything.
batch
edits.json is a JSON array; each entry is either:
[
{ "id": "p1-b0-l0-s0", "new_text": "New Name" },
{ "find": "Old Company", "new_text": "New Company" }
]
idtargets one exact span.findreplaces that substring in every span containing it. Multiplefindentries against the same span compose in order.
The whole file is validated first — if any entry is malformed or names a missing span id, nothing is written and the command exits non-zero.
Autofit
If a replacement is wider than the original box, the font size shrinks (down to 60% of the original) until it fits. Past that floor it's drawn at the minimum size and a warning is printed rather than overflowing silently.
Encrypted PDFs
You're prompted for the password. Note: the _edited.pdf copy is written
without encryption.
Development
pytest # run the test suite
python tests/fixtures/make_sample.py # regenerate the synthetic test fixture
There's no separate lint config. See
CLAUDE.md
for the architecture and the two redraw pitfalls the engine works around,
and docs/ for
longer background.
Metadata
Release files for pdfedit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pdfedit-0.1.0.tar.gz | 35.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pdfedit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 50.2 kB
Release files / pdfedit-0.1.0.tar.gz
| Download URL | pdfedit-0.1.0.tar.gz |
|---|---|
| Size | 35.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4e1763dfa49ef7c0e24fce8800737577d311405c8776abd44ae0437df4af890
|
|
BLAKE2b-256 checksum How to use checksums |
8ff99f8b9519c1b70eba5a46dc6913b71e306881fa3f6d6a637316b4c0787fd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / pdfedit-0.1.0-py3-none-any.whl
| Download URL | pdfedit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be96c1a4670936cbe88415d60d6e37fddf351011763f7e9f5dd906d5683e8382
|
|
BLAKE2b-256 checksum How to use checksums |
603f70d44f65ad2096489e754521433fbdc82dac160d232c8e7872f9e1601cb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|