In this part we'll be tearing apart an ePub file to look at what's inside, and then starting at the top and working our way down through the list of contents one by one. If you haven't downloaded the template file yet, then do so now, as I'll be using it to describe the contents of a standard iBooks file.
OPENING THE FILE
As I mentioned previously, an iBooks file is just a slightly modified .epub, which itself is just a .zip archive with the extension changed. Consequently, you can open an .epub the same way you open any .zip file. You can either change the .epub extension back to .zip if you want to, or you can just right-click on the .epub and select "Extract" or "Open with" whatever zip program you use. I recommend 7-Zip, which lets you modify the contents of an .epub without changing the extension or extracting the files. You can also just drag and drop new files into it, and delete ones that are in there. Other compression programs might do this too, but I haven't tried them, so you're on your own there.
The other program you'll want is Notepad++, or something similar which has numbered lines and search/replace functions. Don't use Windows Notepad as it doesn't have these features and will totally garble your files. You can use any webpage builder you might have, such as Dreamweaver or whatnot, but since you'll be opening and closing it a lot and often, you'll want something that loads and opens files quickly. Whichever editor you choose, be sure to add it as the default editor in 7-Zip (Tools / Options / Editor) so that you can right-click and select "edit" to open compressed files in the editor without extracting the files.
THE FILE STRUCTURE
When you look inside the template, what you'll see at the root level is one file and two folders (whose contents I'll also disclose here for a complete overview of where we're going:
* NOTE: The com.apple file is now obsolete and no longer included in the template, but is still discussed in the tutorial for the sake reference and backwards compatibility with iBooks 2.0. The previous toc.ncx file has also been replaced with the newer toc.xhtml navigation document, both of which will be discussed in due course.
This is the basic ePub file structure, all of which must be in an iBooks file (except for the custom font), although the names of the content files themselves can be unique to your book project, with the exception of the META-INF folder and its contents, which must be named exactly as shown. And of course there will likely be a whole lot of additional files in there before you're done, possibly including a few varieties not listed here. But more on that later. First things first...
THE MIMETYPE FILE
The mimetype file tells the reading system what type of file it's looking at. If you right-click and select "edit" to open this file you'll see a single line of text:
This tells the device's operating system that the file is an epub/zip archive, which tells it a lot about it's structure that the contents are compressed. You can create this file from scratch in your editor, but you can also just use this one, as they're mostly all the same. The new .ibooks files have a new mimetype:
which I imagine tells the iBooks application to apply a whole new set of rules to the contents. This also technically makes it no longer an epub file, although the general structure is pretty much the same. As an experiment I changed the mimetype the template to this and loaded it into iBooks. The file opened with the super-cool new hardback cover animation, but there wasn't anything else inside, so something else is going on with the new .ibooks code.
If you choose to create your own mimetype file there are three stipulations you must observe:
The best way to achieve these requirements is to create a zip archive with just the mimetype file in it, using no compression when you add it, and then to add in all the other files later, with compression. Encryption is an issue I won't even begin to get into here.
THE CONTAINER FILE
Like the mimetype file, the container.xml must be named exactly that. In addition, it must be in a folder named META-INF, so that the OS knows where to find it. The sole function of the container file is to tell the device where to find the .opf (which seems a somewhat redundant step if you ask me). Looking inside the container.xml file here is what you'll see:
This is the first of many files where we need to explain some things to the computer so it understands what we're saying and what to do with the information.
The first two lines are declarations, stating what language we're speaking and giving a namespace reference (xmlns), which is a specific set of operating rules, more or less:
<container version=1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
Within this is contained the rootfile path, which as I said tells the system where to look for the file that contains a listing of the ebook's contents, and what type of file that is:
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
Looking at our file structure above, you'll see that the content.opf is in the OEBPS folder, just like our path data says here. This file can actually be anywhere and named anything you like, so long as you say so here. The media-type, however, must read exactly as given, since it describes the target's file type, which is an Open eBook Publication Structure (OEBPS) package written in eXtensible Markup Language (XML). We'll talk about the .opf itself later. Be sure to include both the </rootfiles> and </container> closing tags as shown in the image.
THE COM.APPLE FILE
NOTE: This file is no longer required for iBooks 3.0 and newer versions of the app. See Part 8 of this tutorial for full details. Should you want to create an ePub 2.0 file for backwards compatibility, however, you will need to include this file. Therefore, the following discussion is still included here.
This is a file completely unique to Apple's iBooks, which consists of a set of display options that tell iOS devices how to present the content. I've included all of the triggers that I am aware of in the template file, along with some notes (in green) giving the allowable choices. However, the only ones required are these:
The platform name "*" means all devices, with the only two other options being either "iphone" for handheld devices only (including the ipod touch) or "ipad" for tablet only content. This allows you to specify different display options for different platforms. I'll give an example using the remaining options:
So here we have one set of options that apply to all platforms and three that apply only to the ipad. This would create an ebook with a fixed-layout and custom fonts on all devices, but which would only open as a spread on the ipad, and only in landscape mode, and which would have its interactive content disabled on handheld devices (since "true" is only chosen for the iPad and "false" is the default).
Most of these have "true/false" choices, with "false" as the default. Taking them one by one:
As mentioned, aside from the "fixed-layout" option itself, you only need to add in others if they apply to your book. Just leave out the rest. But this gives you some leverage in how your work is presented to the world, which can make a lot of difference.
Lastly, you will need to add the xml declaration at the top of this file:
<?xml version="1.0" encoding="UTF-8"?>
So that's it for the META-INF folder. There are other files that can find there way in here, but none you'll need to mess with, as they mainly involve encryption controls. Some ebooks will put in manifest and metadata files here, but those are best left in the .opf where they belong (and are required). These are all you'll need for now, and that's as far as we'll be going for the moment.