Readwyn 0.1.0

Convert PDF to EPUB without calibre

On 50 Project Gutenberg PDFs, Readwyn’s own converter matched or beat calibre’s ebook-convert --enable-heuristics on word error rate for 47 of them, and it was faster on all 50. It’s part of the app, so you don’t need calibre, poppler or anything else installed. Add a PDF and you get an EPUB 3 of it in the library, with the PDF kept beside it.

Adding PDFs

Drop the PDFs on Readwyn’s window, or pick them with “Add books”. PDFs that already sit in a calibre library are converted during the import (How to import your calibre library into Readwyn).

“Read” then opens the EPUB in Readwyn’s reader; Read a PDF book as reflowable text on a Mac shows what that looks like. If you’d rather take the EPUB to another app, the book’s Details tab has “Show in Finder” for it.

What the conversion does

A PDF puts each line at a fixed spot on a page. To get a book that reflows, the converter:

  • joins lines into paragraphs across pages and columns, reading a page with columns one column at a time;
  • drops running headers, running footers and page numbers;
  • rejoins words that were hyphenated at the end of a line;
  • keeps italic, bold, superscripts and subscripts;
  • finds headings from their size, their weight and the PDF’s outline;
  • builds the table of contents from that outline, or from the headings if there’s no outline;
  • turns link annotations into links;
  • keeps every JPEG byte for byte and every other image with the same pixels;
  • marks an image that covers at least 80 % of page 1 as the cover.

What it can’t convert

A scanned PDF with no text layer won’t convert, because there’s no OCR. Nor will an encrypted PDF. Either way you keep the PDF alone, and “Open” passes it to your default PDF app.

JPEG 2000 and JBIG2 images (JPXDecode and JBIG2Decode) are left out, but the rest of the book still converts.

How the conversion was measured

A PDF has no exact text to compare with, so each conversion is scored against a reference: the EPUB 3 of the same Project Gutenberg ebook. The 50 PDFs are in English, German, French, Italian, Greek, Spanish, Latin and other languages, and run from 20 to 2,164 pages.

The baseline is calibre 9.15.0’s ebook-convert --enable-heuristics, run once with --pdf-engine calibre and once with --pdf-engine pdftohtml. For each book, whichever run had the lower word error rate counts. Each run has a time limit of 5 minutes.

Both outputs are scored against the reference in five ways:

  • Word error rate: wrong, missing and extra words, divided by the number of words in the reference.
  • Paragraph-break F1: how closely the paragraph breaks match the reference’s, from 0 to 1.
  • Heading recall: the share of the reference’s headings that come out as headings.
  • Table-of-contents coverage: the share of the PDF outline’s entries that end up in the table of contents, pointing to the right place.
  • Image coverage: the share of the images drawn on the pages that make it into the output.

Each mean leaves out the books where its measure doesn’t apply: a reference with no headings, a PDF with no outline, or pages with no images.

One book skews the total: pg31552, a Portuguese dictionary of 2,164 pages. Both calibre runs went over the limit on it, so its baseline is an EPUB with no text. The second line of the table leaves it out.

MeasureReadwynBaseline
Total word error rate9.15 %36.81 %
Total word error rate without pg315528.68 %10.37 %
Mean paragraph-break F1 (50 books)0.7530.587
Mean heading recall (42 books)0.9120.145
Mean table-of-contents coverage (28 books)0.9900.727
Mean image coverage (25 books)1.0000.859

On the three books where calibre did better, Readwyn’s word error rate was higher by 0.14 percentage points at most. epubcheck reports no errors for any of the 50 EPUB 3 files.

Both were timed on the same Mac, one conversion at a time, with Readwyn’s release build. Readwyn’s slowest conversion was that dictionary, at 0.45 s. Mother’s Remedies, 1,150 pages, took 0.06 s against 115.6 s for the baseline.