|
| 1 | +--- |
| 2 | +name: docling-pdf-extraction |
| 3 | +version: 0.1.0 |
| 4 | +description: > |
| 5 | + Convert PDF documents to markdown, extract images and tables using the docling CLI. |
| 6 | + Use when asked to convert a PDF, extract a datasheet, get images from a PDF, or |
| 7 | + process any document into structured output. Triggers: 'convert pdf', 'pdf to |
| 8 | + markdown', 'extract images from pdf', 'datasheet', 'get tables from pdf', |
| 9 | + 'extract diagrams'. No MCP required — uses docling CLI only. |
| 10 | +entry_point: /docling-pdf |
| 11 | +triggers: |
| 12 | + - convert pdf |
| 13 | + - pdf to markdown |
| 14 | + - extract images |
| 15 | + - extract tables |
| 16 | + - datasheet |
| 17 | + - docling |
| 18 | + - ocr pdf |
| 19 | +--- |
| 20 | + |
| 21 | +# Docling PDF Extraction |
| 22 | + |
| 23 | +Convert PDFs to markdown and structured output using the docling CLI. |
| 24 | +Selects the optimal conversion profile based on document content. |
| 25 | + |
| 26 | +## Step 1 — Verify Installation and Runtime Compatibility |
| 27 | + |
| 28 | +```bash |
| 29 | +which docling && docling --version |
| 30 | +``` |
| 31 | + |
| 32 | +If not found on PATH, also check common install locations — Claude Code's bash |
| 33 | +PATH may differ from the interactive shell: |
| 34 | + |
| 35 | +```bash |
| 36 | +for p in "$HOME/.local/bin/docling" "$HOME/.venvs/docling/bin/docling" \ |
| 37 | + "$(python3 -m site --user-base 2>/dev/null)/bin/docling" \ |
| 38 | + "/opt/homebrew/bin/docling"; do |
| 39 | + [ -x "$p" ] && echo "Found at: $p" && break |
| 40 | +done |
| 41 | +``` |
| 42 | + |
| 43 | +If found at a non-PATH location, use the full path for all `docling` commands, |
| 44 | +or export that directory to PATH for the session. |
| 45 | + |
| 46 | +If not installed: **read `references/installation.md` before proceeding.** |
| 47 | + |
| 48 | +On first use in a session, and after any Docling / `transformers` / `peft` upgrade, |
| 49 | +run the advanced-runtime validation block from `references/installation.md`. |
| 50 | + |
| 51 | +If validation fails: |
| 52 | +- fix the environment before using `vlm` or enrichment-heavy commands |
| 53 | +- fall back to `text`, `scan`, or baseline `rich` without enrichment flags |
| 54 | + |
| 55 | +If the document may need OCR: |
| 56 | +- read `references/profile-scan.md` before running the command |
| 57 | +- be explicit about `--ocr-lang` for the document language; for English-only scans, use `--ocr-lang en` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## Step 2 — Analyze the Document |
| 62 | + |
| 63 | +Before choosing a profile, inspect the document to understand its content type. |
| 64 | + |
| 65 | +**Read `references/document-analysis.md`** to determine: |
| 66 | +- Is text selectable (digital) or bitmapped (scanned)? |
| 67 | +- Are there tables? Images? Diagrams? Charts? Code? Math? |
| 68 | +- Is the layout simple or complex (multi-column, dense mixed content)? |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## Step 3 — Select a Conversion Profile |
| 73 | + |
| 74 | +| Profile | Document Type | Speed / Quality | Reference | |
| 75 | +|---------|--------------|-----------------|-----------| |
| 76 | +| `text` | Digital PDF, prose only, no images needed | Fastest, lowest overhead | `references/profile-text.md` | |
| 77 | +| `scan` | Scanned or photographed, bitmapped text | Slower; OCR-first | `references/profile-scan.md` | |
| 78 | +| `rich` | Datasheet, spec sheet, tables + photographs + diagrams ⭐ | Best default: quick and thorough | `references/profile-rich.md` | |
| 79 | +| `vlm` | Complex layout, dense mixed content, poor standard results | Slowest, highest layout recovery | `references/profile-vlm.md` | |
| 80 | +| `code` | Technical docs with code blocks or math formulas | Moderate cost, structure-focused | `references/profile-code.md` | |
| 81 | + |
| 82 | +**Tie-breaking rules:** |
| 83 | +- Prefer `rich` over `text` — it's a superset with minimal overhead |
| 84 | +- Prefer `rich` over `vlm` — VLM is 3–10× slower; only escalate when standard output is poor |
| 85 | +- Profiles can be combined: `scan` + `rich` flags are additive |
| 86 | + |
| 87 | +### Runtime Guide |
| 88 | + |
| 89 | +Use this rule of thumb when choosing between "usable now" and "best quality later": |
| 90 | + |
| 91 | +| Need | Recommended path | |
| 92 | +|------|------------------| |
| 93 | +| Clean text fast | `text` | |
| 94 | +| Engineering PDF with tables / images, good enough for most agents | baseline `rich` | |
| 95 | +| Scan / photo, readable text first | `scan` | |
| 96 | +| Code / math fidelity matters | `code` | |
| 97 | +| Layout is wrong or content is missing after baseline `rich` / `scan` | `vlm` with `smoldocling` first | |
| 98 | +| Final pass for hardest layouts when runtime is acceptable | `vlm` with `granite_docling` | |
| 99 | + |
| 100 | +Practical timing guidance from local runs: |
| 101 | +- `text`: seconds |
| 102 | +- baseline `rich`: tens of seconds |
| 103 | +- `scan`: tens of seconds to a few minutes |
| 104 | +- `smoldocling`: minutes |
| 105 | +- `granite_docling`: usually the longest path; reserve for cases where the faster paths are not good enough |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## Step 4 — Select Output Format(s) |
| 110 | + |
| 111 | +Output format is independent of conversion profile. Multiple formats can be generated in one run. |
| 112 | + |
| 113 | +| Need | Reference | |
| 114 | +|------|-----------| |
| 115 | +| LLM consumption, reading in editor | `references/output-markdown.md` | |
| 116 | +| Viewing extracted photographs and diagrams | `references/output-images.md` | |
| 117 | +| Working with tables or chart data | `references/output-tables.md` | |
| 118 | +| Structured access, metadata, bounding boxes | `references/output-json.md` | |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Quick Reference |
| 123 | + |
| 124 | +```bash |
| 125 | +# Fastest — clean digital PDF |
| 126 | +docling INPUT.pdf --to md --output ./out --device mps |
| 127 | + |
| 128 | +# Quick, thorough default for engineering PDFs |
| 129 | +docling INPUT.pdf --to md --to json --output ./out \ |
| 130 | + --image-export-mode referenced \ |
| 131 | + --table-mode accurate --device mps |
| 132 | + |
| 133 | +# Slower, richer variant after Step 1 validation passes |
| 134 | +# --enrich-picture-classes --enrich-picture-description --enrich-chart-extraction |
| 135 | + |
| 136 | +# Scanned document: usable OCR text without bloated Markdown |
| 137 | +docling INPUT.pdf --to md --output ./out \ |
| 138 | + --force-ocr --ocr-engine easyocr --ocr-lang en \ |
| 139 | + --image-export-mode placeholder --device mps |
| 140 | + |
| 141 | +# Complex layout rescue: try Smol first, Granite only if needed |
| 142 | +# docling INPUT.pdf --pipeline vlm --vlm-model smoldocling --to md --to json ... |
| 143 | +# docling INPUT.pdf --pipeline vlm --vlm-model granite_docling --to md --to json ... |
| 144 | +``` |
| 145 | + |
| 146 | +For all other cases, follow Steps 1–4 above. |
0 commit comments