Designing an OCR pipeline: from scanned PDF to searchable, chunked text

How to turn a 400-page scanned PDF into text you can search and cite: page batching, concurrency, layout awareness, quality checks, and storing page numbers for citations.

Trophy and certificate after a win
Trophy and certificate after a win

The OCR & Speech Workspace was built to make books searchable — page-batched, concurrent OCR over PDFs, then document-scoped RAG chat with page citations. The OCR model is the easy part. The pipeline around it is what decides whether page 214 is findable six months later.

Split into pages, then batch

Process the PDF page by page and OCR pages in concurrent batches. Per-page processing gives you natural checkpoints (a crash on page 300 does not lose 299 pages), natural citations, and natural parallelism. Tune batch size to the OCR provider's rate limits, and record per-page status so a re-run only touches failures.

Keep the layout, not just the words

Modern OCR returns structure — headings, paragraphs, tables — as markdown or blocks. Preserve it. A table flattened into a paragraph is unsearchable and uncitable. Structure is also what makes chunking for RAG work downstream: heading context travels with each chunk.

Quality checks that catch bad pages

  • Character count far below the document average — a blank or failed page.
  • High ratio of non-dictionary tokens — a rotated or low-resolution scan; re-run with rotation detection.
  • Repeated headers and footers — strip them before chunking or every chunk starts with the book title.
  • Language detection per page for bilingual documents, so the right embedding model is used.

Store for search and for citation

  1. Text per page, with page number and document id.
  2. Chunks with page ranges and heading context, embedded for hybrid retrieval.
  3. A content hash per document so re-uploads do not re-OCR.

What it enables

Once pages are text with metadata, "where does this book discuss X?" becomes a retrieval question with a page-level answer, and citations in RAG answers become links a reader can open. I wrote about the workspace itself in every page and every word, searchable.

OCRPDFDocument AIPipeline
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · Kanpur, Uttar Pradesh, India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU Kanpur) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. Email pranjulrathour41@gmail.com.

Keep reading

More on Vision & speech

All Vision & speech posts →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges.

Pranjul Rathour, GenAI engineer in Kanpur