Kindle preparation part 2 – the files

Share this...

Contents of epub file
Contents of epub file

Last time I looked at the basic principles of a Kindle mobi or general epub file. This time I’ll be focusing a bit more on what the different ingredients do. We’ll also start to uncover a few more places where Kindle and epub handle things differently. For reference, here is a sample set of files you need for an epub book – Kindle is essentially the same but some “administrative” bits are inserted automatically by KindleGen so you don’t need to worry.

Somebody who uses Microsoft Word or some similar software to construct their book may find the following paragraphs confusing, since they will probably never have needed to address this directly. But under the bonnet this is what is happening with your book preparation, and many years of technical software and QA work has convinced me it’s better to know rather than not know. At very least this may help diagnose when something goes wrong!

Preamble / metadata section of opf file
Preamble / metadata section of opf file

So, the key ingredient is the opf file which ties everything together. It has four main sections. The first is Metadata – a general information section containing things like author name, book title, publisher, ISBN (if any), price, brief description, and so on. The kind of detail you might expect to see on a library card or catalogue entry. I’ll be giving specific examples of the different files later in this series but for now want to concentrate on principles rather than details. There are also some important places where you have to ensure that a reference in one place matches one somewhere else – again, I’ll return to this.

Manifest section of opf file
Manifest section of opf file

The second section is a list of resources – the Manifest. For epub this must be complete, and although KindleGen is clever enough to fill in some gaps, it is good practice to be thorough here as well. So this identifies all content files, any separate style sheets, all images including cover, the ncx navigation file, and anything else you intend to include. But it’s a simple list, like the ingredients for a recipe before you get to the directions, and this section doesn’t tell KindleGen or an epub reader how to assemble the items into a book.

Spine section of opf file
Spine section of opf file

The third section – the Spine – does this work of assembly. It lists the items that a reader will encounter in their correct order. This section turns your simple list of included items into a proper sequence, so that chapter two comes after chapter one. Here you also link in the ncx file so it can do its job.

Guide section of opf file
Guide section of opf file

The final section – the Guide – defines key global features of the finished book. For example, this is where you define the cover, the HTML contents page, and the start point – the place where the book opens for the very first time, and the target for the navigation command “Go to Beginning” (or equivalent). It’s worth remembering that the start point doesn’t have to be the first page – many books set this after the front matter, so that you skip over title pages and such like and begin at the beginning of the actual story. But be warned that following a scam to do with counts of pages read, Amazon does not take kindly to people putting the start point too far through the book.

epub treatment of png and gif transparency
epub treatment of png and gif transparency

Images can cause unexpected problems. The opf file expects you to supply not just a file name, but also the file type, such as jpeg, png or gif. And here we encounter one of those annoying differences between devices. Kindle accepts png files along with jpeg and gif, and many people are used to the convenient feature of the png format that it allows transparency. A png with transparency will – usually – take on the background from whatever happens to be behind it, like the page background for example. An epub file will do exactly this if you use coloured background.

Kindle treatment of png and gif transparency
Kindle treatment of png and gif transparency

But KindleGen does not. You can supply a png file successfully, but internally it will be converted to jpeg format… and jpegs do not allow transparency. The background will be converted to white, and the final effect will not be what you hoped for. The way round this is to use gif images if you want transparency, but since this is an old format many people do not suspect that this is necessary.

Now, sometimes this won’t matter – for example if you want to insert a map, and have it look as though it is on white paper. But other times it looks decidedly odd, when it is intended to be just a logo or divider symbol. It’s a thing which particularly catches out those who are used to printed books, or older Kindles which only supported black-and-white. It’s not very long since I discovered this hidden conversion png -> jpeg that KindleGen does, and as a result expanded my pre-publication testing considerably.

A couple of closing comments about the files themselves. The contents files ought to be valid HTML – this sounds obvious, but most browsers, and KindleGen, are very forgiving about syntax errors, so people often forget to be careful. But although the output file may be generated, such errors can lead to surprising changes of appearance between paragraphs. It is good practice to use the w3.org online validator to check this – it’s completely free, and will either confirm that the file is valid or else tell you what’s wrong and how to fix it. Alternatively, once you have built an epub file, the free epubcheck utility will do a similar job as one of its several checks. (I’ll come back to epubcheck when I talk about building an epub file). Other than that, you are at liberty to split up content however you like – all in a single file, or one per chapter, or whatever. It’s up to whatever you find convenient (though a few epub apps load just one file at a time so you might notice a slight delay every now and again while reading).


Share this...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.