root@tr0p:~#Home

OCRack

Translate any PDF with AI. Layout, images and all.

OCRack extracts images, OCRs the text and AI-translates whole PDFs while preserving formatting and positioning. A single terminal pipeline built on PaddleOCR and OpenAI GPT.

  • python3.8+
  • licenseMIT
  • stackPaddleOCR · PyMuPDF · GPT
  • outputlayout-preserving

InstallSource on GitHub

tr0p@kali: ~/apps/OCRack
$ ocrack book.pdf -p "234-235"
[+] analyzing document · 2 pages selected
extract   ████████████ 4 images @ coords
ocr       ████████████ PaddleOCR fallback ok
chunk     ████████████ 18 segments
translate ████████████ gpt-4o-mini
render    ████████████ HTML → PDF

[✓] out/book_translated_20260706.pdf ($0.011)
$ 

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 Tesseract as 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 50

Fast / 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-mini

Translation pipeline

Every PDF flows through the same six deterministic stages, from analysis to a rendered document.

  1. Analyze Parse structure and select pages or chapters.
  2. Extract Pull images with precise page coordinates.
  3. OCR Read text with PaddleOCR, Tesseract fallback.
  4. Chunk Segment text into context-aware pieces.
  5. Translate Send segments to GPT with cost tracking.
  6. Render Compile HTML and print back to PDF.

Numbers

MetricValue
Pages translated per minute1–5
Cost per page (gpt-4o-mini)$0.001+
Cache cost reduction50%
Pipeline stages6

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 chromium for HTML→PDF rendering.
  • Set OPENAI_API_KEY. OPENAI_MODEL defaults to gpt-4o-mini.