Monday, 12 December 2011

How to create an NCX file for a Kindle e-book

While this post is not related to the 'Merdeka' story, it does share how I built the 'Merdeka' e-book in a format that now (hopefully) allows NCX functionality on a Kindle.  It is aimed at other authors trying to get their self-published e-books into a Kindle ready format.

This advice will only work for you if you have built your manuscript in MS Word (and saved it as a Word 97-2003 document) and also if you are using MobiPocket creator to create the PRC file for your e-book.  It is not my intention to re-invent the wheel and I would like to acknowledge Huw Collinbourne of 'Dark Neon', and Araby Greene of 'CJs Easy As Pie Kindle Tutorials'.
  1. For best advice on how to create a Kindle e-book using MobiCreator and on how to build your own table of contents in MS Word visit Dark Neon.  It is important that you manually create your own table of contents and that you do not allow MS Word to do it automatically.   The bookmarks that you create during this process will be the backbone of your NCX file.  Once you have created your table of contents and linked each heading to its bookmark, you should save your file as a web page, filtered document.
  2. When you have done this you need to build your NCX file.  For advice on how to do this follow the instructions 'Create an NCX File' offered by Araby.  When you copy the base code, remember to add in the name of your document and then input each item exactly as you have bookmarked it.
Once I had done both steps 1 and 2 above, my NCX file was still not appearing in the Kindle Previewer and it was driving me mad.  I am not used to writing code, but I had done so to create the NCX file (using a lot of copy and paste) and I was sure that it was correct.  I had also put the toc.ncx file into the folder for the book created by MobiPocket creator (I renamed the text file in which I created the NCX code as 'toc.ncx' and it worked fine).

So what was the problem?  As I looked and relooked at the code in the MobipocketCreator OPF file (you open it using NotePad to read the HTML).... the penny suddenly dropped.  Reference was being made to Item 1 and Item 2.  In Araby's example there are two HTML files, one for the book and one for the table of contents.  I only had one HTML file for the book (as my table of contents was created within the orginal Word Document).  I then deleted the references to Item 2 in the relevant parts of the OPF file and then re-built the book in MobiPocket Creator and, hey presto, the finished e-book (PRC file) worked perfectly in Kindle Previewer and showed the NCX file.

The examples below show what I took out of the orginal OPF file and what I replaced it with.  There is a lot more code before and after each example, but if you look at your OPF file you should be able to see the bit that needs changing.

ORIGINAL EXAMPLE (Items I deleted from my original OPF file shown in red)

…………metadata></metadata><manifest><item id="item1" media-type="text/x-oeb1-document" href="Mybooktitle.html"></item></manifest><spine><itemref idref="item1"/></spine><tours></tours><guide><reference type="title-page" title="Title Page" href="Mybooktitle.html%23titlepage"></reference>………………



FINAL EXAMPLE (Items I pasted into my final OPF file shown in blue)

………….metadata></metadata><manifest><item id="item1" media-type="text/x-oeb1-document" href="Mybooktitle.html"></item><item id="ncx" media-type="application/x-dtbncx+xml" href="toc.ncx"></item></manifest><spine toc="ncx"><itemref idref="item1"/></spine><tours></tours><guide><reference type="title-page" title="Title Page" href="Mybooktitle.html%23titlepage"></reference>………….



It worked for me and please download 'Merdeka' if you would like to check for yourself.

No comments:

Post a Comment