How to generate an EPUB file on Fedora

It is becoming more popular to read content on smartphones. Every phone comes with its own ebook reader. Believe or not, it is very easy to create your own ebook files on Fedora.

This article shows two different methods to create an EPUB. The epub format is one of the most popular formats and is supported by many open-source applications.

Most people will ask “Why bother creating an EPUB file when PDFs are so easy to create?” The answer is: “Have you ever tried reading a sheet of paper when you can only see a small section at a time?” In order to read a PDF you have to keep zooming and moving around the document or scale it down to a small size to fit the screen. An EPUB file, on the other hand, is designed to fit many different screen types.

Method 1: ghostwriter and pandoc

This first method creates a quick ebook file. It uses a Markdown editor named ghostwriter and a command-line document conversion tool named pandoc.

You can either search for them and install them from the Software Center or you can install them from the terminal. If you are going to use the terminal to install them, run this command: sudo dnf install pandoc ghostwriter.

For those who are not aware of what Markdown is, here is a quick explanation. It is a simple markup language created a little over 15 years ago. It uses simple syntax to format plain text. Markdown files can then be converted to a whole slew of other document formats.

ghostwriter

Now for the tools. ghostwriter is a cross-platform Markdown editor that is easy to use and does not get in the way. pandoc is a very handy document converting tool that can handle hundreds of different formats.

To create your ebook, open ghostwriter, and start writing your document. If you have used Markdown before, you may be used to making the title of your document Heading 1 by putting a pound sign in front of it. Like this: # My Man Jeeves. However, pandoc will not recognize that as the title and put a big UNTITLED at the top of your ebook. Instead put a % in front of your title. For example, % My Man Jeeves. Sections or chapters should be formatted as Heading 2, i.e. ## Leave It to Jeeves. If you have subsections, use Heading 3 (###).

Once your document is complete, click File -> Export (or press Ctrl + E). In the dialog box, select between several options for the Markdown converter. If this is the first time you have used ghostwriter, the Sundown converter will be picked by default. From the dialog box, select pandoc. Next click Export. Your EPUB file is now created.

ghostwriter export dialog box

Note: If you get an error saying that there was an issue with pandoc, turn off Smart Typography and try again.

Method 2: calibre

If you want a more polished ebook, this is the method that you are looking for. It takes a few more steps, but it’s worth it.

First, install an application named calibre. calibre is not just an ebook reader, it is an ebook management system. You can either install it from the Software Center or from the terminal via sudo dnf install calibre.

In this method, you can either write your document in LibreOffice, ghostwriter, or another editor of your choice. Make sure that the title of the book is formatted as Heading 1, chapters as Heading 2, and sub-sections as Heading 3.

Next, export your document as an HTML file.

Now add the file to calibre. Open calibre and click “Add books“. It will take calibre a couple of seconds to add the file.

Once the file is imported, edit the file’s metadata by clicking on the “Edit metadata” button. Here you can fill out the title of the book and the author’s name. You can also upload a cover image (if you have one) or calibre will generate one for you.

Next, click the “Convert books” button. In the new dialog box, select the “Look & Feel” section and the “Layout” tab. Check the “Remove spacing between paragraphs” option. This will tighten up the contents as indent each paragraph.

Now, set up the table of contents. Select the “Table of Contents” section. There are three options to focus on: Level 1 TOC, Level 2 TOC, and Level 3 TOC. For each, click the wand at the end. In this new dialog box, select the HTML tag that applies to the table of contents entry. For example, select h1 for Level 1 TOC and so on.

Next, tell calibre to include the table of contents. Select the “EPUB output” section and check the “Insert Inline Table of Contents“. To create the epub file, click “OK“.

Now you have a professional-looking ebook file.

Using Software

