PDF
Process PDFs locally on macOS with exact extraction, source preservation, deliberate tool routing, and structural plus
semantic validation.
Invariants
- Run extraction and transformations locally. Task-relevant document evidence in tool output and internal agent reports
may be processed by the configured model provider. Require explicit user authorization and an external-disclosure
review before uploading or sending document contents outside that agent workflow. Package and language-data downloads
do not authorize document disclosure.
- Preserve every original PDF byte-for-byte. Write a sibling output, copy, or explicitly named destination unless the
user authorizes destructive replacement.
- Preserve monetary values, identifiers, dates, signs, and displayed precision as strings. Use
decimal.Decimal for
arithmetic; never infer missing rows or silently discard headers, footnotes, continuation lines, or boundary pages.
- Inspect structure and representative renders before choosing a transformation. Use the smallest tool that preserves
the required layout, forms, annotations, and image quality.
- Validate every written PDF structurally and against task semantics. A command exiting successfully is not evidence
that extracted rows, totals, page boundaries, form appearances, or visual layout are correct.
- Keep reports concise for private financial, tax, legal, and health documents. Prefer counts, reconciliations, and
file references over raw sensitive rows unless the rows materially support the task or the user asks for them.
Profile First
Resolve the skill directory from this SKILL.md, then profile every unknown input:
uv run "<skill-dir>/scripts/profile.py" "<input.pdf>"
The helper emits schema-versioned JSON with integrity, encryption, page geometry/rotation, image counts, and per-page
text coverage without document text. Stop on password_required; password handling is outside this skill.
When layout, cropping, OCR quality, signatures, or form placement matters, render the first and last page, every
structural boundary, and any page behind a discrepancy.
Route by Evidence
| Need |
Preferred route |
| Quick reading or page-aware extraction |
Host PDF reader when available, then pdftotext -layout |
| Coordinates, columns, or difficult tables |
Poppler bounding boxes, then pdfplumber through uv run |
| Image-only or materially incomplete text |
OCRmyPDF with Tesseract; default languages eng+ron |
| Merge, split, rotate, or integrity checks |
qpdf |
| Render pages or extract embedded images |
pdftocairo or pdfimages |
| Convert ordered images into a PDF |
img2pdf |
| Reduce size |
qpdf lossless rewrite first; Ghostscript only for an accepted lossy pass |
| Inspect, fill, flatten, or overlay forms |
Read references/forms.md first |
Read references/recipes.md only when exact commands for the selected extraction,
transformation, OCR, image, comparison, or compression branch are needed.
Execute and Reconcile
- Profile inputs and identify whether each page is digital, scanned, mixed, rotated, or image-heavy.
- Extract or transform into a new path. For tabular documents, retain page provenance and parse continuations across
page breaks before assigning rows.
- Reconcile financial and evidentiary output with every available invariant: page and row counts, opening/closing
balances, inflows/outflows, subtotals, displayed totals, date coverage, and source hashes when provenance matters.
- For comparisons, extract both sources independently, enumerate overlapping and unique facts, and render the pages
behind every material disagreement. Distinguish a real discrepancy from an extraction failure.
- For split or rename work, establish an old-to-new map from stable content identifiers. Copy by default, preserve
contextual boundary pages when needed, and verify the first and last page of every result.
- Validate outputs with qpdf, expected page count/dimensions, text coverage, representative renders, and the task's
semantic invariants. Retain OCR sidecars or extraction intermediates only when they are requested or useful evidence.
Completion requires preserved originals, intentional outputs, successful structural checks, semantic reconciliation, and
a concise report of paths and evidence. Lead read-only reports with ### 📄 PDF — 🔎 inspected, no files written; use
### 📄 PDF — ✅ updated only after all required validation passes, and ### 📄 PDF — ⛔ not deliverable when a
required check fails.
1---2name: pdf3description: Use when PDF files are the primary input or output: read, compare, reconcile, extract text/tables/images, OCR scans, fill forms, split, merge, rotate, rename, compress, or convert between PDF and images. Optimized for private financial, tax, legal, and health documents on macOS.4---5
6# PDF
7
8Process PDFs locally on macOS with exact extraction, source preservation, deliberate tool routing, and structural plus
9semantic validation.
10
11## Invariants
12
131. Run extraction and transformations locally. Task-relevant document evidence in tool output and internal agent reports
14 may be processed by the configured model provider. Require explicit user authorization and an external-disclosure
15 review before uploading or sending document contents outside that agent workflow. Package and language-data downloads
16 do not authorize document disclosure.
172. Preserve every original PDF byte-for-byte. Write a sibling output, copy, or explicitly named destination unless the
18 user authorizes destructive replacement.
193. Preserve monetary values, identifiers, dates, signs, and displayed precision as strings. Use `decimal.Decimal` for
20 arithmetic; never infer missing rows or silently discard headers, footnotes, continuation lines, or boundary pages.
214. Inspect structure and representative renders before choosing a transformation. Use the smallest tool that preserves
22 the required layout, forms, annotations, and image quality.
235. Validate every written PDF structurally and against task semantics. A command exiting successfully is not evidence
24 that extracted rows, totals, page boundaries, form appearances, or visual layout are correct.
256. Keep reports concise for private financial, tax, legal, and health documents. Prefer counts, reconciliations, and
26 file references over raw sensitive rows unless the rows materially support the task or the user asks for them.
27
28## Profile First
29
30Resolve the skill directory from this `SKILL.md`, then profile every unknown input:
31
32```sh
33uv run "<skill-dir>/scripts/profile.py" "<input.pdf>"
34```
35
36The helper emits schema-versioned JSON with integrity, encryption, page geometry/rotation, image counts, and per-page
37text coverage without document text. Stop on `password_required`; password handling is outside this skill.
38
39When layout, cropping, OCR quality, signatures, or form placement matters, render the first and last page, every
40structural boundary, and any page behind a discrepancy.
41
42## Route by Evidence
43
44| Need | Preferred route |
45| ----------------------------------------- | ------------------------------------------------------------------------ |
46| Quick reading or page-aware extraction | Host PDF reader when available, then `pdftotext -layout` |
47| Coordinates, columns, or difficult tables | Poppler bounding boxes, then `pdfplumber` through `uv run` |
48| Image-only or materially incomplete text | OCRmyPDF with Tesseract; default languages `eng+ron` |
49| Merge, split, rotate, or integrity checks | qpdf |
50| Render pages or extract embedded images | `pdftocairo` or `pdfimages` |
51| Convert ordered images into a PDF | img2pdf |
52| Reduce size | qpdf lossless rewrite first; Ghostscript only for an accepted lossy pass |
53| Inspect, fill, flatten, or overlay forms | Read [references/forms.md](references/forms.md) first |
54
55Read [references/recipes.md](references/recipes.md) only when exact commands for the selected extraction,
56transformation, OCR, image, comparison, or compression branch are needed.
57
58## Execute and Reconcile
59
601. Profile inputs and identify whether each page is digital, scanned, mixed, rotated, or image-heavy.
612. Extract or transform into a new path. For tabular documents, retain page provenance and parse continuations across
62 page breaks before assigning rows.
633. Reconcile financial and evidentiary output with every available invariant: page and row counts, opening/closing
64 balances, inflows/outflows, subtotals, displayed totals, date coverage, and source hashes when provenance matters.
654. For comparisons, extract both sources independently, enumerate overlapping and unique facts, and render the pages
66 behind every material disagreement. Distinguish a real discrepancy from an extraction failure.
675. For split or rename work, establish an old-to-new map from stable content identifiers. Copy by default, preserve
68 contextual boundary pages when needed, and verify the first and last page of every result.
696. Validate outputs with qpdf, expected page count/dimensions, text coverage, representative renders, and the task's
70 semantic invariants. Retain OCR sidecars or extraction intermediates only when they are requested or useful evidence.
71
72Completion requires preserved originals, intentional outputs, successful structural checks, semantic reconciliation, and
73a concise report of paths and evidence. Lead read-only reports with `### 📄 PDF — 🔎 inspected, no files written`; use
74`### 📄 PDF — ✅ updated` only after all required validation passes, and `### 📄 PDF — ⛔ not deliverable` when a
75required check fails.