Formatting Your Ebook for Kindle: .Mobi File Format – .OPF File – Part 5

The final player in our .Mobi drama is the .opf file – Open Packaging Format.  It is what is known as a build file.  The Kindlegen program will use the .opf file to call the other files to generate the .mobi file for your ebook.

NOTE:  When you clip & paste into Notepad ++ the quote marks may get changed to so-called smart quotes.  If so, use search function and replace with straight quotes.  

I’m extremely fond of disclaimers, so here’s a big one:  In the same way that I don’t understand every the facet of the car I drive, the word processor I use, or the cell phone service I employ, I don’t know what every line of this code in this file does, exactly.  I could research it and document it here, but I don’t care.  I know that it works, and all I wanted was a reliable recipe for ebooks.

With that said . . . the entire file, which I have named 3LIESforBlog.opf,  is listed below:

<?xml version=”1.0″ encoding=”utf-8″?>

<package unique-identifier=”uid”>


<dc-metadata xmlns:dc=”” xmlns:oebpackage=””>

<dc:Title>3 LIES</dc:Title>


<dc:Identifier id=”uid”>978-0-9832027-0-7</dc:Identifier>

<dc:Creator>Hanson, Helen</dc:Creator>

<dc:Publisher>DOMINO INK</dc:Publisher>

<dc:Subject BASICCode=”FIC031000“>Thriller</dc:Subject>

<dc:Description>At CIA headquarters, a young officer discovers that terrorists may have commandeered their computer systems to launch an unauthorized mission. Elsewhere, conspirators abduct nine people to manipulate the rules of their game. Two disparate ambitions — Clint Masters becomes the reluctant link in the chain of danger.<br />

Ever since Clint’s almost ex-wife dumped him, he bobs along the Massachusetts coast in a sailboat with his black lab for company. He avoids all forms of technology, a counterintuitive effort for the burned-out founder of CatSat Laboratories. Tired of clutching the brass ring, he needed to untether, step off the corporate treadmill, and smell a flower. Fortunately, he met one, a beautiful, unspoiled woman who doesn’t treat him like a commodity. His relationship with Beth offers more promise than his marriage ever did, even if she is on dialysis for her recovering kidneys, until she disappears.<br />

In spite of the evidence, her family refuses to admit she’s in danger. Without routine dialysis, she won’t survive. As Clint realizes that he loves Beth, damn-near ex-wife Paige sashays back into his life with disturbing news.<br />

While the CIA young gun tracks his quarry, Clint enlists the help of two men to find Beth, a blithe Brit named Merlin, and Todd, his playboy partner-in-tech. But Clint must find Beth before her kidneys fail. And before someone unloads a bullet in his head.<br />





<output encoding=”utf-8″ content-type=”text/x-oeb1-document”></output>


<SRP Currency=”USD“>2.99</SRP>





<item id=”item1″ media-type=”text/x-oeb1-document” href=”3LIES.html“></item>

<item id=”toc” media-type=”application/x-dtbncx+xml” href=”toc.ncx”></item>


<spine toc=”toc”>

<itemref idref=”item1″/>




<reference type=”toc” title=”Table of Contents” href=”3LIES.html%23TOC”></reference>

<reference type=”start” title=”Startup Page” href=”3LIES.html%23start”></reference>



For discussion purposes, I’m skipping down to the line that starts with <dc:Title>.  All the code above that point contains document declarations.  If you want more details, check out the Dublin Core site. They defined the standards and that is what the dc in <dc:Title> stands for.  Other than that, I’m not interested.

But from the <dc:Title> on down, you can start making changes to suit your ebook where the information is in bold.  These <dc: tags are highly self-explanatory and contain the following information, in order: my book title, the language in which the book is written, my ISBN, my name, the name of my publishing Co, and the BISAC code and the genre.

I just noticed that the BISAC code is misspelled as BASIC.  It didn’t throw an error, so maybe it doesn’t matter.  Maybe it’s supposed to show somewhere and doesn’t.  Need to investigate, but not today.

11/15/11 UPDATE:  I recently released my new novel DARK POOL.  In the course of generating my new .mobi file, I corrected the misspelling of BISAC (from BASIC), and it worked just fine.  It’s likely that the prior information was ignored when I misspelled it.  I corrected my 3 LIES files as well.  

Look up your BISAC code. It stands for Book Industry Systems Advisory Committee, and I’ll read up on it some time when I can’t sleep.

Next comes the description of my novel, 3 LIES, and the publication date.

Okay, now back to something interesting:


<output encoding=”utf-8″ content-type=”text/x-oeb1-document”></output>


<SRP Currency=”USD”>2.99</SRP>



There are two pieces you want to edit here.  The Embedded Cover is what a reader who buys your book will see when they use the MENU button on the Kindle and then Go To the cover.  You still need to upload a second file at Amazon so that a cover will show up in the Kindle Store.

I uploaded the same file at Amazon that I embedded here.  To use all the real estate on your Kindle screen, you want an image that is exactly 600 pixels wide by 800 pixels tall.  This will fill the frame and won’t add any white space. I use .png files and .jpg files interchangeably, at least for this purpose.

SIDE NOTE ON COVER ART: When you upload later at Amazon, they allow an image that can be as small as 500 pixels or as large as 1280 pixels on a side.  Again I used the same 600 X 800 file.  The actual space Amazon makes available at the sales page is a square.  For instance, if I copy the image for 3 LIES from the sales page to my hard drive, I get a 300 X 300 square with my rectangular cover art nicely centered amid white space.  If I click on the “see larger image” link and download that, it is 500 X 500.  Whatever you upload, they will shrink to meet their specs, but retain the aspect ratio of the original.  Since I wanted mine to look like a book, as opposed to a square CD cover, and didn’t want the image distorted, I used the same file.  If you search on the MP3 downloads available at Amazon, those covers are usually square.

Moving on, the next item after my embedded cover file is the price.  My novel is set at an affordable price of $2.99 USD.  Ta. Da.

This next line <Demo>3LIESSample.prc</Demo> is a bit of a puzzler.  I’m not entirely sure what it does.  I think it becomes the name of the sample file that is used at Amazon.  Kindles can read .prc files. If anyone reading this has better information on this, please leave a comment. I matched the name of my HTML file with this.  For example, if your HTML file is called JAWS.html, then I would name this piece JAWSSample.prc.  Get in the habit of being sensitive to case, epub formatting can be case sensitive.

Finally we get to the manifest, where your other two files are called out for processing.  You just need to make sure your file name matches exactly here.  Again, I don’t recommend spaces in file names:


<item id=”item1″ media-type=”text/x-oeb1-document” href=”3LIES.html“></item>

<item id=”toc” media-type=”application/x-dtbncx+xml” href=”toc.ncx”></item>


I have no idea what this section does.  It somehow defines the table of contents and the start position within the book.  Other than that, well, you know, if it works, I’m good.


<reference type=”toc” title=”Table of Contents” href=”3LIES.html%23TOC”></reference>

<reference type=”start” title=”Startup Page” href=”3LIES.html%23start”></reference>


I do try to investigate the unknowns because I don’t like to share information if I don’t understand it.  But the time involved in spent in figuring it out, isn’t worth it to me.  I don’t do this for hire.  So if the answers don’t come quickly AND the thing works, I move on.  I’ve got a novel to finish.

The only files I didn’t present are the image files.  I’ll post those on Thursday, since they are purely visual.  After that, we do the deed:  generate a .mobi file from all the odd bits.

Comments? Questions?  Answers?  All are welcome.




p.s  My programmer husband has threatened to properly indent the code on these posts . . .

And if this series has made the formatting process easier for you, please consider purchasing one of my novels for yourself or a thriller lover in your life.  Here are the links:

iBookstore – Amazon – Barnes & Noble

Amazon UK – Amazon DE – XinXii

Other Posts in This Series:

Part 1 – .Mobi File v.s .Epub File Format Overview

