Making an EPUB File

We have discussed most of the types of files that occur in an EPUB document. The main content is contained in the HTML files. The appearance can be modified by using CSS style files. The other files are organizational. It is useful to have both an NCX table of contents and an HTML table of contents. The HTML table of contents contains links to the various sections of the document and can be seen as you page through the document. An example HTML table of contents is shown below.

<html xmlns="​1999/xhtml" xml:lang="en">


<title>Table of Contents</title>


p {margin-bottom: 1em; text-align: left}

p.ind {margin-left: 2em;}




<p><a href="intro.html">​Introduction<​/a></p>

<p><a href="chap1.html">Chapter 1</a></p>

<p><a href="chap2.html">Chapter 2</a></p>

<p class="ind"><a href="chap2.html#sect1"> ​Section 2.1</a></p>

<p class="ind"><a href="chap2.html#sect2"> ​Section 2.2</a></p>

<p><a href="chap3.html">Chapter 3</a></p>

<p><a href="chap4.html">Chapter 4</a></p>

<p><a href="chap5.html">Chapter 5</a></p>

<p><a href="refs.html">References ​ </a></p>



This code will produce the following table of contents


Chapter 1

Chapter 2

Section 2.1

Section 2.2

Chapter 3

Chapter 4

Chapter 5


You can also have an HTML cover page if you wish. This is a standard XHTML file with the cover image specified in the tag

<img src="…" alt="…" style="height: 100%;" />

The size requirements for covers change fairly often, so it is best to check with the publisher for the current requirements. The last I heard Amazon wanted a 1688x2700 pixel Jpeg image.

The final step in making an EPUB document is to zip the files into a file with extension .epub, e.g., MyBook.epub. There is one caveat. The file mimetype must be the first file added and it must be placed in the EPUB file uncompressed. Not all zip programs do this easily. One program that does this is the info-zip command line program zip.exe that can be downloaded from the site​archive/zip64/ or from the site​index.php?tool=zipunzip. To add mimetype to the file MyBook.epub you would use the command

zip MyBook.epub -DX0 mimetype

To add the remaining files you would use

zip MyBook.epub -rDX9 META-INF OEBPS

At this point is a good idea to validate your epub file. You can do this online at or you can download a java command line validator at​epubcheck/releases/.

You can put aliases for the zip commands (used in building EPUB file) in a file init.bat. If zip.exe is stored in the directory e:\utilities, then we insert the following commands in init.bat

doskey zipnc=e:\utilities\zip.exe $1 -DX0 mimetype

doskey zipc=e:\utilities\zip.exe $1 -rDX9 META-INF OEBPS

If you downloaded the epubcheck validator, you can put an alias for it in init.bat, i.e.,

doskey val=java -jar e:\utilities\​epubcheck\epubcheck-3.0b4.jar $1

where you need to use the correct path for the jar file you downloaded.

Now running init.bat in the command window will replace the zip commands by zipnc and zipc,and the epubcheck command will be replaced by val. We next modify the registry so that init.bat will run automatically every time a command window is opened. We run regedit from the start menu to open the registry editor. We then navigate down the tree to the key

HKEY_LOCAL_MACHINE\​SOFTWARE\Microsoft\​Command Processor

We then enter a new string value whose value name is AutoRun and whose value data is c:\MyFolder\init.bat. Of course, you need to substitute the path to init.bat for c:\MyFolder. It is necessary to restart the computer in order for these settings to be incorporated.

A good viewer for EPUB files is Adobe Digital Editions. It can be downloaded at​digitaleditions.