pdf-surgical-edits
Skill2 starsChanged 2 months agoMITView on GitHub
Redact, draw, and add text to existing PDFs via PyMuPDF.
- Installs packages
In this repository58 other files it gives its agents.
- ad-hoc-script-verificationSkill
- architecture-diagramSkill
- blocked-page-recoverySkill
- cadquery-enclosure-designSkill
- canonical-thumbnailSkill
- circuit-designSkill
- competitor-news-monitorSkill
- component-alternativesSkill
- debugging-hermes-tui-commandsSkill
- docker-container-update-checkSkill
- document-to-action-itemsSkill
- docxSkill
- email-inbox-triageSkill
- embedded-porting-patternsSkill
- ephemeral-file-sharingSkill
- excalidrawSkill
- flash-game-researchSkill
- flutter-android-buildSkill
- flutter-content-renderingSkill
- github-code-reviewSkill
- githubSkill
- goatcounter-analyticsSkill
- google-oauth-file-pollSkill
- grounded-citationsSkill
- hermes-agent-skill-authoringSkill
- hermes-gateway-slash-commandSkill
- hermes-gateway-supervisionSkill
- jellyseerr-watch-suggestionsSkill
- maintained-fork-publishingSkill
- meeting-action-itemsSkill
- native-mcpSkill
- obsidian-mapsSkill
- pdf-flattenSkill
- pdfSkill
- planSkill
- product-price-monitorSkill
- psp-developmentSkill
- psp-homebrew-testingSkill
- psp-prx-plugin-maintenanceSkill
- python-debugpySkill
- python-webapp-patternsSkill
- reddit-readingSkill
- retro-fansiteSkill
- reverse-proxy-websocket-debuggingSkill
- rss-feedsSkill
- simplify-codeSkill
- sketchSkill
- skit-thumbnailSkill
- spikeSkill
- subagent-driven-developmentSkill
- test-driven-developmentSkill
- usb-device-enumerationSkill
- weekly-review-planningSkill
- wiki-media-asset-pipelineSkill
- windows-c-build-toolchainSkill
- windows-crash-forensicsSkill
- writing-plansSkill
- yt-dlp-anti-botSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 119
Use page.get_drawings() to list all vector shapes — useful for identifying which drawings belong to which table area:
- Very specific: line 132
Hebrew text reversed without bidi: Always use get_display() from python-bidi for RTL scripts.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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
PDF Surgical Edits
Modify existing PDF pages in-place: blank regions, redraw shapes, insert text. Uses PyMuPDF (pymupdf).
Prerequisites
python -m pip install PyMuPDF
# For RTL/Hebrew/Arabic text:
python -m pip install python-bidiWorkflow: Redact → Draw → Insert
1. Redact (blank an area)
Removes all drawings AND text in the rect. Fills with a color (usually white).
import pymupdf
doc = pymupdf.open('input.pdf')
page = doc[0]
page.add_redact_annot(pymupdf.Rect(x0, y0, x1, y1), fill=(1, 1, 1))
page.apply_redactions()Redaction removes everything in the rect — vector shapes, text, images. Grid lines inside the rect are also removed. Redraw them after if needed.
2. Draw shapes (rebuild grid, add colored blocks)
def draw_rect(page, x0, y0, x1, y1, fill=None, color=(0,0,0), width=0.5):
shape = page.new_shape()
shape.draw_rect(pymupdf.Rect(x0, y0, x1, y1))
if fill:
shape.finish(fill=fill, color=fill, width=width)
else:
shape.finish(color=color, width=width)
shape.commit()3. Insert text
LTR text (English, numbers, codes)
page.insert_text(
pymupdf.Point(x, y), 'Hello 123',
fontfile='C:/Windows/Fonts/tahoma.ttf', fontname='tah', fontsize=6
)RTL text (Hebrew, Arabic) — REQUIRES python-bidi
pymupdf does NOT apply Unicode bidi. Hebrew text inserted in logical order renders backwards in PDF viewers. Convert to visual order first:
from bidi.algorithm import get_display
visual = get_display('תרגול-1 אלגוריתמים')
page.insert_text(
pymupdf.Point(x, y), visual, # visual order, NOT logical
fontfile='C:/Windows/Fonts/tahoma.ttf', fontname='tah', fontsize=6
)Right-align Hebrew text — calculate x from right edge:
def rtl(page, x_right, y, text, fontsize=6, char_width=0.38):
visual = get_display(text)
w = len(text) * fontsize * char_width
page.insert_text(
pymupdf.Point(x_right - w, y), visual,
fontfile='C:/Windows/Fonts/tahoma.ttf', fontname='tah', fontsize=fontsize
)char_width of 0.38 works for Tahoma at small sizes. Verify with a test render for other fonts.
PDF Table Structure Analysis
Map table columns/rows from text coordinates:
blocks = page.get_text('dict')['blocks']
for b in blocks:
if 'lines' not in b:
continue
for line in b['lines']:
for span in line['spans']:
text = span['text'].strip()
bbox = span['bbox'] # (x0, y0, x1, y1)
cx = (bbox[0] + bbox[2]) / 2
# Map cx to column based on header positionsSteps:
- Extract header text positions to find column boundaries
- Assign each data block to a column by x-center
- Map y-positions to row labels using the hour/time column
Enumerating Vector Elements
Use page.get_drawings() to list all vector shapes — useful for identifying which drawings belong to which table area:
for i, d in enumerate(page.get_drawings()):
rect = d.get('rect')
fill = d.get('fill')
if rect:
print(f'[{i}] rect={rect} fill={fill}')Pitfalls
- Redaction kills grid lines. Redrawing a table cell removes the dividers inside it. Redraw them explicitly after redaction.
- Hebrew text reversed without bidi. Always use
get_display()from python-bidi for RTL scripts.insert_htmlboxwithdir="rtl"CSS also fails — it renders LTR. - Font path is OS-specific. Tahoma:
C:/Windows/Fonts/tahoma.ttf(Windows). On Linux/macOS use Noto Sans Hebrew or similar. - Save to same path fails.
doc.save(path)errors if path == the opened file. Use incremental save or open from original source. - Verify with vision_analyze. Text extraction may show different order than visual rendering. Always render a crop and verify for layout-critical edits.
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.

