Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“„ PDF OCR Text Extractor

High-quality text extraction from scanned PDFs with Persian/Arabic (RTL) support.

This project provides a powerful Python script that extracts text from PDFs โ€” especially scanned or image-based documents โ€” using Tesseract OCR, advanced image preprocessing, and robust text-cleaning tailored for Persian/Arabic languages.
It outputs both clean UTF-8 text and HTML with proper RTL support.


โœจ Features

๐Ÿ” OCR Extraction

  • Works with scanned PDFs
  • Supports Farsi, Arabic, and English
  • Runs multiple OCR configurations and selects the best output

๐Ÿ–ผ Advanced Preprocessing

  • Uses OpenCV (if available):
    • Adaptive thresholding
    • Noise reduction
    • Morphological cleanup
  • Uses Pillow fallback when OpenCV is not installed

๐Ÿ‡ฎ๐Ÿ‡ท RTL Persian/Arabic Handling

  • Auto-detects Persian text
  • Normalizes common OCR mistakes
  • Fixes diacritics, punctuation, and spacing
  • Converts digits contextually
  • Uses arabic-reshaper + bidi for correct display

๐Ÿ“ Output Formats

  • extracted_text_clean.txt
  • extracted_text_clean.html
  • Page-separated output

๐Ÿ“ฆ Requirements

Install Python Dependencies

pip install pytesseract PyMuPDF Pillow opencv-python arabic-reshaper python-bidi numpy

Install Tesseract OCR

Windows: https://github.com/UB-Mannheim/tesseract/wiki

Ubuntu :

sudo apt-get install tesseract-ocr tesseract-ocr-fas

MacOs:

brew install tesseract
brew install tesseract-lang

Usage

Place the PDF into the same directory and name it: Sample.pdf

Run:

python pdf_ocr.py

About

This script performs OCR on a PDF file with scanned images using tessaract.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages