Skip to content

huseyinuzum/PDFtoEPUB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

📚 PDFtoEPUB Converter

An enterprise-grade, full-stack web application designed to instantly convert PDF documents into responsive, perfectly formatted EPUB files for e-readers. Built with modern web technologies, this system guarantees zero data loss, intelligent layout extraction, and high-performance concurrent processing.


🚀 Key Technological Highlights

1. Robust API & Conversion Engine (Python / FastAPI)

The core of the application relies on an asynchronous Python microservice built to handle heavy, concurrent PDF parsing.

  • FastAPI Core: Leverages uvicorn and FastAPI for ultra-low latency, async route handling, and highly concurrent multipart file uploads (up to 20MB per request payload limits enforced).
  • Intelligent Page-by-Page Extraction (PyMuPDF / fitz): Extracts raw structural text arrays from the document. The system processes PDF geometries (x/y coordinates) to mathematically separate body text from running headers and footers (ignoring the top and bottom 8% vertical margins to strip out repeated author names/page numbers).
  • Dynamic E-Book Generation (EbookLib): Recompiles chronological string chunks directly into standard, reflowable EPUB3 architecture. The API enforces strict CSS rules (page-break-before: always;) to perfectly map 1 PDF Page to 1 EPUB Page without compromising the fluid, text-based reading experience.
  • Auto-Cleanup Background Tasks: Integrates FastAPI's BackgroundTasks queue to programmatically flush temporary processing directories (tmp) immediately after the FileResponse executes, strictly preventing memory leaks and storage overlap.

2. High-Performance Client Interface (Next.js 14+)

The frontend provides a seamless, App-like (PWA) experience without page reloading or server-side lag.

  • Next.js & Turbopack: Bootstrapped via Next.js for SSR/CSR combinations, utilizing Turbopack for near-instant compilation and rendering.
  • Dynamic IP Binding: Developed with mobile-testing in mind. Includes intelligent window .hostname polling via XMLHttpRequest to automatically bypass "localhost" restrictions, dynamically targeting local network and cellular network endpoints without code recompilation.
  • State Management: Fully client-side state machine (React Hooks) tracking parallel file objects inside an interactive Dropzone. Supports 4 distinct lifecycle queues: idle, converting, success, and error.
  • UI/UX Design: Zero CSS frameworks required beyond standard TailwindCSS v4. Implements advanced "Glassmorphism" design paradigms (backdrop-filters) combined with granular micro-animations via Lucide-React.

3. Progressive Web App (PWA) Standards

  • Built to function identically to a native iOS/Android application.
  • Configured with strict metadata limits and caching layers to be fully installable directly to a mobile device's home screen.

🌐 Local Development Environment

Prerequisites

  • Node.js (v18+)
  • Python (v3.11+)

Running the Backend

  1. cd backend
  2. Create virtual environment: python -m venv venv
  3. Activate virtual environment:
    • Mac/Linux: source venv/bin/activate
    • Windows: venv\Scripts\activate
  4. Install dependencies: pip install -r requirements.txt
  5. Start the FastAPI server (Bind to all IPs for mobile testing):
    uvicorn main:app --host 0.0.0.0 --port 8000 --reload

Running the Frontend

  1. cd frontend
  2. Install active dependencies: npm install
  3. Start the Turbopack server:
    npm run dev

☁️ Cloud Deployment Architecture

This application utilizes a decoupled, serverless hosting strategy for maximum free-tier scaling and security.

  • Frontend Hosting (Vercel): The Next.js client is CI/CD integrated with Vercel edge networks. Ensure the NEXT_PUBLIC_API_URL environment variable is explicitly set to point to the backend provider.
  • Backend Hosting (Render.com / AWS): The FastAPI Python engine is deployed natively using Python 3.11 (configured via .python-version explicitly). Requires minimal build triggers: pip install -r requirements.txt and uvicorn main:app --host 0.0.0.0 --port $PORT.