How to create an eBook the open source way

No readers like this yet.
Publishing the open source way

Opensource.com

Astute readers will have noticed that we’ve begun publishing our "Open Voices" eBooks in the ePub format. Now, some of our best essays and interviews are available as lightweight and portable files, and can be read on any electronic reading device that supports this open standard.

And who better to undertake the task of converting our library than your friendly opensource.com intern? This summer, I’ve refined what I consider a simple, reliable method for creating eBooks the open source way. Today, I’d like to share it.

Our task

This guide explains one method for creating electronic books ("eBooks") in the ePub format using open source tools available on most popular computing platforms. ePub is the International Digital Publishing Forum's open standard for digital book publishing, and most major electronic reading devices support it (except for the Kindle—sorry, Amazon fans!). But more importantly, formatting an electronic book as an ePub guarantees that many online eBook marketplaces will host and distribute the work.

The method I outline here reflects two desires: to create open eBooks in open formats using open tools, and to avoid unnecessary complication by involving as few of these tools as possible. As a result, this guide describes a rather specific procedure—one for collecting and editing content in the OpenDocument format and turning that content into an ePub eBook.

You will need

One additional note before we begin: I could not have done this work as quickly or as easily without the help of Scott Nesbitt, the Auckland-based writer and editor who's a mainstay at opensource.com. When I began imagining how I might accomplish this project, I read (several times) many of Scott's outstanding eBook tutorials, which were immensely helpful. Any open source project worth its salt must acknowledge its debts; Scott has my gratitude.

Alright. Let’s get started.

Preparing content

First things first: your eBook needs content.

You might be composing fresh content for your eBook project. Or maybe you’re repurposing content you’ve already published on a blog. In either scenario, LibreOffice makes for an ideal tool.

Regardless of how you get your content into LibreOffice, remember one crucial point: you must use styles to format your document. "Styles" are more than font choices and line-height preferences; they’re statements about the logical and meaningful structure of your document (for more on this, do some reading on "semantic markup").

Some might think using a word processor to create electronic books is a bit looney, but here's the thing: quickly and efficiently formatting text is what word processors are designed for. Unfortunately, most users never learn to use word processing software properly, applying text formatting (like font sizes or text colors) to individual elements willy-nilly. If you’re one of those people (I was!), then you should do yourself a wonderful favor and study Ahuka’s LibreOffice tutorials on Hacker Public Radio.

Applying styles

In LibreOffice, press F11 to toggle the Styles and Formatting pane. When this pane is visible, it will display the styles currently in use in your document. To make an ePub file, you’ll need to designate at least the following elements:

  • Headings. The title of the book and its major chapters should be set in  "Heading 1." All chapter sections should be set in "Heading 2." For subsections, choose "Heading 3." While LibreOffice allows writers to designate up to nine heading styles, you shouldn’t move beyond the first three. Most ePub makers won’t recognize anything but these.
  • Body text. The text of your book should receive the "Text body" style in LibreOffice.
  • Monospace text. Some text—computer code, most notably—requires special formatting to maintain its spacing. It should be designated "Preformatted text."
  • Extended quotations. Some types of writing feature block quotes. These should be set in the "Quotations" style.

No element in your OpenDocument should be unstructured. Be sure that every heading, every quotation, and every paragraph are properly designated as such. Bonus: if you’re copying text from a source that’s already been marked up semantically—say, a web page—then LibreOffice should recognize the styles from the source document and apply them in the target document.

Forget fonts

Don’t worry about how the elements of your document look. You can spend all afternoon finding the perfect font for your chapter titles, but you’ll be wasting your time. ePub files contain styling specifications written in CSS;  they're designed to allow electronic reading devices to apply their own preferences to books, allowing readers to specify their font styles and sizes.

In short, how something looks is not as important as how something has been designated. Be sure every element in your OpenDocument has been marked up, but don’t fret about things like margins.

When you’ve finished putting all your content into LibreOffice, save your work.

Editing content

Before generating your eBook, you’ll want to edit it. Of course, your readers will appreciate a thorough copy edit, but your software will reward you for the time you spend tidying your markup.

