What I built
A FastAPI service that reads the text layer first and only OCRs scanned pages after cleaning the image, returning text, hOCR or a searchable PDF.
Key features
- POST /extract with page, mode, engine and output options
- Fast path for PDFs that already have a text layer
- Thai/English OCR for scanned pages
- hOCR with coordinates and a searchable PDF
- CLI scripts for n8n’s Execute Command node
Under the hood
- Pages with 200 characters or fewer in the text layer are treated as scans and sent to OCR
- Image clean-up: 300 DPI, deskew, orientation fix, adaptive threshold and table-line removal
- Calls Typhoon OCR 3B on Ollama through its OpenAI-compatible API