agentleFS
mikel-codemikel-code/claude-skills/pdf-to-markdown/SKILL.md

pdf-to-markdown

Skill0 starsChanged 3 months agoMITView on GitHub

Convert a PDF into OKF-frontmatter markdown through a tiered, correctness-first pipeline: local structure extraction (pdf-inspector, docling for table-heavy docs), OCR for scanned pages (ocrmypdf), cross-engine verification (poppler), and Claude-vision escalation for pages the tools can't resolve. Use for /pdf-to-markdown, \"convert this PDF to markdown\", \"extract the text/tables from this PDF\", or \"turn this paper/report into markdown\". Non-PDF office documents belong to the doc-to-markdown skill instead.

  • Installs packages

18 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do the tier-3 workflow below, then deliver.

    line 47
  2. Very specific:

    Read the listed pages of the source PDF directly with the Read tool (pages parameter.

    line 58
  3. Very specific:

    Run pdf_to_markdown.py --reconcile <out.md> — it re-derives the report statuses from the markdown's own markers (placeholder gone + vision …

    line 69
  4. Very specific:

    If the user asked for --no-vision (or offline), skip all of this and tell them which pages are unresolved and why.

    line 81

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

pdf-to-markdown

Deterministic, script-driven PDF conversion with a per-page audit trail. The script does the tiered work (triage → extract → OCR → verify); you are tier 3 — the script hands you exactly the pages it could not resolve, and you transcribe them visually. references/design.md records the full design and its rationale; read it before changing anything.

Convert

uv run <skill-dir>/scripts/pdf_to_markdown.py <file.pdf> [-o out.md] [--output-dir DIR]
#   --json           print the machine-readable report to stdout
#   --no-vision      fully local: flagged pages stay unresolved, no vision step
#   --verify         request a vision spot-check of unflagged pages too
#   -l eng+spa       OCR languages (tesseract codes)
#   --images         export figure images to <out>.assets/ and reference
#                    them (docling route; icons filtered by size)

The markdown carries an invisible <!-- p.N --> anchor at every page boundary — use it to locate a page when reviewing or citing. Deterministic repair passes run before verification and are recorded per page in the report's tier_history (repair:reversal(n) — word-order fixed against the poppler reference; repair:debris(n) — OCR noise lines removed from photo pages).

Outputs <stem>.md (OKF v0.2 frontmatter + content) and <stem>.report.json (per-page status: every page is accounted for — nothing is ever silently dropped).

Exit codes → what you do next

  • 0 — clean. Every page extracted; born-digital pages cross-verified against a second engine. Caveat: OCR'd pages pass verification tautologically (both engines read the same tesseract output), so for documents where correctness is critical, offer the user --verify. Deliver the file.
  • 4 — converted, but pages need vision (report.vision.pending_pages). Do the tier-3 workflow below, then deliver.
  • 2 — missing Homebrew dependency; stderr names the brew install fix.
  • 1 — unexpected failure; read stderr, don't retry blindly.

Tier-3 workflow (you, on exit 4)

On exit 4 the command's own output ends with an ACTION REQUIRED block listing the flagged pages, their reasons, and these exact steps — you never need to open or parse <stem>.report.json (it exists as the provenance artifact, nothing more).

  1. Read the listed pages of the source PDF directly with the Read tool (pages parameter; ≤20 pages per request) — you get text + page image.
  2. In the markdown file, replace each <!-- page N: flagged (…) — awaiting vision transcription --> placeholder with your transcription of that page, headed by the label <!-- page N: transcribed by vision -->. If partial extractor output follows the placeholder, use it as a hint but trust the page image.
  3. Numeric tables: cross-foot before accepting. Vision transcription fails silently (plausible wrong values) — check totals/sums where the table implies them; if a figure is illegible, write [illegible] rather than a guess.
  4. Run pdf_to_markdown.py --reconcile <out.md> — it re-derives the report statuses from the markdown's own markers (placeholder gone + vision label present ⇒ vision) and exits 0 when every page is resolved. Never edit the report JSON by hand.

With --verify, additionally sample 2–3 unflagged pages, Read them, and compare against the markdown; report discrepancies to the user rather than silently patching them. Prioritize "ocr" pages and pages with recall: null in the report — those are exactly the ones the automatic cross-check cannot really vouch for (OCR verification is tautological: both engines read the same tesseract text layer).

If the user asked for --no-vision (or offline), skip all of this and tell them which pages are unresolved and why.

Routing (informational)

Triage picks the extractor per document: pdf-inspector by default; docling when layout is complex or table-heavy (better table structure, slower, model-based). Scanned/garbled pages get one ocrmypdf pass whose mode is chosen by reason code (--skip-text / --redo-ocr / --force-ocr — see design.md for why garbled-text pages must use force). Every page's markdown is then cross-checked against poppler's independent extraction; low recall flags the page rather than trusting either engine.

Troubleshooting

  • "missing dependencies" (exit 2) → run the printed brew install lines.
  • First run is slow / downloads models → docling fetching weights; one-time, cached under ~/.cache.
  • Wrong language OCR → pass -l with the right tesseract codes (needs tesseract-lang for non-English).
  • Report says low_recall on a page that looks fine → the verifier is conservative by design; Read the page, confirm visually, and if the markdown is actually complete just note it in the report (status stays auditable either way).
  • word_order reason → tokens are all present but their order is corrupted beyond automatic repair (scrambled TOC columns, shuffled table cells). Vision-transcribe the page; pay attention to reading order.
  • ocr_debris reason → an OCR pass over a decorative/photo page left mostly noise; transcribe visually what real text the page carries (often just a chapter title).
  • Encrypted PDF → not supported; ask the user for a decrypted copy.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.