How does OCR work step by step? OCR models, offline use, libraries, training, PDFs

What OCR scanning is, how OCR works step by step, how OCR models read text, offline OCR, the best libraries, better results, training and OCR PDFs.

Pranjul Rathour, GenAI engineer, India
Pranjul Rathour, GenAI engineer, India

Key takeaways

  • OCR turns images of text into machine-readable text through preprocessing, text detection, recognition and post-processing.
  • Modern OCR models use neural networks: a detector finds text regions and a recogniser reads character sequences.
  • OCR works offline with Tesseract, PaddleOCR, EasyOCR and Google ML Kit's on-device recogniser.
  • Better scans give better OCR: around 300 DPI, even lighting, flat pages, straight alignment and high contrast.
  • OCRmyPDF adds a searchable text layer to scanned PDFs for free.

OCR, optical character recognition, works in steps: the image is cleaned up, text regions are detected, each line or word is read by a recognition model, and the output is corrected and assembled into text with its layout. The result is searchable, editable text from scans, photos and PDFs. I use OCR in the OCR and Speech Workspace and DocuLens AI, so this page covers OCR scanning, each step, how models work, offline use, the best libraries, improving results, training a model and making OCR PDFs.

What is OCR scanning?

OCR scanning means scanning a document or photographing it and running optical character recognition so the text becomes machine-readable, rather than just a picture of text. You can then search, copy, edit and index it.

Many scanners and phone apps run OCR automatically and produce searchable PDFs. Uses include digitising records, extracting data from invoices and forms, making books searchable, reading receipts in expense apps and making documents accessible to screen readers. Without OCR, a scanned PDF is just images: you cannot search it or select its text, and AI tools cannot read it reliably.

How does OCR work step by step?

OCR follows a pipeline: capture the image, preprocess it, detect text regions, recognise characters and words, then post-process and reconstruct layout.

Steps in detail:

  • Capture: scan or photograph the document.
  • Preprocess: convert to greyscale, remove noise, fix skew and adjust contrast.
  • Layout analysis: find blocks, columns, lines, tables and reading order.
  • Detection: locate words or lines of text.
  • Recognition: convert each text image into characters with a neural model.
  • Post-processing: apply dictionaries or language models to fix errors.
  • Output: plain text, structured data, or a PDF with a hidden text layer.

Each step's quality affects the next, so preprocessing often matters most.

How do OCR models work?

Modern OCR models use deep learning: a detection network finds where text is, and a recognition network reads the cropped text as a sequence. Classic recognisers combine convolutional networks for visual features with recurrent layers and CTC loss to output character sequences.

Newer recognisers use transformers, such as TrOCR, treating OCR like translation from image to text. Vision language models go further, reading whole pages, understanding layout and tables, and returning structured output like Markdown. They handle complex documents better but cost more and can occasionally hallucinate text, so validate outputs. For scanned PDFs, the OCR and Speech Workspace uses Mistral's OCR model in page batches for layout-aware text.

Does OCR work offline?

Yes. Many OCR tools run entirely on your device: Tesseract on desktops and servers, PaddleOCR and EasyOCR in Python, Google's ML Kit on Android and iOS, Apple's Live Text on Apple devices, and Tesseract.js in browsers.

Offline OCR protects privacy, since documents never leave your machine, works without internet, and has no per-page cost. Cloud OCR services and vision language models often give better accuracy on complex layouts, handwriting and poor scans, but require sending data to a provider. Choose based on document sensitivity, accuracy needs and volume.

Which OCR library is best?

It depends on the documents. Tesseract is a solid free choice for clean printed text; PaddleOCR is strong for photos, complex layouts and Asian scripts; EasyOCR is simple for scene text; and vision language model OCR leads on complex documents.

How to choose:

  • Clean scans, many languages, CPU only: Tesseract.
  • Photos, receipts, signboards: PaddleOCR or EasyOCR.
  • Tables, forms, mixed layouts: layout-aware OCR or vision language models.
  • Mobile apps: Google ML Kit or Apple's Vision framework.