Beware the invisible

In LibreOffice, press Ctrl+F10 to make "nonprinting characters" visible. Nonprinting characters are simply those invisible indicators that the word processor uses to keep track of text formatting. By toggling this feature, you’re able to spy every errant space, line break, and carriage return that may have crept into your document.

Remove any of these that aren’t necessary, like a space at the end of a paragraph’s final sentence or a blank paragraph between chunks of text. You’ll want your ePub file to be as clean as possible not only so it looks great, but also so that the OpenDocument-to-ePub conversion process proceeds smoothly.

At this point, be sure to save your work.

Generating your ePub

We’re now ready to generate an ePub file from the OpenDocument source. Thanks to the handy Writer2ePub extension for LibreOffice, doing this couldn’t be much easier.

Download and install Writer2ePub by clicking the appropriate download link on the project page. If the extension saves to your computer, double-click the download package and Writer should do the work of setting up the plugin for you.

If you’ve properly installed Writer2ePub, then LibreOffice should now feature a new ePub toolbar. With only three buttons, it’s easy to miss—so look closely.

First, click the blue button to set your eBook’s metadata. This is not only important but essential, as Writer2ePub won’t let you proceed without doing so. At the very least, you must specify:

  • An author's name
  • The book's title
  • The book's language

Additionally, you can specify a cover image for your book. By default, Writer2ePub searches your document for images and creates a cover from the first one it finds. It gets rather ornery if you ask it to do this when your book contains no images, so be sure to select "No Cover" to avoid trouble in this case.

When you’re satisfied with the parameters you’ve set, click "OK," then save your OpenDocument.

Finally, press the green button on the Writer2ePub toolbar, and watch as this magnificent plugin does its thing.

Examining your ePub

Writer2ePub will take control of LibreOffice and begin converting your OpenDocument to an ePub file. Naturally, the time required to do this varies depending on the length of your book and the number of images it contains.

When it’s finished, locate the folder that contains your OpenDocument source file. Next to it should be a brand new ePub with the same filename.

Open that file with your ePub reader of choice. Most folks like FBReader, which available on Windows, OS X, Linux, and Android. You might also consider installing your ePub reader as a browser extension (as you might with the aptly-named EPUBReader in Firefox, for example). Doing this allows you to open links to ePub files on the web without switching applications.

You’ll now want to inspect your eBook carefully. Be sure to examine its:

  • Table of contents (Is it complete? Are all headings properly ordered?)
  • Chapter and section headings (Do their maintain proper hierarchies? Is their capitalization consistent?)
  • Hyperlinks (Do they point where expected and function properly?)

I’ve noticed that Writer2ePub will occasionally produce errors when confronted with inordinately long hyperlinks, or links that point to things other than HTML files (like PDFs). I’ve also noticed that the plugin doesn’t react well when a chapter or section concludes with a numbered or bulleted list. In these cases, enter a blank paragraph at the end of the offending list to avoid complications.

Finally, validate your ePub file with the IDPF's validation tool.

Next steps

You now possess an eBook produced the open source way—with open tools, in an open format. Next, you might consider:

Bryan Behrenshausen
Bryan formerly managed the Open Organization section of Opensource.com, which features stories about the ways open values and principles are changing how we think about organizational culture and design. He's worked on Opensource.com since 2011. Find him online as semioticrobotic.

43 Comments

"ePub files do not carry much formatting information. They’re designed this way so electronic reading devices can apply their own preferences to books"

Sorry, that's just not true. If it were, we could just remove CSS altogether from the ePUB spec – which is not the case. Formatting is relevant to the content too.

Thanks, Marcio, for clarifying this. I should have provided a more nuanced explanation here. The IDPF does include CSS specifications as part of ePub accessibility guidelines (<a href="http://www.idpf.org/accessibility/guidelines/content/style/reference.php">available here</a>). CSS is valuable in this context because it allows users or other agents (i.e., ePub readers) to apply their own formatting in accordance with the classes outlined in the style sheets. But this is not to say that styles (or style sheets) are an unimportant aspect of ePub publishing—just that ePub creators should be aware that the styling they select may not be what readers ultimately confront. This is an important point; I'm glad you raised it, and I updated the guide to reflect it.

