E-Book Enlightenment

Making EPUBs

e_books.png

Of all the formats for e-books only EPUB combines small file sizes with the ability to do formatted text and illustrations.  An EPUB is like a website contained in a Zip file, with a Table of Contents attached.  It is also in one important way different from a website.  A website is made with HTML (usually) but an EPUB is made with XHTML.

The difference is small but crucial.  HTML is meant to be forgiving.  If you make a web page you can leave out some tags, fail to close tags, or close tags in a different order than you opened them in.  A web browser is supposed to forgive that, as much as possible.  XHTML, on the other hand, is like HTML that is not forgiving.  You can't leave out a tag or put in a tag where the XHTML browser does not expect it.  If an XHTML browser discovers an error in your page it can simply refuse to display it.

The end result is that an XHTML browser is easier to make than an HTML browser.  A lot easier.   It does put a burden on the e-book author to get his tags right, but in practice you'll never create an XHTML file by hand.  Instead, I recommend that you use the free e-book editor Sigil, shown here editing The Galaxy Primes by Edward E. Smith:

Sigil in action

Sigil is available for Windows, Linux, and the Macintosh.  You can download it here:

http://code.google.com/p/sigil/ 

There are installers for all three platforms.  On Windows the installer can be a little flaky.  It is supposed to install a Visual C++ runtime component if it is needed but it doesn't always do that.  If you have problems check the FAQ on the website, which explains how to work around the problem.  The installer on Linux worked fine, and I would recommend using that instead of compiling Sigil from the source code.

To create your EPUB you'll start by creating an HTML file with your word processor using the Save As... option from the File menu.  As before, I recommend Open Office but MS Word will do.  When you add this HTML file to Sigil under the Text folder it will run a piece of code called HTML Tidy that will convert your HTML into XHTML automatically.  After that you can split your book into multiple chapters, create table of contents entries, add images, etc.  Here is the Boy's Aviation book being edited using Sigil.  The Ch button on the toolbar is used to split the file containing the entire book into separate files for each chapter.  When you make the title of a chapter have the Heading 1 style Sigil puts the chapter in the Table of Contents for the book.

Sigil Boys Aviation

You can easily add pictures to the book by cropping them out of the original page images, but they should probably be resized to be 600 pixels wide for best results.

Here are a couple more screen shots of the EPUB I made with Sigil being read in the Read Activity:

Read EPUB

In the Read Activity you can change the size of the text using the View tab, but the illustrations stay the same size.

Read EPUB

 

Making A MOBI For The Kindle Store

If all you want to do is convert an EPUB you have made to read on a Kindle it is quite simple.  All you need to do is download the free kindlegen utility (available for Windows, Linux, and the Mac) from Amazon.com and run it against your file like this:

kindlegen BigBookOfAviationForBoys.epub

While this will give you a perfectly usable .mobi file for your Kindle it will not be in the format required by the Kindle Store.  If you've created a book as a class project and want to have a Kindle format available for parents, this may be sufficient.  However, with only a bit more work you can sell your book to the world.

What your book is lacking that the Kindle Store requires is:

  1. A cover image
  2. A linked table of contents page

The cover image is simply a JPEG file that looks like the front cover of a book.  You can easily create a nice book cover image with The GIMP.  Here is one I made for another book:

Note that because the image has a white background I put a gray border around it.  You'll need this image for the Kindle Store page as well as for the book itself, and the grey border is needed to make the book cover stand out against the white page background.

You can then insert this image into the EPUB without actually showing it on any page.

The table of contents is simply a page that links to the chapters in your book.  Neither Booki or Sigil supports creating a page like that, but that's easily solved.  What you need to do is extract your EPUB files into a directory with any utility that supports Zip files.  When you have everything unzipped you'll see a bunch of files with .xhtml suffixes.  As you might expect, these are simply web pages, which you can edit with any HTML editor.

The Mozilla project has a product called Seamonkey which combines a web browser, an HTML editor, and an email client.  This can be downloaded for free from mozilla.org in versions for Windows, Linux, and Mac OS, and it's perfectly adequate for creating your table of contents page.

Look for a file named content.opf.  Using a text editor add the entries in bold to the top of the file to be like this:

 <metadata>
   <dc:publisher>FLOSS Manuals</dc:publisher>
   <dc:rights scheme="License">GPLv2+</dc:rights>
   <dc:language>en</dc:language>
   <dc:title>Make Your Own Sugar Activities!</dc:title>
   <dc:creator>James D. Simmons</dc:creator>
   <dc:date>2010-11-28</dc:date>
   <dc:date scheme="start">2010.12.09-07.20</dc:date>
   <dc:date scheme="last-modified">2011.05.13-00.00</dc:date>
   <dc:date scheme="published">2011.05.13-18.25</dc:date>
   <dc:identifier id="primary_id">ActivitiesGuideSugar/2010.11.28
   </dc:identifier>
   <dc:identifier scheme="booki.cc">make-your-own-sugar-activities
   </dc:identifier>
   <meta name="cover" content="att000_MYOSA_Cover" />
 </metadata>
 <guide>
       <reference type="toc" title="Table Of Contents"
           href="table_of_contents.xhtml" />
 </guide>

  The toc entry point to another entry in the file that should look like this:

    <item href="table_of_contents.xhtml" media-type="application/xhtml+xml" id="table_of_contents"/>

If you created a new page with your HTML editor (instead of editing a page that was already in the EPUB) you'll need to add an entry like this yourself.  There should be a similar entry for your cover image if the image is included in the EPUB.

If everything looks good you can use your Zip utility to create a new archive with all these files in it.  Change the suffix from .zip to .epub and you'll have a file you can run kindlegen against to create a MOBI file that the Kindle store will accept.

When you run kindlegen, do pay attention to the messages it gives you.  If it cannot find your table of contents or cover image it will tell you.  Also, be sure to try out your file with the free Kindle Previewer program.  There are versions of this for Windows and the Macintosh, and the Windows version will run under WINE on Linux.  This program will show you what your book will look like on a real Kindle.  The formatting that a Kindle will support is a subset of what HTML supports, so it is likely you'll need to modify some pages to make them look right on the Kindle.  The web page version of this book has beautiful drawings with transparent backgrounds at the top of each chapter.  They looked quite awful on the Kindle version so I had to remove them.

Having a book on the Kindle Store is not an easy path to riches.  The first two weeks my book Make Your Own Sugar Activities! was available it sold seven copies.  These meager sales were enough to make my book ranked 60,425 out of over 750,000 books, making me one of the top sellers on the Store!

The Kindle Store will let you publish public domain works as well as your own writings.  I have created e-books from a couple of books in my personal collection: Ancient Manners by Pierre Lou├┐s and The Big Book of Aviation for Boys.  I decided to sell them on the Kindle Store as well as donate them to the Internet Archive and Project Gutenberg.  While Ancient Manners did quite well its first week on Project Gutenberg it has yet to sell a single copy on the Kindle Store.

The Big Aviation Book for Boys almost ended up getting rejected by the Kindle Store because I could not prove conclusively that it was in the public domain.  I had also posted the EPUB and MOBI files on the Internet Archive, so the work would not have been totally wasted.