# Multi-Page PDF + OCR Pattern — Session 2026-05-10

## Problem
PDF with mixed content: Page 1 = text-based (Docling extracts correctly), Page 2 = scanned images (Docling skips entirely, returns only `<!-- image -->` placeholders).

## Solution
1. Split PDF into individual pages using PyMuPDF (fitz)
2. Render each page as PNG at 300 DPI
3. Process image pages with Docling (OCR triggered automatically on images)

## Code Pattern
```python
import fitz
from docling.document_converter import DocumentConverter

pdf_path = "document.pdf"
doc = fitz.open(pdf_path)

for page_idx in range(len(doc)):
    page = doc[page_idx]
    pix = page.get_pixmap(dpi=300)
    pix.save(f"/tmp/page_{page_idx+1}.png")

doc.close()

converter = DocumentConverter()
result = converter.convert("/tmp/page_2.png")
print(result.document.export_to_markdown())
```

## Install Dependencies
```bash
cd /home/agent/.hermes/hermes-agent && uv pip install pymupdf docling
```

## Key Observations
- Docling on PDFs = text extraction only (no OCR on image pages)
- Docling on PNGs = automatic OCR
- 300 DPI is the sweet spot for OCR quality
- PyMuPDF (fitz) must be installed via `uv pip install pymupdf` (lowercase)
