← Back to projects

// Personal Project · Case Study

PDF2EPUB: an Albanian Book Converter

A little desktop app I built after buying a friend a Kindle as a gift. The Albanian books they wanted to read only existed as PDFs, a lot of them scanned, and every converter I tried turned the text into a mess. So I wrote one that doesn't.

Role
Solo project
Type
Desktop app (Windows)
Stack
Python · PyMuPDF · Tesseract
Status
Working · in use

01. The problem

I bought a friend a Kindle as a gift, but the Albanian books they wanted weren't sold in any format it could read. They only existed as PDFs, and a lot of them were scanned images rather than real text.

I went through a dozen online PDF to EPUB converters and they all fell over the same way. Scanned files came out as unreadable image blobs, and the handful that tried OCR butchered Albanian's special letters. Every ë and ç came out as garbage, which made the whole book pointless. So I decided to write my own.

02. How I approached it

The trick is realising that not all PDFs are the same. One that was written digitally already has selectable text inside it, while a scanned book is really just photos of pages. The converter figures out which one it's looking at and handles it accordingly.

  • Work out the PDF type Sample the first few pages with PyMuPDF. If there's no text to pull out, it's a scan.
  • Read digital PDFs directly Grab the text block by block and keep the paragraphs intact.
  • Send scans through OCR Render each page to a 300 DPI image and run Tesseract in Albanian and English (sqi+eng).
  • Fix the Albanian letters Clean up the OCR mistakes that always show up, like ë and ç.
  • Build the EPUB Generate the chapters, table of contents, navigation and styling with ebooklib, one chapter per page.
def _is_scanned(doc) -> bool:
    for i in range(min(5, len(doc))):
        if doc[i].get_text().strip():
            return False
    return True

That's the whole detection step: if none of the first five pages has any text to pull out, the PDF is a scan and goes through OCR.

03. Why the other converters failed me

Generic OCR has no idea about Albanian, so it keeps misreading the accented letters. Fixing it came down to two things: pointing Tesseract at the Albanian language pack, and then cleaning up the few mistakes that still slipped through.

A scanned page of Albanian text titled Kapitulli i parë, full of ë and ç letters

Tesseract on its own

Një ditë vendosi ta shkruante vetë fundin e tregimit. Mori njé fletore të re, ndezi llambën dhe filloi: «Cdo gjë që ka réndési, fillon me një faqe të bardhe.»

After the clean-up, in the EPUB

Një ditë vendosi ta shkruante vetë fundin e tregimit. Mori një fletore të re, ndezi llambën dhe filloi: «Çdo gjë që ka rëndësi, fillon me një faqe të bardhë.»

misread fixed

A demo page I wrote and "scanned" for this case study, run through the real converter (the last paragraph is shown). Tesseract alone misreads four words. The clean-up fixes all of them: é goes back to ë, the missing Ç is restored, and a dropped ë is caught by a short list of known misreads. The finished page matches the original word for word.

04. How it's built

Simple GUI

A Tkinter desktop window with drag-and-drop (tkinterdnd2), file picker, page count, and a live progress bar.

Responsive UI

Conversion runs on a background thread so the window never freezes, reporting per-page progress back to the UI.

Smart pipeline

PyMuPDF for parsing & rendering, Tesseract for OCR, ebooklib for spec-compliant EPUB output with a TOC.

One-click distribution

Packaged into a standalone Windows .exe with PyInstaller, so there's no Python install needed to run it.

05. How it turned out

It ended up doing the one thing nothing else could, and it's genuinely in use:

  • Turns whole Albanian novels into clean, readable EPUBs with the right letters.
  • Real books I've run through it: Ferma e kafshëve (Animal Farm), Krim dhe ndëshkim (Crime and Punishment), and others.
  • Handles digital and scanned PDFs on its own, no manual fiddling.
  • And the part that actually mattered: the Kindle I gave my friend is full of Albanian books now.