In an earlier post, I talked about Kindlegen and how to make it sing. This post talks about the key to all that singing: the OPF file. The OPF file is essentially a list of things for Kindlegen to do. It consists of three parts: the “manifest.” the “spine,” and the “guide.” You feed the OPF file to Kindlegen rather than the HTML file. Let me demystify the OPF file.
First of all, an OPF file is just a plain old ordinary text file. You DO NOT create it with your word processor. You create it with a text editor. If you are running Windows, you have Notepad (dreadful) and Wordpad (not quite so dreadful) available at your fingertips. I use TextPad. Lots of people use Notepad++.
The OPF file is an XML file, so it has some stuff in the header:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="tut">
Notice right off the bat that I created my own value for the ‘unique-identifer.’ It doesn’t matter what it is, just be consistent between files.
We now come to the metadata. The word “metadata” means data about data. Sort of data-squared. The metadata starts with, appropriately enough, a metadata tag:
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
Don’t worry what it means, just pick it up verbatim and put it in your file.
Now you need to add some metadata. You can probably figure out what to do from context:
<dc:title>The Unexpected Traveler</dc:title>
<dc:language>en-us</dc:language>
<meta name="cover" content="my-cover-image" />
Obviously your title goes in place of mine (The Unexpected Traveler). Copy the next two lines after the titleline verbatim. The line about the cover is just a prelude to actually telling it what the cover image is.
<dc:identifier id="tut" opf:scheme="ISBN">9781375890815</dc:identifier>
Use that line only if you have an ISBN. Hint: for a Kindle book, you don’t need an ISBN.
<dc:creator>David Casler</dc:creator>
<dc:publisher>Mt. Sneffels Press</dc:publisher>
<dc:subject>Fantasy</dc:subject>
<dc:date>2012-03-01</dc:date>
<dc:description>The best fantasy novel you've ever read!</dc:description>
</metadata>
Obviously you’ll put your own data in there. The date is the book’s release date. And you’ll want to make your description longer—think of it as the description that goes on the back cover. You close the metadata with the </metadata> tag.
The next element is the manifest. Now this doesn’t mean “manifest destiny” or anything so magnificent. It’s just a list. A list of the cargo on a ship is called the ship’s manifest. That’s where the word comes from: blame the shipping industry. But it’s just a list. You start it and close it in the usual way:
<manifest>
What comes after is your list of HTML files. Note that I split my HTML into three parts: the front matter, the table of contents, and the rest. Each gets a mention in the manifest.
<item id="front_matter" media-type="application/xhtml+xml" href="tut_front_matter.html"></item>
The “front matter” is everything from the cover up until the start of the table of contents. Next, I pulled out the table of contents into its own html file:
<item id="item1" media-type="application/xhtml+xml" href="tuttoc.html"></item>
And now comes the rest of the book:
<item id="item2" media-type="application/xhtml+xml" href="tut.html"></item>
Now comes your cover image. In this case, you copy the tag verbatim except you put the file name of your cover image. In this case, I have a concept image that I’m using for testing. (You need to change JPEG to GIF if you’re using a GIF cover image.)
<item id="my-cover-image" media-type="image/jpeg" href="Brett_Concept.jpg"/>
Now this next part is very important. It looks like a table of contents. But, no, it’s an NCX file, which is the subject of another post. Note again that you keep everything verbatim except the actual file name.
<item id="toc" media-type="application/x-dtbncx+xml" href="tutbas.ncx"/>
</manifest>
Okay, the next part is the spine. The spine tells Kindlegen in what order you want things to appear. (Aha, you think, didn’t the manifest convey that information? No. The manifest is just a list. Not an ordered list. Just a list.)
<spine toc="toc">
<itemref idref="front_matter"/>
<itemref idref="toc"/>
<itemref idref="item1"/>
<itemref idref="item2"/>
</spine>
The careful observer will note that the idref tags refer to id items in the manifest. Make your items match accordingly. Note especially here that you can break up your book into chunks to make handling easier. For example, each chapter can be its own HTML file. The spine section sets the order so that Kindlegen can sew things together.
Now there’s just one last thing, the guide section. You’ll note a suspicious relationship between the items in the guide section and the navigational items found on a Kindle or Kindle App. Specifically here we tell Kindlegen that the Table of Contents is actually the Table of Contents that it’s looking for. Further, the Welcome is actually the place to which Kindle first opens the book, usually at the beginning of the first chapter.
<guide>
<reference type="toc" title="Table of Contents" href="tuttoc.html"></reference>
<reference type="text" title="Welcome" href="tut.html#start_here"></reference>
</guide>
We now close the file:
</package>
What could be simpler? (I’m laughing through gritted teeth. It took me hours to figure all this out. Hopefully my notes are a helpful adjunct to Amazon’s rather inadequate explanations.)
I'm a member of the Church of Jesus Christ of Latter-day Saints, or more commonly known as the Mormon Church. There's lots of misinformation out there about the Church. Why not check out
I'm a ham radio operator, callsign KEØOG, Amateur Extra Class, and a member of the American Radio Relay League. See my
I'm an engineer and a member of the 