29 Comments

  1. There are a lot of command-line tools that come with Calibre one of these is ebook-convert.

  2. dimwit

    Cool, but where is the paragraph with some usage examples of the pandoc command line conversion tool?
    Ok, as a seasoned Linux user I would study pandoc’s man page now.

  3. Chris Moller

    A more elaborate use of calibre, one I use in writing books, is to write the book using DocBook markups, an HTML-like schema.

    DocBook sources can be spun in different ways, including directly to publication-quality PDF as well as to HTML, and then from there to EPUB using a CLI utility, called ebook-convert, that’s part of the calibre package. (I use a Makefile to run all that, so going from DocBook to EPUB is just a matter of pounding in “make epub” on the command line.)

    The advantage of all this is that DocBook offers a lot of things like title page formatting, table-of-contents, bibliography, index, and glossary formatting, etc, and gives you access to most or all of the Unicode character set. You can also write the DocBook source using any text editor–I use emacs–that gives you a lot more control than WYSIWYG things like LibreOffice. (A plus of emacs is that you can customise it to, for example, have it insert things like pairs with a single keystroke.)

    (DocBook is part of the “Authoring and Publishing” packages group.)

    (Editor’s note: This comment was edited to remove artifacts of WordPress trying to treat the example as HTML)

    • I never heard of DocBook before. Thanks for mentioning it. I stopped using word processors about five years ago and now write exclusively in Markdown. I was writing in plain text, but I wanted to be able to add simple formating. I discovered Markdown and was hooked.

    • Also, I’ve been meaning to get into the world of emacs, but haven’t had a chance to do so.

  4. Leslie Satenstein

    My bit of fun for today.

    This symbol # is called the octothorpe
    and this one £ is the pound symbol.

    I am not sure what to call ¤

    And yes, I did find your article informative and I learned about
    pandoc, ghostwriter and more.

    Thanks

    Leslie

    • Thanks for setting me straight. I’ll fix it. By the way, was it named after a guy named Thorpe or a guy named Octo? 🙂

      • leslie Satenstein

        Hi John,
        Actually, named after Thorpe. He was born missing the two pinky fingers from each hand.
        No-one questioned him about his toes.

        I also discovered that the ¤ on my Canadian French keyboard layout. I believe it represents currency, but the glyph has no name.

    • Vernon Van Steenkist

      In the Linux/Unix world, # is known as the pound, hash or number symbol – never the octothorpe symbol.

      • What Leslie means is that’s the actual name for the symbol itself. People also often call & an “and,” although the symbol is itself named the ampersand, because it’s clumsy to say “use ampersand ampersand for a logical AND” instead of “use ‘and and’ for a logical AND.” You’re right though, we usually refer to # as pound, hash, or number.

  5. robert pratersch

    My E-Reader tolino doesnt work with linux/fedora. lsusb command list the device correctly but mounting did not work. So Fedora is unable to communicate with the device. What can i do?

    • Robert, this sounds like a good question to post on Ask Fedora.

    • Vernon Van Steenkist

      What do you mean doesn’t work? Have you tried opening Calibre, connecting your tolino reader to your computer, and seeing if Calibre recognizes it?

    • Rene Reichenbach

      I am using Tolino shine 1 and 3 … both work flawless with fedora 32.

      I fear your setup is slightly broken.

  6. Eduard Lucena

    Quick fix: “Level 1 TOC, Level 3 TOC, and Level 3 TOC” should be “Level 1 TOC, Level 2 TOC, and Level 3 TOC”

  7. Vernon Van Steenkist

    A few comments.

    Both LibreOffice and the web version of Google Docs, accessible through Firefox and Chromium will export into epub format directly. Not sure why you are exporting to HTML, importing into Calibre and then converting to epub.
    Besides an epub editor, Calibre is also an e-book library. Epubs catalogued in the Calibre library can be transferred to an e-book reader by Calibre via USB. In addition, Calibre can act as a server. The Calibre Content Sharing button allows you to access your library through an HTML web browser (ex. http://fedorabox:8080) or an e-book reader supporting OPDS (ex. (ex. http://fedorabox:8080/opds). The Calibre server can be started through the menus or from the command line (calibre-server).
    Reading e-books on your phone can cause eye problems since the screen is constantly refreshing and generating light. You are much better off reading e-books on an e-ink e-book reader. E-ink screens reflect light rather than emit light and the screen only refreshes when you turn the page. E-ink is like paper and will not wash out in direct sunlight. I personally use an Onyx Boox e-book reader model that supports WiFi and OPDS.
    Finally, another way to generate epubs is to scan your paper book or printed page (scanimage), process the image with unpaper (unpaper) and then perform optical character recognition on the scanned image via tesseract. The resulting text file can be edited and converted into an epub via Calibre. You can also convert the scanned image to pdf using convert and then perform optical character recognition via the web version of Google Docs.

  8. Anthony

    I have experimented with asciidoc, and with asciidoctor, using the output as html. Alternatively, if I specify the output as docbook, I can then use pandoc to send it to many different formats, such as epub, docx, or latex. Where I need precise PDF output, I’ve found writing latex the best method. I’ve wondered how to go from docbook to customised html (i.e. themed), but couldn’t wrap my head around xslt/saxon or whatever the mechanisms were to achieve that.

  9. LibreOffice Writer can export to EPUB as well. It’s perhaps a little less flexible than the tools described above but it is much more accessible. On my Fedora Workstation it’s in the “File – Export as …” menu.

  10. I would write a piece on the excellent Sigil application, but I see that Fedora carries a rather older version of it.

  11. Marc Balmer

    There is also AsciiDoctor, asciidoctor.org, which produces beautiful e-books in .epub format.

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions