Features
Extraction, OCR, smart segmentation and rendering, chained end to end so a translated PDF comes out looking like the original.
- Image extraction and reinsertion
- Figures are pulled out with their coordinates and dropped back into the translated document at the exact same position.
- OCR with fallback
- PaddleOCR is the primary engine with
Tesseractas an offline fallback, so scanned or image-only pages still get read. - Smart chunking
- Intelligent text segmentation keeps translation context tight, improving accuracy on long, structured documents.
- Cost optimization
- Real-time token and cost tracking with OpenAI prompt caching: up to
50%cheaper on repeated content. - Robust and resumable
- Error handling, automatic retries and checkpoint recovery mean a long job survives flaky APIs and picks up where it stopped.
- Rich terminal UI
- A professional
Rich-powered interface shows live progress, chapter detection and per-page cost as it works.
Usage
Generate a pixel-faithful translated PDF, or skip rendering and read the translation straight in your terminal.
PDF mode default
Extract images, translate and re-render into a new layout-preserving PDF next to an HTML twin.
$ ocrack book.pdf -p "234-235"
$ ocrack input.pdf --pages "10-28" -m gpt-4o
$ ocrack input.pdf -c "1,3-5" --max-chunks 50Fast / CLI mode no-render
Skip image extraction or PDF rendering when you just want the translated text quickly and cheaply.
$ ocrack book.pdf -p "234-235" --cli
$ ocrack book.pdf -p "234-235" --no-ocr
$ ocrack book.pdf -o ./out -m gpt-4o-miniTranslation pipeline
Every PDF flows through the same six deterministic stages, from analysis to a rendered document.
- Analyze Parse structure and select pages or chapters.
- Extract Pull images with precise page coordinates.
- OCR Read text with PaddleOCR, Tesseract fallback.
- Chunk Segment text into context-aware pieces.
- Translate Send segments to GPT with cost tracking.
- Render Compile HTML and print back to PDF.
Numbers
| Metric | Value |
|---|---|
| Pages translated per minute | 1–5 |
| Cost per page (gpt-4o-mini) | $0.001+ |
| Cache cost reduction | 50% |
| Pipeline stages | 6 |
Install
Clone, install and you get the ocrack console command.
$ git clone https://github.com/marcostolosa/OCRack.git && cd OCRack && pip install -e .- Requires Python 3.8+ and an OpenAI API key.
- Run
playwright install chromiumfor HTML→PDF rendering. - Set
OPENAI_API_KEY.OPENAI_MODELdefaults to gpt-4o-mini.
Links
Translate the books the tools skip. Star it on GitHub, file an issue, or send a pull request.