This reply covers four things: 1 – Thanks, 2 – A Problem, 3 – A Solution, 4 – A Question
1 – Thanks: I’ve spent over a week scratching my head and other parts of my anatomy trying to figure out how to assemble my book through Kindlegen and get the navigational tools to navigate to the cover and the Table of Contents. Your blog helped me over the hump. THANK YOU!
2 – A Problem: I have Word 2003. I took my book file and broke it into 3 parts, as you suggested on your blog. But when I extracted my original table of Contents (TOC) and made a separate TOC.html file, I lost all the links. Even when I edited the links with long path names, it didn’t work right; the links were broken. I was rethinking the syntax when I got the following solution:
3 – A Solution: I still used 3 html files as you suggested, BUT I kept my toc in the 3rd file. I made the second file a “contentless” html file. I figured kindlegen would build nothing from it and then tack on the real Table of Contents from the third file. The actual code of the second file is as follows:
<html><head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>Heidi’s Hope</title>
</head>
<body lang=EN-US>
</body>
</html>
Other changes I made to the OPF file were as follows: 1 – I removed the line which specified the NCX file, and 2 – I took the toc reference out of the spine. The spine code is as follows:
<spine><itemref idref="part1f"/>
<itemref idref="part2t"/>
<itemref idref="part3m"/>
</spine>
“where “part1f” is the front end material, part2t” is the contentless htlm file described above, and “part3m” if the main file containing the Table of Contents and the story.
With these changes, I ran the OPF file through KindleGen and the resulting prc file was successfully built with no errors or warnings. Most importantly, the navigational tools work when I run the prc file through my Kindle For PC application.
4 – A Question. Is it true that the prc file is COMPILED? I hope that it is. The way I see it, if the prc file is compiled and it works correctly on the kindle today, then it should work on the kindle tomorrow or 5 years from now. Would you agree?
God’s Grace, and thanks again!
Stephen Goss
Author of HEIDI’S HOPE
available now (in book form) on Amazon
Kindle version pending
You are a life saver. Thanks so much for saving me sooo much time!
Well, not actually twice. You can skip the NCX file if you wish. But there’s a feature on some Kindles that can take advantage of the NCX file. It would seem that one ought to be able to create a single HTML file and have it tell Kindlegen what the cover is and what the TOC is. But, alas, I have figured out how to make the single file tell Kindlegen what the cover image is, but not what the TOC is, hence the need for the OPF. I created the TOC in Open Office and told it to make all the entries be hyperlinks. Then I created the HTML file, then yanked the resulting HTML for the TOC out into a separate file, then “manifested” them in the OPF. To me it all seems absurdly complicated. However, we have to deal with the world the way it is, not the way it should be!
So you need to have the toc twice? Once as html file for display (item1 in your case) and once as ncx file for kindle itself (toc in your case)?
Can’t the html toc be contained withing the html file for the book? This way it could be tested just by opening the html file in a browser and clicking.