Skip to main content
KrutiExtract Logo

KrutiExtract

A Universal Legacy Hindi PDF to Markdown Extractor

Python Version License: MIT Maintenance


Extracting legacy Hindi fonts (like KrutiDev, Devlys, or Chanakya) from PDF documents has traditionally been a nightmare. Standard OCR and PDF text extractors read characters based on visual coordinates. Because Hindi matras (vowel marks like ि or े) overlap with consonants, this visual sorting scrambles the text (e.g., typing vkSj for 'और' gets extracted as vkjS, breaking the conversion into the nonsense word 'आरै').

KrutiExtract solves this problem by bypassing visual coordinate sorting and extracting the logical character stream directly from the PDF.

✨ Core Features

  • Perfect Character Order: Preserves the original typist's keystrokes, completely avoiding spatial scrambling of matras.
  • Smart Auto-Detect Engine: Automatically mathematically calculates text frequencies to detect whether the typist used KrutiDev / Devlys or Chanakya, instantly routing the text to the correct translation engine!
  • English / Hinglish Bypass Mode: If the engine detects that the document contains modern Unicode Hindi, standard English, or Hinglish, it automatically bypasses legacy conversion entirely—perfectly preserving your modern texts!
  • Dynamic English Preservation: Uses NLTK's English corpus to proactively detect and protect English words, numbers, acronyms, and HTML tags interspersed within mixed-font Hindi texts.
  • Collision-Free Safe-Tokens: Markdown syntax elements (like # or *) clash with KrutiDev maps. KrutiExtract shields these structural elements using a unique $$$INDEX$$$ safe-token system during font conversion.

👁️ Advanced OCR & Image Cleaning

When the toolkit encounters text trapped inside a scanned image, it seamlessly hands it over to Tesseract OCR in the background.

  • Native Hindi OCR: The toolkit hardcodes ocr_language="hin" into the internal pipeline. This permanently stops Tesseract from trying to hallucinate English letters onto Hindi image shapes, ensuring natively output Unicode Devanagari.
  • OpenCV Image Cleaning (--enhance-ocr): Pass this flag to activate our built-in computer vision pipeline. The toolkit will automatically intercept blurry images in the PDF, upscale the resolution, apply unsharp masking, and run adaptive thresholding to perfectly reconstruct the text shapes before OCR scans it!

🚀 Installation

Ensure you have Python 3.8+ installed.

# Clone the repository
git clone https://github.com/epicbharat/krutiextract.git
cd krutiextract

# Create and activate a virtual environment (Recommended)
python -m venv venv
venv\Scripts\activate  # On Windows
# source venv/bin/activate  # On macOS/Linux

# Install dependencies
pip install -r requirements.txt

# Download the required NLTK English word corpus
python -c "import nltk; nltk.download('words')"

Note on Tesseract (Required for OCR)

If you are parsing scanned PDFs or PDFs with embedded images, you must have Tesseract OCR installed on your system.

  • Windows: Download the installer and ensure you check the "Hindi" language pack during installation. Add Tesseract to your PATH.
  • Linux: sudo apt-get install tesseract-ocr tesseract-ocr-hin

💻 CLI Usage Guide

KrutiExtract provides a powerful Command Line Interface (CLI).

1. Process a Single File

python -m src.cli --input "path/to/document.pdf" --output "path/to/output.md"

2. Batch Process a Directory

Recursively process an entire folder of PDFs:

python -m src.cli --dir "path/to/pdf/folder" --out-dir "path/to/markdown/folder"

3. Force a Specific Font Encoding

By default, the font is set to auto. You can force a specific bypass or mapping:

# Available options: krutidev, chanakya, auto, unicode, english
python -m src.cli --input "doc.pdf" --font chanakya

4. Enable OpenCV OCR Enhancement

Use this flag for old, blurry, or low-resolution scanned PDFs to artificially sharpen the text before extraction:

python -m src.cli --input "blurry_scan.pdf" --enhance-ocr

🤝 Contributing

Contributions are welcome! If you find a PDF that breaks the extraction logic or a rare character combination we missed, please open an issue and attach the sample PDF.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Author: Bharat Choudhary (Lecturer, Department of Secondary Education, Govt. of Rajasthan)
Email: epicbharat@gmail.com
GitHub: https://github.com/epicbharat

Metadata

Release files for krutiextract 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for krutiextract 1.0.0
File Size Uploaded
krutiextract-1.0.0.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for krutiextract 1.0.0
File Interpreter ABI Platform
krutiextract-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.3 kB

Release files / krutiextract-1.0.0.tar.gz

Download URL krutiextract-1.0.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bd85c6dbe233abe6403455fbdfc09edf72dd6d476782095037873b81f1c27b43
BLAKE2b-256 checksum
How to use checksums
35218e793c09a224d6bf6d04e8a57512a0be8c05c823fecf91137f8e0924eed8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / krutiextract-1.0.0-py3-none-any.whl

Download URL krutiextract-1.0.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
488a97b981f4fc097f15bac84b858c44e425dfcebbff07442767df258d0e8ca7
BLAKE2b-256 checksum
How to use checksums
4be7320836f31a3f51d71943a9b63d8078f480d05ff9bb6a7588319a3a1949b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release history Release notifications | RSS feed

1.6.1

2 release files

1.0.7

2 release files

1.0.3

2 release files

1.0.2

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page