How kurama-90/ocr-and-text-extraction-from-scanned-pdfs works
Project Type and Purpose
• This is a Python-based tool using OCR (EasyOCR) and PDF processing (PyMuPDF) to extract text from scanned PDFs.
• The purpose is to convert a scanned PDF into a searchable PDF (by adding a text layer) and export the OCR results into an Excel file for further analysis.
Key Components from the File Structure
• uploads folder: Serves as the input repository where users place scanned PDFs (e.g., scanned_document.pdf).
• main.py: The central script that orchestrates the entire processing pipeline.
• outputs folder: Stores the results including output.pdf (enhanced with a text layer) and output.xlsx (extracted text data).
• requirements.txt: Lists dependencies such as EasyOCR, PyMuPDF, pdf2image, OpenCV, NumPy, and Pandas.
Mapping Out the Processing Flow
• Input Stage:
• “Uploads” folder: Represents the entry point where the scanned PDF is provided.
• PDF to Image Conversion:
• Use pdf2image (and require poppler) to convert the uploaded PDF into images.
• Optionally, use OpenCV and NumPy to preprocess these images (e.g., enhancing contrast, resizing).
• OCR Stage:
• Utilize EasyOCR to perform text recognition on the processed images.
• PDF Text Layer Addition:
• Use PyMuPDF (fitz) to incorporate a selectable text layer into the original PDF.
• Exporting and Output:
• Write the new searchable PDF into the “outputs” folder.
• Recognized text into a structured format and export it as an Excel file using Pandas.
Architectural Patterns and Design Principles
• Although not a multi-tier architecture, the project follows a linear processing pipeline where each stage depends on the output of the previous one.
• Modularity: Even if implemented in a single script, think of each functional block as an independent module (PDF conversion, OCR, PDF editing, Excel export). This is akin to a pipeline or sequential processing system.