{“content”:”---\nname: ocr-and-documents\ndescription: Extract 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.\nversion: 2.3.0\nauthor: Hermes Agent\nlicense: MIT\nmetadata:\n hermes:\n tags: [PDF, Documents, Research, Arxiv, Text-Extraction, OCR]\n related_skills: [powerpoint]\n---\n\n# PDF & Document Extraction\n\nFor DOCX: use python-docx (parses actual document structure, far better than OCR).\nFor PPTX: see the powerpoint skill (uses python-pptx with full slide/notes support).\nThis skill covers PDFs and scanned documents.\n\n## Step 1: Remote URL Available?\n\nIf the document has a URL, always try web_extract first:\n\n\nweb_extract(urls=[\"https://arxiv.org/pdf/2402.03300\"])\nweb_extract(urls=[\"https://example.com/report.pdf\"])\n\n\nThis handles PDF-to-markdown conversion via Firecrawl with no local dependencies.\n\nOnly use local extraction when: the file is local, web_extract fails, or you need batch processing.\n\n## Step 2: Choose Local Extractor\n\n| Feature | pymupdf (~25MB) | marker-pdf (~3-5GB) |\n|---------|-----------------|---------------------|\n| Text-based PDF | ✅ | ✅ |\n| Scanned PDF (OCR) | ❌ | ✅ (90+ languages) |\n| Tables | ✅ (basic) | ✅ (high accuracy) |\n| Equations / LaTeX | ❌ | ✅ |\n| Code blocks | ❌ | ✅ |\n| Forms | ❌ | ✅ |\n| Headers/footers removal | ❌ | ✅ |\n| Reading order detection | ❌ | ✅ |\n| Images extraction | ✅ (embedded) | ✅ (with context) |\n| Images → text (OCR) | ❌ | ✅ |\n| EPUB | ✅ | ✅ |\n| Markdown output | ✅ (via pymupdf4llm) | ✅ (native, higher quality) |\n| Install size | ~25MB | ~3-5GB (PyTorch + models) |\n| Speed | Instant | ~1-14s/page (CPU), ~0.2s/page (GPU) |\n\nDecision: Use pymupdf unless you need OCR, equations, forms, or complex layout analysis.\n\nIf the user needs marker capabilities but the system lacks ~5GB free disk:\n> “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.”\n\n---\n\n## pymupdf (lightweight)\n\nbash\npip install pymupdf pymupdf4llm\n\n\nVia helper script:\nbash\npython scripts/extract_pymupdf.py document.pdf # Plain text\npython scripts/extract_pymupdf.py document.pdf --markdown # Markdown\npython scripts/extract_pymupdf.py document.pdf --tables # Tables\npython scripts/extract_pymupdf.py document.pdf --images out/ # Extract images\npython scripts/extract_pymupdf.py document.pdf --metadata # Title, author, pages\npython scripts/extract_pymupdf.py document.pdf --pages 0-4 # Specific pages\n\n\nInline:\nbash\npython3 -c \"\nimport pymupdf\ndoc = pymupdf.open('document.pdf')\nfor page in doc:\n print(page.get_text())\n\"\n\n\n---\n\n## marker-pdf (high-quality OCR)\n\nbash\n# Check disk space first\npython scripts/extract_marker.py --check\n\npip install marker-pdf\n\n\nVia helper script:\nbash\npython scripts/extract_marker.py document.pdf # Markdown\npython scripts/extract_marker.py document.pdf --json # JSON with metadata\npython scripts/extract_marker.py document.pdf --output_dir out/ # Save images\npython scripts/extract_marker.py scanned.pdf # Scanned PDF (OCR)\npython scripts/extract_marker.py document.pdf --use_llm # LLM-boosted accuracy\n\n\nCLI (installed with marker-pdf):\nbash\nmarker_single document.pdf --output_dir ./output\nmarker /path/to/folder --workers 4 # Batch\n\n\n---\n\n## Arxiv Papers\n\n\n# Abstract only (fast)\nweb_extract(urls=[\"https://arxiv.org/abs/2402.03300\"])\n\n# Full paper\nweb_extract(urls=[\"https://arxiv.org/pdf/2402.03300\"])\n\n# Search\nweb_search(query=\"arxiv GRPO reinforcement learning 2026\")\n\n\n## Split, Merge & Search\n\npymupdf handles these natively — use execute_code or inline Python:\n\npython\n# Split: extract pages 1-5 to a new PDF\nimport pymupdf\ndoc = pymupdf.open(\"report.pdf\")\nnew = pymupdf.open()\nfor i in range(5):\n new.insert_pdf(doc, from_page=i, to_page=i)\nnew.save(\"pages_1-5.pdf\")\n\n\npython\n# Merge multiple PDFs\nimport pymupdf\nresult = pymupdf.open()\nfor path in [\"a.pdf\", \"b.pdf\", \"c.pdf\"]:\n result.insert_pdf(pymupdf.open(path))\nresult.save(\"merged.pdf\")\n\n\npython\n# Search for text across all pages\nimport pymupdf\ndoc = pymupdf.open(\"report.pdf\")\nfor i, page in enumerate(doc):\n results = page.search_for(\"revenue\")\n if results:\n print(f\"Page {i+1}: {len(results)} match(es)\")\n print(page.get_text(\"text\"))\n\n\nNo extra dependencies needed — pymupdf covers split, merge, search, and text extraction in one package.\n\n---\n\n## Notes\n\n- web_extract is always first choice for URLs\n- pymupdf is the safe default — instant, no models, works everywhere\n- marker-pdf is for OCR, scanned docs, equations, complex layouts — install only when needed\n- Both helper scripts accept --help for full usage\n- marker-pdf downloads ~2.5GB of models to ~/.cache/huggingface/ on first use\n- For Word docs: pip install python-docx (better than OCR — parses actual structure)\n- For PowerPoint: see the powerpoint skill (uses python-pptx)\n”}