Sorry but excepted a very few apps like FBReader -- which has an interesting approach in "be the typographer of your ebooks" but fails miserably as it doesn't respect CSS support, which makes it the worst EPUB reader ever -- apps and devices have quite succeeded in honoring CSS style sheets while offering readers to modify some details (line-height, font, font-size, etc.).

Truth is you must get an in-depth knowledge of apps and devices so that you do not screw readers' overrides, but you just can't create some ebooks without advanced styles or you will provide with a sub quality reading experience.

And that is the reason why writer2epub offers users to create their own styles by prefixing their LO/OO styles with w2e_ for example, and why version 2 will get a CSS editor and allow fonts' embedding (BYW, that is something you can already do by exporting the EPUB file writer2epub exports in EPUB format with calibre, even if the resulting file is not top-notch regarding HTML markup + CSS).

The problem with styles is that since the old kindle mobi7 format was insanely limited, then everybody claimed ebooks' styles were pretty useless. Sure EPUB suffers from infuriating overrides (on the vendors' side) as overrides are not dealt with in the specs, but saying "styles are not important" will just make ebooks the cheap brother of paper books (bad typography, even worse layout not facilitating the understanding of some passages, etc.).

Note also that wellknown brands of tablets or ereaders CANNOT accept the ePub format, but almost all of them accept PDF (a few of them will also accept the DejaVu format, notably for high-resolution quality scans, notably when the content is also very graphics, such as comics books).

This howto completely forgets to say that the ePub format is not universal, and that ebooks shouldbe proposed at least in a secondary format (PDF is the second one, and for the PDF format, which is now open, there are also lots of producton tools, many more than tools that produce ePub documents).

Sorry, Phillippe, but I think you're overstating the case. According to Wikipedia, among hardware only Amazon's Kindle line, the Sony Librie (released in 2004 and now discontinued), and the Samsung Papyrus (released in 2009 before .epubs really took off) fail to read the .epub format. Source:

http://en.wikipedia.org/wiki/Comparison_of_e-book_readers#File_format_support

Wikipedia does not have a similar comparison available for software, but does have a short list of available apps and applets that support the format:

http://en.wikipedia.org/wiki/EPUB#Software

There's a much longer list in the same article of editing apps.

That's a bit of a blanket statement.

You can import EPUBs into the Kobo Reader. As for tablets, if you have a reader like <a href="http://fbreader.org/">FBReader</a> or <a href="http://www.aldiko.com/">Aldiko</a> then you should have no problems reading an EPUB.

Where did I speak about the Kobo Reader ???

I just said that the ePub format is NOT accepted on ALL ebook-readers.

And you reply by citing a speciifc model that supports ePub...

Your reply is just a blanket statement when you criticize something in my response that I've definitely NOT written.

Getting a bit quibbly here. My book, Green Comet, is available in ePub, but I also provide PDF and ODT, as well as OGG for those who'd rather listen. The only people who have reported a problem were the people with Kindles. Some were skilled enough to convert the file to the correct format, but for others Amazon provides an automatic conversion service. Members send the file to their Kindle email and it does the conversion for them. It's just not that dire.

Here's the link again, if you want to try it out.
http://greencomet.org

rjb

Interesting that you mention converting to the Kindle format. I've found that on occasion, Amazon's Kindlegen utility (whether run on my computer or at Amazon.com) is a bit finicky with EPUBs. I tried to convert one of my ebooks and Kindlegen choked because it didn't like one element in my CSS. That's <em>after</em> a check showed it was valid and well-formed.

In the end, I had to edit the stylesheet before that worked.

How does it work with "straight" text, like ODT or DOC?

I'm not sure how it works with formats like .odt or .doc/.docx. I usually write my ebooks in Sigil (for EPUB) or LyX (for PDF versions), and go from there.

To be honest, I've only encountered the problem I described twice -- once with a new ebook, and once with an update to another one that has previously been published to Amazon. And, in my infinite wisdom, I didn't note 1) the error message, and 2) how I fixed it. I know ...

tsk! ^_^

When I added my book to Amazon publishing, I was able to upload my ePub file and the Kindle Direct Publishing Services automatically converted my book into .mobi format.

Jason

That usually works for me, too. But, as I mentioned in a comment above (below?), I've had a couple of failures with the KDP converter. The worst part is that there's no visible rhyme or reason to it.

You wrote <em>wellknown brands of tablets or ereaders</em> and last time I checked, the Kobo Reader is a well-know brand of ereader. And at least one flavour of the Barnes & Noble Nook supports EPUB.

As for tablets, well there's always an app for that -- as I pointed out FBReader and Aldiko, as well as apps I don't know how many apps for the iPad.

Presumably all of this could have been done as easily with the equally open source Open Office (http://www.openoffice.org/) from the Apache Software Foundation. The download link for the Writer2ePub plugin, for instance, points to the Apache Open Office site.

Presumably, yes. But I have not tested it and so I cannot say for sure.

It does work with Apache OpenOffice, though, according to the Writer2ePub plugin project's site (which is mostly in Italian), there is a separate download for Apache OpenOffice 4.X. (The one marked 1.1.25A). Version 1.1.25 is compatible with LibreOffice 3.X-4.X, OpenOffice.org 3.X, Apache OpenOffice 3.X, and NeoOffice. I haven't tested it too much, but it does work.

Wonderful article, Bryan. Thanks for sharing the workflow you developed.

I was excited when I went to the FBReader site and saw that the version number was now up to 0.99.4 (the last version I used was 0.12). But then I was a little disappointed when I saw that only the Qt4 interface was supported now (it used to have Qt and GTK interfaces; not a big deal to me, but some people care about that kind of thing). Super disappointed that the version of FBReader in Fedora 19 is version 0.12. I'm going to try installing FBReader and <a href="https://github.com/sakisds/pPub">pPub</a> (a python/gtk3/webkit based e-reader) from source.

You're very welcome, Joshua. Happy publishing!

I've written something similar back in 2011 :)

<a href="http://linuxblog.darkduck.com/2011/11/how-to-create-ebook-with-openofficeorg.html">http://linuxblog.darkduck.com/2011/11/how-to-create-ebook-with-openofficeorg.html</a>

Please refrain from using the term "Open Source". The point of all this is to build, promote, and protect freedom. The correct term to use is Free Software

https://www.gnu.org/philosophy/open-source-misses-the-point.html

Hi windowsrefund,

Thanks for jumping in on the conversation here on opensource.com. There are many great places on the web advocating for free software. While we respect those views and enthusiasm, this thread about creating ePubs using open source tools is probably not the right forum for this type of philosophical discussion. Thanks again for your participation.

Jason

Thank you, no, I'll use open source or free software as the case requires.

As simple as a plugin? Thanks for the article, I'm going to try and convert client reports as having them to hand on iPad might be very useful...

Another very nice tool for creating ebooks is Calligra Author → http://www.calligra.org/news/calligra-announces-author/

Has this software been released? Calligra hasn't really spoken about it <a href="http://www.calligra.org/news/calligra-announces-author/">since last year</a>.

Yes, Calligra is up to version 2.7 which was released just a few days ago. I just had a chance to play with. Very promising. Not up to "snuff" concerning LibreOffice in terms of some of the more "professional" aspects of a world class office suite. However, what is very intriguing is the uniformity of the various modules' interfaces. Plus they have an "infant module" which is an offshoot of the word processor "Words" called Calligra Author which is more geared to e-publishing.

The main Calligra portal is here
http://www.calligra.org/
And the info on Calligra Author is here
http://www.calligra.org/news/calligra-announces-author/

Oh...BTW...thanks for the article....very helpful.

You're very welcome. And thanks for the Calligra update!

Great article (and not just because I'm mentioned!). There are a few resources in there that I haven't taken a look at, but definitely will.

I've found with Writer2ePub that I often need or want to tweak the CSS a bit. The look and feel of the resulting book isn't always the way I'd like it.

There are a two other tools for creating EPUB books that I find useful. One is <a href="http://www.methods.co.nz/asciidoc/">AsciiDoc</a>, which consists of a lightweight markup language and tools for converting that language into formats like HTML, PDF, and EPUB. The other is <a href="http://johnmacfarlane.net/pandoc/">Pandoc</a>, which is a pretty much a Swiss Army Knife for converting between markup formats -- for example, Markdown to EPUB.

Ah! The man himself is in the thread!

Scott, I'm assuming you use something like <a href="http://code.google.com/p/sigil/">Sigil</a> to edit your ePub CSS. Is that correct?

For the most part, I use Sigil. If not, I use a nifty feature in Calibre called <b>Explode Book</a> (which I describe in <a href="http://scottnesbitt.net/ubuntublog/?p=1371">this post</a>) and modify the CSS file in a text editor.

Good article. It pretty well reflects my own experience, as I used LibreOffice and Writer2ePub to produce my own free eBook: Green Comet. If you want to see what it looks like, you can download it at http://greencomet.org . It's under a Creative Commons license, so you're encouraged to take it enjoy.

Writer2ePub certainly made the job much easier than it could have been, and I didn't mind having to work through the little gotchas and work-arounds. I learned a lot and I'm grateful to its author. I always make sure to include a credit to it in the final product.

rjb

Good article. But do not forget LaTeX as a high quality composer and the toolchain TEX4ht,XSLT and ANT to transform .tex to ePub.

There is a paper "LATEX to ePub" by Rishi T. that tell how to transform LaTeX to ePub using those tools.

Best regards.

I'd like to suggest the free software Alkinea to convert your book from OpenOffice or LibreOffice to Kindle and/or ePub.
It exports many things that are specified in the OO styles, like margins (all sides), indents, pictures with captions and wrapping, dropcaps etc.
It also offers the option to convert the headings to pictures, allowing to use a nice font for the chapter titles. This helps to make the ebook reading experience as enjoyable as a real book.
You can get it here:
http://soft.alkinea.net
It's free for commercial and personal projects.

This tool looks interesting, but is it open source? I scoured the website for licensing informaiton to no avail.

I did too and all I found was one reference to "free software," which could just mean freeware.

rjb

Given the fact that the downloads for the Linux version and the portable Windows version don't even have a license file (or a readme, or anything really), I'd assume it isn't open source. The linux zip file just contains an executable file and the Windows portable version has an exe and a few dlls. Pretty safe to say that it is free/gratis, or donation-ware to be a little more accurate, but not free open source.

Quite frankly I get sick of hearing the free vs open software BS. It doesn't matter which one it is.

In the end all that matters is that it works for you. Regardless of how some people choose to clasify a particular piece of software, if it works, just use it.

The appeal to pragmatism. Maybe it doesn't matter to you, and if it truly doesn't then go for it. But your preference isn't all that matters in the end. There are other people on the planet and it does matter to some of us. You'll just have to learn to forgive us if our principles annoy you.

rjb

Thank you for the interest!
The software is not yet open source, but it might be in the near future. For the moment it's free as in: just use it for free, on your commercial or personal projects.
There are no guarantees on the result, but the developer (myself) will be happy to fix any issues, so don't hesitate to contact him (me).
Although it is in beta, the software has already been used on many books.
I will make it open source if I feel there is an interest from the community.

There is another plugin to convert ODT to ePub: http://elaix.org/

I wrote a how-to in German: http://literatur.hasecke.com/news/e-books-mit-libreoffice-produzieren

Another option to produce ebooks alongside with a printable PDF and a Website is Sphinx: sphinx.pocoo.org.

I wrote something about this in English: http://www.hasecke.eu/Members/juh/sphinx-a-tool-for-self-publisher

Just for completeness sake: you can also use AsciiDoc to create ePub as described in <a href="https://opensource.com/life/13/9/create-ebook-AsciiDoc">this article on opensource.com</a>.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.