precision-pdf-editing
Skill14 starsChanged 31 days agoMITView on GitHub
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 and rendered before/after checks. Use when someone says 'add 150 to every price in this PDF', 'change these numbers but keep the layout', 'edit the PDF without regenerating it', or when a natural-language PDF editor would be too loose. Needs Python with PyMuPDF; works in Claude Code or any environment that can run Python.
- Installs packages
In this repository63 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- board-advisorSkill
- bottleneck-removalSkill
- business-auditSkill
- business-starterSkill
- competitor-researchSkill
- founder-independenceSkill
- hand-it-offSkill
- happy-customerSkill
- hiring-replacementSkill
- meeting-follow-upSkill
- monday-numbersSkill
- new-hireSkill
- no-meeting-mondaySkill
- obsidian-brainSkill
- ops-deskSkill
- safe-resaleSkill
- spreadsheet-dashboardSkill
- warm-leadSkill
- downloadable-asset-engineeringSkill
- html-to-pdfSkill
- linux-server-opsSkill
- repo-radarSkill
- secure-credentialsSkill
- security-auditorSkill
- best-timeSkill
- brand-deal-filterSkill
- comment-replySkill
- content-monthSkill
- daily-socialSkill
- dm-closerSkill
- idea-bankSkill
- marketing-teamSkill
- reel-ideationSkill
- reel-scorecardSkill
- trial-postSkill
- viral-breakdownSkill
- youtube-seoSkill
- caption-engineSkill
- content-multiplierSkill
- edit-styleSkill
- footage-ingestSkill
- longform-editSkill
- podcast-repurposeSkill
- raw-to-reelSkill
- ready-to-filmSkill
- reel-captionsSkill
- script-polishSkill
- thumbnail-generatorSkill
- use-local-whisperSkill
- conversion-funnel-auditingSkill
- llms-txtSkill
- seo-agentSkill
- website-designerSkill
- website-devSkill
- be-conciseSkill
- humanizerSkill
- launch-weekSkill
- linkedin-writerSkill
- newsletterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Do not regenerate pages or tables when the user needs everything else untouched: regeneration changes fonts, wrapping, image encoding and …
- Distinctive: line 17
If PyMuPDF cannot be installed, stop and say so.
- Distinctive: line 75
Duplicate or skipped printed row numbers: keep them as they are; tell rows apart by product text and y-position.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Python 3 with
pip install pymupdf numpy(the bundled script uses both). - Optional but recommended:
qpdf(structural check) and Poppler (pdftotext,pdftoppm,pdfinfo). - If PyMuPDF cannot be installed, stop and say so. Do not fall back to an "AI PDF editor" or to regenerating the document.
Inputs to confirm first
- The source PDF, and an output path (never overwrite the source).
- 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.
- Number format rules: thousands separator, decimals, currency symbol.
Steps
- Preserve and fingerprint the source. Record SHA-256, page count, page
rects and rotation, metadata, fonts (
page.get_fonts()), image list. Runqpdf --check src.pdfso pre-existing defects are not blamed on you. - Inspect. Render every page at 150 to 300 dpi (
pdftoppm -r 200 -png) and look at them. Dumppage.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. - Enumerate target cells with the script (character-level boxes, not span boxes):
Withoutpython scripts/pdf_cells.py cells src.pdf --x0 250 --x1 360 --add 150 > manifest.json--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. - 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;autocopies each cell, so980 + 150gives1130, which may break the column's style). - Apply:
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 withpython scripts/pdf_cells.py apply src.pdf out.pdf manifest.jsonno_new_id. - Verify (all must pass, see
references/verification.md):
Exit 0 means zero changed pixels outside the edit masks. Then runpython scripts/pdf_cells.py diff src.pdf out.pdf manifest.json --dpi 150qpdf --check out.pdf,pdftotext -layout out.pdf -(every new value decodes once, at the right row), and comparepdfinfofor both files. - 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
- Font fallback reported (
font_fallbacksnot empty): the embedded font is a 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. - Fill not null: the row is highlighted. The redaction must use that colour. A white patch on a coloured row is a defect even when every other check passes.
- Duplicate or skipped printed row numbers: keep them as they are; tell rows apart by product text and y-position. Do not "fix" source numbering.
- Count mismatch between manifest and visible rows: stop and narrow the x-range or pattern. Never apply a manifest you have not reconciled.
- Rotated pages, scanned images or text drawn as vector outlines: the script 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 ambiguousExample 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
- Span boxes include alignment spaces and produce oversized redactions. Use character boxes (the script does).
- Comparing full word tuples after editing fails because block/line ids renumber. Compare text plus bbox.
- Text-only checks miss white patches; pixel-only checks miss wrong values. Do both.
See references/worked-example.md for a full two-page price-list walkthrough.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