Always benchmark on 50 to 100 of your own documents, measuring character or field accuracy, before committing.

What is the best OCR library for Python?

Popular Python options are pytesseract, a wrapper for Tesseract; EasyOCR, simple and deep-learning based; PaddleOCR, accurate with layout tools; docTR, with good detection and recognition models; and newer document OCR toolkits for layout and tables.

Also asked as: best ocr library python

Start with pytesseract for clean documents because it is lightweight and fast on CPUs. Move to PaddleOCR or EasyOCR for photos and difficult images, ideally with a GPU. For PDFs with tables and structure, try layout-aware tools or a vision language model API. Combine OCR with OpenCV preprocessing for better results on noisy images.

Is there a free OCR library for Android?

Yes. Google's ML Kit Text Recognition is free and runs on the device, supporting Latin, Devanagari, Chinese, Japanese and Korean scripts. Tesseract is also available on Android through community libraries such as Tesseract4Android.

Also asked as: is there any free ocr library for android

ML Kit is usually the easiest and fastest choice: add the dependency, pass a camera frame or image, and receive text blocks, lines and elements with bounding boxes. Tesseract offers more language coverage and control but needs language data files and more setup. For Java or Kotlin apps, both integrate well; test accuracy and speed on low-end devices your users actually have.

How do I improve OCR scanning results?

Improve the input first: scan at around 300 DPI, use even lighting without shadows, keep pages flat and straight, and choose greyscale or colour with good contrast. Then preprocess: deskew, denoise, binarise and crop margins.

Also asked as: how to improve ocr (scanning) results

More tips:

  • Set the correct language or languages in your OCR tool.
  • Choose the right page segmentation mode for single lines or blocks.
  • Remove backgrounds and watermarks where possible.
  • Split multi-column pages before recognition.
  • Use a dictionary or validation rules for fields like dates and IDs.
  • Try a stronger model for handwriting or complex layouts.

Measure accuracy on a sample before and after each change.

How do I train an OCR model?

For Tesseract, fine-tune an existing language model with its tesstrain tools using line images and matching text. For deep learning OCR, fine-tune a pretrained recogniser such as TrOCR or a PaddleOCR model on labelled crops of your text.

Also asked as: how to train a ocr model

Steps:

  • Collect real samples and transcribe them accurately.
  • Add synthetic data by rendering text in fonts and backgrounds like your documents.
  • Split data into training, validation and test sets.
  • Fine-tune from a pretrained model rather than training from scratch.
  • Measure character error rate on the test set.

Fine-tuning works well for specific fonts, forms or handwriting styles; general OCR is better left to existing models.

How do I make an OCR PDF?

Use OCRmyPDF, a free command-line tool built on Tesseract, to add a searchable text layer to scanned PDFs: ocrmypdf input.pdf output.pdf. Adobe Acrobat and many scanner apps also create searchable PDFs.

Also asked as: how to make ocr pdf

OCRmyPDF keeps the original page images and places invisible text underneath, so the PDF looks the same but becomes searchable and selectable. Add -l eng+hin for multiple languages, --deskew to straighten pages and --skip-text to skip pages that already have text. Searchable PDFs are also much better inputs for RAG systems, which need real text to retrieve from.

Sources

  1. Tesseract OCR, documentationtesseract-ocr.github.io
  2. Google ML Kit, Text recognition v2developers.google.com
  3. OCRmyPDF, repositorygithub.com
  4. PaddleOCR, repositorygithub.com
  5. Shi, Bai & Yao, An End-to-End Trainable Neural Network for Image-based Sequence Recognition (CRNN, 2015)arxiv.org
  6. Li et al., TrOCR: Transformer-based Optical Character Recognition (2021)arxiv.org
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · 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) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on Vision, speech & OCR

All Vision, speech & OCR guides →
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. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India