Precision pdf editing

From jsath/claude-skills · View interactive version

Precision pdf editing is an AI agent skill from the GitHub repository jsath/claude-skills. Makes surgical edits to an existing PDF (change every value in one table column, fix a few labels, replace text in fixed cells) while keeping page geometry, fonts, highlights, images, metadata and every unrelated pixel unchanged, then proves it with a mapping CSV, a pixel diff outside the edit masks

How to use this skill

Skill file

Precision PDF Editing

Change a few values in a PDF without rebuilding it, and prove nothing else moved.

Do not regenerate pages or tables when the user needs everything else untouched:

regeneration changes fonts, wrapping, image encoding and unrelated pixels.

Requirements

"AI PDF editor" or to regenerating the document.

Inputs to confirm first

  1. The source PDF, and an output path (never overwrite the source).
  2. Exactly which cells change: column header text, pages, and the transform

(for example "add 150", "replace X with Y"). Ask if the column is ambiguous.

  1. Number format rules: thousands separator, decimals, currency symbol.

Steps

  1. Preserve and fingerprint the source. Record SHA-256, page count, page

rects and rotation, metadata, fonts (page.get_fonts()), image list. Run

qpdf --check src.pdf so pre-existing defects are not blamed on you.

  1. Inspect. Render every page at 150 to 300 dpi (pdftoppm -r 200 -png)

and look at them. Dump page.get_text("words") and find the header's x-range.

Identify the column by header text AND geometry: right-aligned values share a

right edge. If text extraction order disagrees with the picture, trust the picture.

  1. Enumerate target cells with the script (character-level boxes, not span boxes):

```bash

python scripts/pdf_cells.py cells src.pdf --x0 250 --x1 360 --add 150 > manifest.json

```

Without --add, each cell's "new" is null: fill it in yourself. Check the

printed count against the number of rows you can see on the renders, page by

page. Every target must appear once, nothing else may appear.

  1. Review the manifest: old/new values, fill (background colour under the

cell, null = white), font, size, colour. Integer arithmetic only; format to the

source convention (--thousands auto|comma|none; auto copies each cell, so

980 + 150 gives 1130, which may break the column's style).

  1. Apply:

```bash

python scripts/pdf_cells.py apply src.pdf out.pdf manifest.json

```

It redacts only the union of old and new glyph boxes using the cell's own

fill colour, keeps images and vector graphics, writes the new value on the

same baseline and right edge, reuses the embedded font (or the same base-14

font), and restores metadata with no_new_id.

  1. Verify (all must pass, see references/verification.md):

```bash

python scripts/pdf_cells.py diff src.pdf out.pdf manifest.json --dpi 150

```

Exit 0 means zero changed pixels outside the edit masks. Then run

qpdf --check out.pdf, pdftotext -layout out.pdf - (every new value decodes

once, at the right row), and compare pdfinfo for both files.

  1. Look at it. Render the full pages and zoom each edited region. Check

background continuity, gridlines, clipping, leftover old glyphs, baseline and

weight. A pixel diff of zero outside the masks says nothing about what is

inside them.

Decision rules

subset missing a glyph you need (common when a new digit never appeared in the

original). Tell the user; options are a matching full font file they supply, or

accepting the substitute. Never ship a fallback silently.

A white patch on a coloured row is a defect even when every other check passes.

apart by product text and y-position. Do not "fix" source numbering.

x-range or pattern. Never apply a manifest you have not reconciled.

cannot edit these. Say so; scanned pages need OCR plus an image patch, which is

a different job.

Output

Deliver the edited PDF plus an audit folder:

out.pdf
audit/mapping.csv          page,row_id,context,old,new,edit_bbox
audit/manifest.json        full geometry and styling per cell
audit/diff.json            output of the diff command
audit/renders/             source and output pages, zooms of edited regions
audit/REPORT.md            counts, hashes, checks run, anything ambiguous

Example REPORT.md summary:

Edited 111 cells (68 on p1, 43 on p2), Price column, old + 150.
Outside-mask changed pixels: 0 on both pages (150 dpi, 3 px pad).
qpdf --check: OK. Page sizes, rotation, metadata, trailer /ID: unchanged.
Font: embedded Calibri reused, no fallback.
Note: source prints row 97 twice and skips 98; both kept, told apart by product.

Pitfalls

See references/worked-example.md for a full two-page price-list walkthrough.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.