$npx -y skills add adityahimaone/hermes-agent-rtk-caveman --skill ocr-and-documentsExtract text from PDFs and scanned documents. Use web_extract for remote URLs, pymupdf for local text-based PDFs, marker-pdf for OCR/scanned docs. For DOCX use python-docx, for PPTX see the powerpoint skill.
| 1 | # PDF & Document Extraction |
| 2 | |
| 3 | For DOCX: use `python-docx` (parses actual document structure, far better than OCR). |
| 4 | For PPTX: see the `powerpoint` skill (uses `python-pptx` with full slide/notes support). |
| 5 | This skill covers **PDFs and scanned documents**. |
| 6 | |
| 7 | ## Step 1: Remote URL Available? |
| 8 | |
| 9 | If the document has a URL, **always try `web_extract` first**: |
| 10 | |
| 11 | ``` |
| 12 | web_extract(urls=["https://arxiv.org/pdf/2402.03300"]) |
| 13 | web_extract(urls=["https://example.com/report.pdf"]) |
| 14 | ``` |
| 15 | |
| 16 | This handles PDF-to-markdown conversion via Firecrawl with no local dependencies. |
| 17 | |
| 18 | Only use local extraction when: the file is local, web_extract fails, or you need batch processing. |
| 19 | |
| 20 | ## Step 2: Choose Local Extractor |
| 21 | |
| 22 | | Feature | pymupdf (~25MB) | marker-pdf (~3-5GB) | |
| 23 | |---------|-----------------|---------------------| |
| 24 | | **Text-based PDF** | ✅ | ✅ | |
| 25 | | **Scanned PDF (OCR)** | ❌ | ✅ (90+ languages) | |
| 26 | | **Tables** | ✅ (basic) | ✅ (high accuracy) | |
| 27 | | **Equations / LaTeX** | ❌ | ✅ | |
| 28 | | **Code blocks** | ❌ | ✅ | |
| 29 | | **Forms** | ❌ | ✅ | |
| 30 | | **Headers/footers removal** | ❌ | ✅ | |
| 31 | | **Reading order detection** | ❌ | ✅ | |
| 32 | | **Images extraction** | ✅ (embedded) | ✅ (with context) | |
| 33 | | **Images → text (OCR)** | ❌ | ✅ | |
| 34 | | **EPUB** | ✅ | ✅ | |
| 35 | | **Markdown output** | ✅ (via pymupdf4llm) | ✅ (native, higher quality) | |
| 36 | | **Install size** | ~25MB | ~3-5GB (PyTorch + models) | |
| 37 | | **Speed** | Instant | ~1-14s/page (CPU), ~0.2s/page (GPU) | |
| 38 | |
| 39 | **Decision**: Use pymupdf unless you need OCR, equations, forms, or complex layout analysis. |
| 40 | |
| 41 | If the user needs marker capabilities but the system lacks ~5GB free disk: |
| 42 | > "This document needs OCR/advanced extraction (marker-pdf), which requires ~5GB for PyTorch and models. Your system has [X]GB free. Options: free up space, provide a URL so I can use web_extract, or I can try pymupdf which works for text-based PDFs but not scanned documents or equations." |
| 43 | |
| 44 | --- |
| 45 | |
| 46 | ## pymupdf (lightweight) |
| 47 | |
| 48 | ```bash |
| 49 | pip install pymupdf pymupdf4llm |
| 50 | ``` |
| 51 | |
| 52 | **Via helper script**: |
| 53 | ```bash |
| 54 | python scripts/extract_pymupdf.py document.pdf # Plain text |
| 55 | python scripts/extract_pymupdf.py document.pdf --markdown # Markdown |
| 56 | python scripts/extract_pymupdf.py document.pdf --tables # Tables |
| 57 | python scripts/extract_pymupdf.py document.pdf --images out/ # Extract images |
| 58 | python scripts/extract_pymupdf.py document.pdf --metadata # Title, author, pages |
| 59 | python scripts/extract_pymupdf.py document.pdf --pages 0-4 # Specific pages |
| 60 | ``` |
| 61 | |
| 62 | **Inline**: |
| 63 | ```bash |
| 64 | python3 -c " |
| 65 | import pymupdf |
| 66 | doc = pymupdf.open('document.pdf') |
| 67 | for page in doc: |
| 68 | print(page.get_text()) |
| 69 | " |
| 70 | ``` |
| 71 | |
| 72 | --- |
| 73 | |
| 74 | ## marker-pdf (high-quality OCR) |
| 75 | |
| 76 | ```bash |
| 77 | # Check disk space first |
| 78 | python scripts/extract_marker.py --check |
| 79 | |
| 80 | pip install marker-pdf |
| 81 | ``` |
| 82 | |
| 83 | **Via helper script**: |
| 84 | ```bash |
| 85 | python scripts/extract_marker.py document.pdf # Markdown |
| 86 | python scripts/extract_marker.py document.pdf --json # JSON with metadata |
| 87 | python scripts/extract_marker.py document.pdf --output_dir out/ # Save images |
| 88 | python scripts/extract_marker.py scanned.pdf # Scanned PDF (OCR) |
| 89 | python scripts/extract_marker.py document.pdf --use_llm # LLM-boosted accuracy |
| 90 | ``` |
| 91 | |
| 92 | **CLI** (installed with marker-pdf): |
| 93 | ```bash |
| 94 | marker_single document.pdf --output_dir ./output |
| 95 | marker /path/to/folder --workers 4 # Batch |
| 96 | ``` |
| 97 | |
| 98 | --- |
| 99 | |
| 100 | ## Arxiv Papers |
| 101 | |
| 102 | ``` |
| 103 | # Abstract only (fast) |
| 104 | web_extract(urls=["https://arxiv.org/abs/2402.03300"]) |
| 105 | |
| 106 | # Full paper |
| 107 | web_extract(urls=["https://arxiv.org/pdf/2402.03300"]) |
| 108 | |
| 109 | # Search |
| 110 | web_search(query="arxiv GRPO reinforcement learning 2026") |
| 111 | ``` |
| 112 | |
| 113 | ## Split, Merge & Search |
| 114 | |
| 115 | pymupdf handles these natively — use `execute_code` or inline Python: |
| 116 | |
| 117 | ```python |
| 118 | # Split: extract pages 1-5 to a new PDF |
| 119 | import pymupdf |
| 120 | doc = pymupdf.open("report.pdf") |
| 121 | new = pymupdf.open() |
| 122 | for i in range(5): |
| 123 | new.insert_pdf(doc, from_page=i, to_page=i) |
| 124 | new.save("pages_1-5.pdf") |
| 125 | ``` |
| 126 | |
| 127 | ```python |
| 128 | # Merge multiple PDFs |
| 129 | import pymupdf |
| 130 | result = pymupdf.open() |
| 131 | for path in ["a.pdf", "b.pdf", "c.pdf"]: |
| 132 | result.insert_pdf(pymupdf.open(path)) |
| 133 | result.save("merged.pdf") |
| 134 | ``` |
| 135 | |
| 136 | ```python |
| 137 | # Search for text across all pages |
| 138 | import pymupdf |
| 139 | doc = pymupdf.open("report.pdf") |
| 140 | for i, page in enumerate(doc): |
| 141 | results = page.search_for("revenue") |
| 142 | if results: |
| 143 | print(f"Page {i+1}: {len(results)} match(es)") |
| 144 | print(page.get_text("text")) |
| 145 | ``` |
| 146 | |
| 147 | No extra dependencies needed — pymupdf covers split, merge, search, and text extraction in one package. |
| 148 | |
| 149 | --- |
| 150 | |
| 151 | ## Notes |
| 152 | |
| 153 | - `web_extract` is always first choice for URLs |
| 154 | - pymupdf is the safe default — instant, no models, works everywhere |
| 155 | - marker-pdf is for OCR, scanned docs, |