Part 2 – .Mobi File Format vs .EPub File Format Overview

Part 1 – .Mobi File Format – HTML Component

Part 2 – .Mobi File Format – HTML – Table of Contents

Part 3 – .Mobi File Format – HTML – The Chapters

Part 4 – .Mobi File Format –  Toc.ncx File

Part 6 – .Mobi File Format – Kindlegen Your .Mobi

Kindle Promises Here

Photo by brendan.lally….away


Click Click Boom ! Share on Facebook0Tweet about this on Twitter0Pin on Pinterest0Share on Google+0Digg thisShare on Reddit0Share on StumbleUpon0Email this to someone
This entry was posted in Kindle Formatting. Bookmark the permalink.

18 Responses to Formatting Your Ebook for Kindle: .Mobi File Format – .OPF File – Part 5

  1. Fred says:

    Funny issue coming up in regards to the content of the <dc:Description> element in the .OPF file. Your example here in the p=1318 installment makes it seem as if pretty near limitless amounts of stuff is OK, so long as each paragraph’s worth is ended with a BR tag.

    But when I use just four medium-length sentences, each terminated by a BR so as to become a super-short paragraph, only the first two of them survive as comments into the KindleGen log report, along with the first 7 characters or so of the third, and none of the fourth.

    Does the log just not capture everything beyond maybe the first 256 characters worth? Or is there an absolute limit on the character count of the content of the dc:Description element?

    [Or, if you haven’t the foggiest idea — why should you, after all — where should I go ask?]

    Many thanks yet again for your supreme helpfulness! Cheers, — Fred

    • Helen says:

      I don’t know the answer to this. I would suggest checking the documentation at Amazon for kindlegen. They wrote it, so they should have a clue even if I don’t :)

      Thanks, Fred!

      • Fred says:

        Fair enough, Helen.

        Have you any idea, though, where all that text specified in the <dc:Description> element is meant to show up, once it’s found its way into the KindleGen-erated .mobi file, and a Kindle tries to read it? I, for one, haven’t the foggiest inkling :-) . And you’re forgiven, too if you’re in the same boat.

        TIA — Fred

        • Helen says:

          I don’t know. A good test might be to leave it out and see what happens.
          I suspect that some of the information in the file may be redundant, but I don’t know for certain. If if cost me anything, I would be more concerned. So far, electrons are still relatively free :)

          • Fred says:

            Leave it out, you suggest, and compare what happens.

            In fact, before I ever put it in, I had left it out. The only difference I could see was that the KindleGen log file omitted any mention of what I’d left out. But in the actual resultant .mobi files I could detect no difference at all, not by eye, nor through the KindleForPC virtual Kindle, nor through an honest-to-G Kindle 3 (w/ keyboard), nor through any of the other virtual Kindles that Amazon makes available to KindleGen users.

            And that’s why I asked you :-) . No matter, I’ll assume it’s something that maybe amazon gets to see, and prizes highly having.

            Cheers, — Fred

        • Helen says:

          Another nested comment limit. . . .

          I have the same wonder about information I sent to Kobo. It doesn’t appear anywhere, but is it useful to some algorithm? Hopefully.

  2. Shannon says:

    Whew. Just want to say BIG thanks. Took me 12hrs to figure all this out (I’m a Mac user… so there were a few things I had to get through “differently”) but your advice and help was incredible in doing what was supposed to be “a real cinch” … *blink* *blink*
    Looking forward to reading your book. Just purchased it through iTunes.
    Keep writing.

  3. Matthew S says:

    The “demo” tag which -if used- must contain a .prc file, allows you to specify an example section of a book (Eg. a sample chapter). I am not entirely sure how the formatting works but the .prc file contains information specifying a .mobi file containing the example section or how to automatically generate the example section from the main book’s own .mobi file (which is then done on-the-fly by the e-tailer).

    The “demo” tag is entirely optional and should be omitted if not being used. Since you do not have a “3LIESSample.prc” file at all the “demo” line should be taken out of your code, so remove the line of code with the demo tag around the .prc file.

    Hope this helps.

    NOTE: This comment was edited by me (Helen) at the request of the author, Matthew. Thanks for taking the time to illuminate this dark little corner of formatting. I appreciate it, sir.

    • Helen says:

      Thanks for the insight. I’m formatting my next book, DARK POOL, for release this week. If time permits, I’ll remove this part of the code and check the results. Even now, I want to review the details from the kindlegen output to see what it did with this ghost file, if anything. I appreciate the comments, Matthew. Thanks!

  4. Vern McGeorge says:

    I love this series. It is helping me immensely with the process of preparing my novel, All Fall Down, for the Kindle. I’m just barely into it, having started at bedtime last night, but I’m liking it so far.

    I have three questions:

    1. Is 3LIESSample.prc a file that you created? If so, how? Underlying this is the question – Can I define where my sample ends?

    2. I’ve got a toc.ncx file that looks perfect (to my eye at least) and an .html file with anchors to match. Does this file need to contain the Table of Contents starting with an anchor defining AllFallDown.html#TOC?

    3. Do you care to offer any wisdom on pricing?


    • Helen says:

      Thanks, Vern, for your kind words and your intriguing questions. AND Congratulations, oh-by-the-way.!

      1. I plead ignorance on this one. I really don’t know what that line of code does. I’ve even made an appeal to anyone who might to please leave a comment for the rest of us. I haven’t been brave enough to leave it out of my file, and it works fine with it. I don’t have time to research it, so I don’t mess with it. I believe the amounts you can show as a sample are determined by the outlet. I believe Kindle allows 10% of the book, whereas Smashwords, you can enter a percentage or make the whole thing free.

      2. I don’t use put the TOC in the nav points within the the toc.ncx file. If I did that, it would send the reader there. The reader can get there easily enough using the Go To function via the Menu key. If you have all the rest of it correct, it will work without using the anchor you suggest. unless you want to force the reader to see your TOC. I don’t.

      3. Wild @ss guesses, perhaps. Wisdom, however is unlikely. I could as easily tell you which numbers to choose in the lottery. I set my price at 2.99 for the 70% royalty. If I thought I could get more, I would. Writing a novel is an enormous effort, as you darn well know, and three bucks for several hours worth of entertainment is an exceptional value. I haven’t gotten to the point where I want to lower my price to .99. But then I’m not John Locke with an e-shelf full of books. My second novel, DARK POOL goes live in October. When I break the top 10 for Kindle, I might have some wisdom to share ;)

      All the best to you!

  5. Kris says:

    The BISAC referencing is important, although I am not sure it fully applies to e-books, yet. Here is the link to the codes,

    Someone apparently goofed up and misspelled it, as you noticed. Kindlegen only takes the BASIC code. If they fix it to BISAC, you should be able to notice your “FIC031000″ disappearing from the DOS report, when you try to compile the book…. see,

    Other than that I had not trouble following your steps and compiling a short kindle. One thing I found is that the Kindle Previewer v.1.5 does a poor job with word wrapping. When I load the .mobi, part of the text goes out of the right border of the simulated Kindle and does not wrap. I tried it on XP, Vista and 7 – same. Kindle for PC is fine. I do not own a Kindle device, so I cannot test it there.

    Thanks again, -Kris

    • Helen says:

      I appreciate your feedback on this. I had a different experience with the previewer. I thought it superior to the Kindle for PC. I’ll be generating another full-length .mobi for my next novel within a few weeks, so I’ll specifically look for the word wrap issue you mentioned. I was using Vista then and will be using 7 this time. For my final pass, I checked the .mobi file directly on my Kindle before uploading it.

      Thanks for adding to the knowledge base. Take care!


  6. Kris says:

    Absolutely great and useful! I am high-tech, Sr. Programmer and Sr. DBA, with many years of experience, Still the Kindle details scare the heck out of me. No surprise consultants keep them out hidden and use them to skin the ordinary customers. Your contribution deserves a praise – same as the explanations of the masked magician! Just kindling. -Kris