How PDF classification works in pdf-inspector
mainClassification works by parsing the xref table and page tree without loading the full document. It samples content streams looking for text operators (Tj/TJ) and image operators (Do).
This allows for extremely fast detection (~10-50ms) and provides a pages_needing_ocr list, which allows callers to route only specific pages to an OCR service instead of the whole document.
Scan Strategies
| Strategy | Behavior | Best for |
|---|---|---|
EarlyExit (default) | Scan all pages, stop on first non-text page | Pipelines routing TextBased PDFs to fast extraction |
Full | Scan all pages, no early exit | Accurate Mixed vs Scanned classification |
Sample(n) | Sample n evenly distributed pages | Very large PDFs where speed matters more than precision |
Pages(vec) | Only scan specific 1-indexed page numbers | When the caller knows which pages to check |