Metadata-Version: 2.5
Name: pdfedit
Version: 0.1.0
Summary: Find and edit any text in a PDF while matching the original font, size, and color
Project-URL: Homepage, https://github.com/sachinpandey22/pdfedit
Project-URL: Repository, https://github.com/sachinpandey22/pdfedit
Project-URL: Issues, https://github.com/sachinpandey22/pdfedit/issues
Author-email: Sachin Pandey <xachin300@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: edit,font,pdf,pymupdf,redaction,text
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing :: Markup
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: pymupdf>=1.28.2
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# 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](https://pymupdf.readthedocs.io/),
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

```bash
pip install pdfedit
```

This puts a `pdfedit` command on your PATH. You can also run it as
`python -m pdfedit`.

From source (for development):

```bash
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

```bash
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:

```json
[
  { "id": "p1-b0-l0-s0", "new_text": "New Name" },
  { "find": "Old Company", "new_text": "New Company" }
]
```

- `id` targets one exact span.
- `find` replaces that substring in **every** span containing it. Multiple
  `find` entries 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

```bash
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`](https://github.com/sachinpandey22/pdfedit/blob/main/CLAUDE.md)
for the architecture and the two redraw pitfalls the engine works around,
and [`docs/`](https://github.com/sachinpandey22/pdfedit/tree/main/docs) for
longer background.
