Blog · EPUB

How to Convert EPUB to TXT

When plain text is the right target

Plain text has no layout, no fonts and no images, and that is why people ask for it. It can be searched with any tool, read aloud by a text-to-speech program, compared with another edition using a diff tool, pasted into a translation memory, or fed to a word counter. If you want those uses, TXT is better than any rich format.

Steps with the PDFSwift tool

  1. Open EPUB to TXT.
  2. Choose the EPUB or drag it onto the page.
  3. Press Convert to TXT.
  4. Look at the preview and the chapter and word counts.
  5. Press Download TXT.

The conversion happens in your browser. The book is not uploaded, and the page does not need to talk to a server to produce the file.

What the text file contains

HTML entities are decoded, so —,   and numeric references like — come out as the real characters.

Encoding, Arabic and other scripts

The file is UTF-8. That covers every script, including Arabic, Hebrew, Cyrillic, Greek, Devanagari and CJK, without conversion or transliteration. If a text editor shows nonsense, it is probably reading the file as a legacy code page. Choose UTF-8 explicitly when opening it. Right-to-left text is stored in logical order, as it should be; the direction is applied when it is displayed.

What gets lost

If you need structure such as heading levels and emphasis, convert to Markdown instead. If you only need chapters in separate files, or the quotations, use the text extractor.

Checking the result

  1. Compare the number of sections with the table of contents of the book.
  2. Search the text file for a phrase you know is in the last chapter.
  3. Look at one chapter with a list and one with a table to see how they were written.

If chapters are missing, the book’s reading order may not list them. The validator will show it, and the repair tool can re-link chapters that the table of contents still points to.

A note on DRM

Books from stores may be encrypted. The converter reads the file exactly as stored; for an encrypted book the result is unreadable text, and these tools do not remove protection. Use books you are allowed to convert.

Cleaning the text for common uses

The output is intentionally plain, but some uses want a little more tidying. Here are the changes that come up most often, with commands for a Unix-style shell, available on macOS, Linux and Windows with WSL or Git Bash.

You wantCommand or step
Word countwc -w book.txt
Search with contextgrep -n -i -C 2 "phrase" book.txt
Remove line breaks inside paragraphs for pastingJoin lines that are not followed by a blank line; most editors have a “join lines” command.
Compare two editionsdiff -u edition1.txt edition2.txt
Split into chaptersUse the text extractor to get one file per chapter instead of splitting by hand.
Strip the first lines (title, author)tail -n +4 book.txt > body.txt

Using the file with text-to-speech

Most text-to-speech tools read everything they are given, including the copyright page and the contents list. Delete those parts from the beginning of the text file first. If the voice mispronounces a recurring name, find and replace it with a phonetic spelling in the text copy, which does not affect your EPUB.

Language learning

Plain text imports easily into vocabulary and flashcard tools, and many reading-comprehension tools accept it. Because the file is UTF-8 and unaltered, accented letters and non-Latin scripts remain intact. For right-to-left languages, check that the program you import into handles bidirectional text; the file itself is stored in logical order, which is the correct form.

What the converter will not do