# azozzalfiras/pdf-ocr architecture

> Architecture diagram of the GitHub repository azozzalfiras/pdf-ocr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azozzalfiras/pdf-ocr
- Repository: https://github.com/azozzalfiras/pdf-ocr

## Overview

##### Project type and purpose
- This is a purely front-end, client-side web tool (no backend or server component).
- Its goal is to let users load PDFs or images, extract text via OCR, convert images to PDFs, and download or copy the results—all running locally in the browser.

##### Main components
- HTML & Tailwind CSS “UI Layer” – the interactive interface (buttons, dropdowns, file inputs, progress indicator, output area)
- JavaScript Modules – the processing engines and glue code
b. OCR Engine (Tesseract.js)
c. PDF Renderer (pdf.js)
d. PDF Generator (jsPDF)
e. Output Handlers – Download (PDF/Text), Clipboard

##### Relationships and data flows
1) User → UI Layer:
- Select PDF/Image file
- Choose OCR language
- Click “Convert” or “Download”
2) UI Layer → pdf.js (if input is PDF):
- Render each PDF page to an image/canvas
3) UI Layer → Tesseract.js:
- Feed image (from pdf.js or directly from an uploaded image)
- Receive extracted text
4) UI Layer → jsPDF (for image-to-PDF or text-to-PDF download):
- Assemble pages or text into new PDF
5) UI Layer → Output Handlers:
- Trigger browser download of PDF or TXT file
- Copy text to clipboard

##### Architectural patterns and design principles
- Modular separation of concerns:
- UI presentation (HTML + CSS)
- “Orchestration” script (glues UI to processing libs)
- Third-party engine modules (Tesseract.js, pdf.js, jsPDF)
- Client-side processing only: no network calls, ensuring privacy
- Event-driven: user events trigger asynchronous workflows

- Rectangles for your UI components (File Picker, Language Selector, Buttons, Progress Display)
- Diamonds or small rectangles for Output Handlers (Download, Clipboard)
- From File Picker → pdf.js / Tesseract.js
- From pdf.js → Tesseract.js
- From Tesseract.js → UI (Text Output)
- From Text Output → jsPDF / Clipboard / Download module

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::external

    subgraph "Browser (Client)"
        subgraph "UI Layer"
            FilePicker["File Picker"]:::ui
            LanguageSelector["Language Selector"]:::ui
            ConvertButton["Convert / Download Buttons"]:::ui
            ProgressDisplay["Progress Indicator"]:::ui
            TextOutput["Output Area (Text/PDF)"]:::ui
        end

        subgraph "Orchestration Script"
            Orchestrator["Glue Code"]:::script
        end

        subgraph "Processing Engines"
            Tesseract["Tesseract.js"]:::ocr
            PDFRenderer["pdf.js"]:::pdf
            PDFGenerator["jsPDF"]:::pdfgen
        end

        subgraph "Output Handlers"
            DownloadPDF["Download PDF"]:::output
            DownloadText["Download TXT"]:::output
            CopyClipboard["Copy to Clipboard"]:::output
        end
    end

    Documentation["README.md"]:::doc

    User -->|Select File| FilePicker
    FilePicker -->|"PDF file"| PDFRenderer
    FilePicker -->|"Image file"| Tesseract
    PDFRenderer -->|"Canvas Image"| Tesseract
    LanguageSelector -->|Select Language| Orchestrator
    ConvertButton -->|Trigger Conversion| Orchestrator
    Orchestrator -->|Assembles Data| PDFGenerator
    Orchestrator -->|Sends Text| TextOutput
    TextOutput -->|Text Data| Orchestrator
    Orchestrator -->|Blob/TXT| DownloadPDF
    Orchestrator -->|Blob/TXT| DownloadText
    Orchestrator -->|Text| CopyClipboard
    Orchestrator -->|Updates| ProgressDisplay
    Tesseract -->|"Extracted Text"| TextOutput

    click FilePicker "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click LanguageSelector "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click ConvertButton "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click ProgressDisplay "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click TextOutput "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click Orchestrator "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click Tesseract "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click PDFRenderer "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click PDFGenerator "https://github.com/azozzalfiras/pdf-ocr/blob/main/Img2PDF.html"
    click DownloadPDF "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click DownloadText "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click CopyClipboard "https://github.com/azozzalfiras/pdf-ocr/blob/main/index.html"
    click Documentation "https://github.com/azozzalfiras/pdf-ocr/blob/main/README.md"

    classDef external fill:#d3e5ff,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef ui fill:#e0f7fa,stroke:#00796b,color:#004d40,stroke-width:1px;
    classDef script fill:#fff3e0,stroke:#fb8c00,color:#e65100,stroke-width:1px;
    classDef ocr fill:#e8f5e9,stroke:#388e3c,color:#1b5e20,stroke-width:1px;
    classDef pdf fill:#fff8e1,stroke:#f9a825,color:#f57f17,stroke-width:1px;
    classDef pdfgen fill:#ffebee,stroke:#e53935,color:#b71c1c,stroke-width:1px;
    classDef output fill:#f5f5f5,stroke:#616161,color:#212121,stroke-width:1px;
    classDef doc fill:#ede7f6,stroke:#5e35b1,color:#311b92,stroke-width:1px;
```
