# kurama-90/ocr-and-text-extraction-from-scanned-pdfs architecture

> Architecture diagram of the GitHub repository kurama-90/ocr-and-text-extraction-from-scanned-pdfs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs
- Repository: https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Input Stage"
        A("Uploads Folder"):::folder
    end

    subgraph "Orchestration"
        G("Main Processing Script"):::script
    end

    subgraph "Processing Pipeline"
        B("PDF-to-Image Conversion Module (pdf2image, OpenCV, NumPy)"):::module
        C("OCR Module (EasyOCR)"):::module
        D("PDF Processing Module (PyMuPDF)"):::module
    end

    subgraph "Output Stage"
        E("Searchable PDF (outputs/output.pdf)"):::file
        F("Excel Output (outputs/output.xlsx)"):::file
    end

    subgraph "Dependencies"
        H("Dependencies (requirements.txt)"):::dependency
    end

    A --> G
    G --> B
    B --> C
    C --> D
    D --> E
    D --> F
    H --> G

    click A "https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs/tree/main/uploads/"
    click G "https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs/blob/main/main.py"
    click E "https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs/blob/main/outputs/output.pdf"
    click F "https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs/blob/main/outputs/output.xlsx"
    click H "https://github.com/kurama-90/ocr-and-text-extraction-from-scanned-pdfs/blob/main/requirements.txt"

    classDef folder fill:#D3EBCD,stroke:#333,stroke-width:2px;
    classDef script fill:#FFE699,stroke:#333,stroke-width:2px;
    classDef module fill:#B3D7FF,stroke:#333,stroke-width:2px;
    classDef file fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef dependency fill:#F4CCCC,stroke:#333,stroke-width:2px;
```
