How to Create an Ebook, Part 5:
Assembling the Ebook

An ebook is essentially a zip file, or compressed file, that contains all of the folders and documents you have created.

There is one difference between an ebook zip file and a normal zip file: the mimetype document must go into the file first and must not be compressed, or the ebook won’t work.

The method of assembling the ebook will differ according to the operating system you are using.

Ebook Zip Files with Windows

Perhaps surprisingly, the most painless way to do this is to use a Windows machine.

  1. Navigate to the location you have chosen for your ebook.
  2. Right–click and select the option, ‘New Compressed Folder’.
  3. Give the folder a name. Leave the extension, .zip, unchanged. When you name your zip file, you may like to add a number to the end. The name might be something like ebook01.zip. It is likely that you will need to perform the process more than once to get it right, and numbering the versions will allow you to keep track of them. You will be able to change the name once the ebook has finally been created to your satisfaction.
  4. Copy the mimetype file and paste it into the zip folder.
  5. Copy the META–INF folder and paste it into the zip folder.
  6. Copy the OEBPS folder and paste it into the zip folder.
  7. Right–click over the zip folder and select ‘Rename’.
  8. Change the extension from .zip to .epub. You will probably see a message warning you that the folder may not be usable if you change the extension. This is normally good advice, but in this case it does not apply. Ignore it and rename the extension.

You may paste the OEBPS folder before the META–INF folder if you prefer, but it is essential that the mimetype file goes in first.

If your version of Windows does not display the file extensions, you will need to delve into the system’s settings. The precise location may vary with different versions of Windows, but try going to My Computer then Tools then Folder Options then View. There should be a tick box (check box, if you are American) next to the option Hide extension for known file types. Untick the box, and the file extensions should become visible.

Ebook Zip Files with Mac and GNU/Linux

Although all modern versions of Windows include a zip program that makes compiling an .epub file easy, that isn’t currently the case for users of non–Windows systems. Macintosh and GNU/Linux operating systems often include similar programs, but these programs behave in a different way to their Windows equivalent, usually by automatically compressing the mimetype file, which will cause the ebook not to work. Users of these systems will have to try a more direct method: the command line.

Typing commands into a terminal is an activity unfamiliar to most computer users, but it should not cause any problems if you follow these instructions. Both Macintosh and GNU/Linux operating systems are based on Unix, so the procedures for each ought to be very similar, if not identical.

The first thing to do is to open the terminal. The easiest way to do this is to hold down the CTRL + ALT + T keys. Other methods may be available, depending on your particular version of operating system: e.g. clicking on Applications then Accessories then Terminal.

Using the Terminal

The following method works for GNU/Linux users:

  1. Tell the system where the ebook’s files are situated. I’ll assume for the purpose of this example that you are logged into your computer as sausages, and that your ebook files are stored in your personal directory in a folder called ebook. Type the following line of code into the terminal, adjusting the names and location according to your situation:
    cd /home/sausages/ebook/
    Note that there is a space between cd, which stands for ‘change directory’, and /home/.
  2. Create a zip file called ebook01.zip containing the mimetype file, by typing the following code:
    zip -X -0 ebook01 mimetype
    There are two bits of code whose meaning is not obvious: -X, with a capital X, ensures that nothing is added to the plain mimetype file, and -0 (dash zero) sets the amount of compression to zero.
  3. Add the META–INF folder to the zip file:
    zip -9 -r ebook01 META-INF
    Here, -9 ensures that the META–INF folder is compressed as much as possible, and -r ensures that all the files within a folder are copied along with the folder itself.
  4. Add the OEBPS folder to the zip file:
    zip -9 -r ebook01 OEBPS
  5. Rename the zip file, by typing:
    sudo mv ebook01.zip ebook01.epub
    To allow the sudo command to work, you will be asked to type your password. For more about the sudo command, which can be dangerous if misused, see https://help.ubuntu.com/community/RootSudo. mv stands for ‘move’, and because you’re moving the file to the directory it’s already in, mv results in the file being renamed. You can, of course, adapt this line of code to change any part of the ebook’s file name, not just the extension. For example:
    sudo mv ebook01.zip war-and-peace.epub
  6. Return your system to its default working directory, by typing:
    cd ../..

Here is the full code:

cd /home/sausages/ebook/

zip -X -0 ebook01 mimetype

zip -9 -r ebook01 META-INF

zip -9 -r ebook01 OEBPS

sudo mv ebook01.zip ebook01.epub

cd ../..

Depending on where your ebook files are stored, you may be able to omit the first and last lines. If your system allows it, you may be able to drag and drop or copy and paste the META–INF and OEBPS folders, and rename the zip file, without using the command line. As far as I’m aware, however, the mimetype file won’t function correctly if it is added by dragging and dropping or copying and pasting on anything other than a Windows computer.

Using the Terminal on a Macintosh

There are other ways to achieve the same result, some of which may be more efficient than the method set out above, but this works for me, and ought to work with any version of GNU/Linux. I haven’t tried to create an ebook using the terminal on a Mac, but the procedure ought to be the same.

If these instructions don’t work with your computer, or if you find using the command line too intimidating, the easiest solution is to get hold of a Windows machine, and use that instead. If you are a GNU/Linux user, you may already be familiar with the command line. If you are wealthy enough to own an extortionately expensive but nice and shiny Mac, you can just send a couple of your servants out to buy a PC, but of course not before they’ve finished cleaning out your stables and polishing your private jet.

Checking the Code

Before you let your ebook loose on your grateful readers, you must check that everything works correctly. Go to http://validator.idpf.org/ and run your .epub file through its validator.

Be prepared for a long list of errors! Even one missing tag will cause problems. You will be surprised how easy it is to forget a closing </p> tag. Any errors will be listed with their line numbers, so at least they will be easy to find.

Correct any errors in your main ebook folder. Create a new .zip file with a new number, such as ebook02.zip (or ebook27.zip, as the case may be), and copy the revised files and folders into it. Eventually, you will get it right. Once you get it right, your ebook will be finished, and you can get on with hammering out a film deal with the big Hollywood studios and writing your acceptance speech for next year’s Nobel prize for literature.

The Amazon Version

The ebook you have just created in .epub format will need to be converted into one of Amazon’s proprietary formats if it is to be read on any of Amazon’s devices, which, at the time of writing, do not recognise the EPUB standard. There are two methods:

  • If you sign up with Amazon to sell your ebook with them, all you need to do is log in, follow the relevant links, and upload the ebook in EPUB format. Amazon will take care of the rest.
  • Windows and Mac users may download Amazon’s Kindle Previewer software free of charge from http://www.amazon.com/gp/feature.html?docId=1000765261. It is quite a sizeable file, which at the time of writing is not available for operating systems earlier than Windows 7 or Mac OSX 10.9, and not available at all for GNU/Linux systems. This program will allow you to see how your ebook looks on various Amazon devices, and will convert your EPUB ebook automatically and store the copy on your computer, so that you can sell a Kindle–friendly version of your ebook independently of Amazon’s website.

Good luck!

[This tutorial is part 5 of a series by Jeremy Bojczuk, showing you how to code an ebook.]