Can Everton Jones find out how his father stole Emperor Bokassa’s diamonds and, more importantly, where he hid them; before the world and his brother get there first?
Click on the picture link in the sidebar to read an extract of my first novel, which was published by Paradise Press in August 2012.

Sunday, 13 August 2017

How to convert an e-pub to Kindle using kindlegen

This series of blogposts has covered everything you need to know about to make an e-pub 2.0 e-book using Sigil and then convert it to kindle. I think some sort of overview is in order, as well as the crucial instructions for actually making the kindle file from the e-pub which, I now realise have not yet been published.

I am finally looking at the new kindle and e-pub formats, and will post when I have got my head around them. I will need more of the newer e-readers and some more antique models to check how this can all be done and how backward compatibility works out in practice. On the surface of it, it seems to me that there are some promising new possibilities, and some features I wanted which will remain impossible.

I think you will want an e-pub which works on all e-readers (including older epub 2.0 e-readers) and also a kindle version. You will end up with TWO e-books, an epub 2.0 e-book and a kindle e-book. However I think both should look and feel the same, as far as possible.

Maybe I should also say that these posts cover making an epub 2.0 ebook, which will work on all e-pub e-readers and a kindle e-book which works with the older kindle e-readers. Any new features in e-pub 3.0 or kindle format 8 will NOT be backwards-compatible, which is to say that an e-pub 3.0 e-book won’t work on an e-pub 2.0 e-reader and a kindle format 8 e-book won’t work on older kindles either. The methods I have described produce a perfectly acceptable e-book, and one which is formatted according to the best practice of the print book industry, adapted to take account of the e-book format and which work on all e-pub and kindle readers in existence. It is a conservative strategy, and misses out on some of the bells and whistles becoming available in the newer formats, but it will produce an e-book which can be marketed the most widely.

As I have said, you want a kindle and an e-pub which look and feel the same. And the problem at the heart of all of this is the Kindle, which will not accept certain CSS and html and will not support certain characters. So make your e-pub using CSS, html and characters which will also work on a kindle and your task is made that much simpler. See my post on CSS which works with kindle for the information about the difficulties I have identified and ways to get around them.

Amazon provide a program, called Kindlegen, which will make a kindle e-book. It uses an e-pub file as the source and chucks out a file in a format called mobipocket (with the extension .mobi). When you upload this file to the kindlestore, it is then converted to their .azw file format complete with copy protection if you want it. Both .mobi and .azw files can be loaded onto a kindle. This post covers how to do this:

So the starting point is an e-pub file. My strong advice is to make this e-pub with the KINDLE metadata embedded within it. (So, for example, use the Kindle ISBN and specify a ‘format’ of ‘mobi’ in the metadata.) I like to put a copy of the back cover of the book at the end of my e-books, complete with a barcode appropriate to the e-book. If you wanted to do the same, you would want to make sure that the back cover has the barcode for the kindle on it. Also make sure that the title-page verso (copyright page) has the kindle ISBN and other information on it. It might seem crazy to be making an e-pub with the KINDLE data embedded in it, but this is going to be converted to a kindle, so it makes sense.

The index at the bottom of this post has links to all my posts on making an e-pub, roughly in the order in which you would need to read them if you were creating an e-book from scratch for the first time.

Once your epub is finished and has passed epubcheck, you will need to make a few adjustments to it for kindle. See my six early posts linked in the next two paragraphs for the details. YOU ARE NOW FINISHED WITH SIGIL. From this point on, ANY changes to your e-book will need to be made with an html editor, such as Komodo Edit.

This now gets complicated, so be methodical. Start with a new folder with your epub in it. Now make a copy of the epub and save it somewhere safe and make sure the folder it is in is carefully labelled as ‘epub with Kindle values’ or ‘Original Epub’ or whatever works for you. Now go back to the first folder and ‘unpack’ the epub. See my post: how to unpack an epub for instructions. Following those instructions will create a new folder with the various parts of the original epub file inside. This folder will have the same name as your original e-book file.

Now you will need to delve into this folder and restructure your html table of contents and then link the html table of contents. Next you need to delete the html cover and then finally link the cover IMAGE. You will also have to delete any <h>tags styled as invisible as described here. Click the links for how tos on all of these. This step is probably the most problematic bit of converting an epub to kindle and took me quite a lot of time to work out how to do it.

Once you are finished, you need to re-pack the folder, restoring it to e-pub format, BUT WITH THE NECCESSARY CHANGES for kindle. YOU SHOULD NOT re-open this file with Sigil, because Sigil will not like what you have done to the file and will try to change it back, with unpredictable and probably either inconvenient or catastrophic results.

How to re-pack your e-book:

In essence, all you need do is to follow the procedure for unpacking your e-book in reverse order. The results of the various processes will depend a little on your operating system, and so this discussion is deliberately vague about where the files will be created. But I would recommend being methodical about naming and storing your files.

The converted e-pub will now be in pieces in a folder somewhere with the same name as the original e-pub. So begin by creating a blank .zip file (archive). In Windows 7, right-click where you want the blank archive and select ‘new ▶ Compressed (zipped) Folder’ from the pop-up menu. Then open the blank archive by double-clicking it. DRAG the various parts of your e-book into the archive: FIRST the mimetype, THEN the META-DATA folder and FINALLY the OEBPS folder. I cannot see a reason why, but it seems to help if the files are zipped in this sequence. This is all you need to do in Windows. On a Mac, you will need to have created a new, blank, archive using BetterZip (or equivalent, see this place in my post on how to unzip an e-pub for details) and, when you have added the various parts of the e-book, save the archive using the ‘save without mac stuff’ option (important).

Now you have to change the extension of the archive from .zip to .epub and ignore the warning. The icon for the file should change to the e-pub icon. If you have not done so already, change the name of the file to the filename you want your e-book to have, and you’re done! The e-pub (converted to Kindle) is now ready to send to kindlegen. NB the actual filename is something of a convenience: e-reader software will look in the <metadata> of the file, locate the title and display this, NOT the filename, which can be different.

Now get yourself a copy of Kindlegen.

Getting Kindlegen:

You can download Kindlegen from here:  which is I hope an address which is not going to change. If it does, just google ‘kindlegen download’ and you should get to a download page very quickly.

SAVE the file which downloads to your desktop (recommended) and extract it. The folder on my desktop looks like this:

The important file inside is ‘kindlegen.exe’. Note the name of the enclosing folder: ‘kindlegen_win32_v2_8’. The version I have on my computer is slightly out of date, you will need the latest one (2.9 at the time of writing). More importantly, the filename of the folder is just ONE WORD with NO SPACES. This matters. The ENTIRE path to kindlegen AND to your e-pub MUST have NO SPACES in any component. In my case, the folder is on the desktop, so the path is: ‘C:\Users\Rod\Desktop\Kindlegen_win32_v2_8’. If you have a user name with spaces in it, then either change it or else create the kindlegen folder on an external drive (say) ‘E:\Kindlegen_win32_v2_8’.

Running Kindlegen:

Although the file is called ‘kindlegen.exe’, your SHOULD NOT double-click on it to run it. You will need to use the command prompt (Windows) or Terminal (Mac). See here in my earlier post on using epubcheck for instructions on how to access and launch these programs.

NB this part of the post has been written quite a bit later then the foregoing and uses kindlegen v2.9 on a Windows 10 machine, rather than Windows 7 which I was using earlier. When I downloaded this new version of Kindlegen, I was a bit worried that it didn’t say ‘Windows 10’ next to the download link. Well, it is a command-line application, and worked just fine on my Windows 10 machine.

Running Kindlegen from the Command Prompt in Windows:

Firstly, open the folder you just downloaded: ‘kindlegen_win32_v2_9’ (or whatever other name the folder downloaded with). Launch the command prompt and superimpose it on top of the folder, so you can still see the icon for kindlegen.exe. Click and drag kindlegen.exe onto the command prompt window (do NOT hit return at this point!):

The filename and path for kindlegen should be copied to the command prompt:


Type a space after it.

G:\Example>G:\Example\kindlegen_win32_v2_8\kindlegen.exe _

Now open the folder with your e-book in it and click and drag the icon for your epub onto the command prompt window in exactly the same way. You need to make sure the command prompt is in the front, so click on it to give it focus. The cursor should be blinking. THEN drag the file.

In the example, the epub I converted was in a folder called ‘Example’ which was on an SD card in my G: drive, so the filename and path was: ‘G:\Example\TheBexhillMissileCrisis.epub’. The comand prompt ended up like this:

G:\Example>G:\Example\kindlegen_win32_v2_8\kindlegen.exe G:\Example\TheBexhillMissileCrisis.epub_

Now that the command has been assembled, you can hit return, and kindlegen should run. In my case the output was:

 Amazon kindlegen(Windows) V2.8 build 0208-797bf75
 A command line e-book compiler
 Copyright and its Affiliates 2013

Info(prcgen):I1047: Added metadata dc:Title        "The Bexhill Missile Crisis"
Info(prcgen):I1047: Added metadata dc:Date         "2014-04-07"
Info(prcgen):I1047: Added metadata ISBN            "9781904585718"
Info(prcgen):I1047: Added metadata dc:Creator      "David Gee"
Info(prcgen):I1047: Added metadata dc:Publisher    "Paradise Press"
Info(prcgen):I1047: Added metadata dc:Rights       "Worlwide Exclusive"
Info(prcgen):I1002: Parsing files  0000021
Info(prcgen):I1015: Building PRC file
Info(prcgen):I1006: Resolving hyperlinks
Info(prcgen):I1008: Resolving start reading location
Info(prcgen):I1049: Building table of content     URL: C:\Users\Rod\AppData\Local\Temp\mbp_7DE_B_7_A_12_3_12B_12B8_1414_1\OEBPS\toc.ncx
Info(pagemap):I8000: No Page map found in the book
Info(prcgen):I1045: Computing UNICODE ranges used in the book
Info(prcgen):I1046: Found UNICODE range: Basic Latin [20..7E]
Info(prcgen):I1046: Found UNICODE range: General Punctuation - Windows 1252 [2018..201A]
Info(prcgen):I1046: Found UNICODE range: Latin-1 Supplement [A0..FF]
Info(prcgen):I1017: Building PRC file, record count:   0000104
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  53.71%
Info(prcgen):I1040: The document identifier is: "The_Bexhill_Missile_Crisis"
Info(prcgen):I1041: The file format version is V6
Info(prcgen):I1031: Saving PRC file
Info(prcgen):I1032: PRC built successfully
Info(prcgen):I1016: Building enhanced PRC file
Info(prcgen):I1007: Resolving mediaidlinks
Info(prcgen):I1011: Writing mediaidlinks
Info(prcgen):I1009: Resolving guide items
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  55.20%
Info(prcgen):I1041: The file format version is V8
Info(prcgen):I15000:  Approximate Standard Mobi Deliverable file size :   0000443KB
Info(prcgen):I15001:  Approximate KF8 Deliverable file size :   0001072KB
Info(prcgen):I1036: Mobi file built successfully

Hopefully the last line will be: ‘Mobi file built successfully’. If there are errors they will be listed.

NB I have NOT updated the output from the earlier draft of this post, so notice that the version of kindlegen in the graphic above is 2.8 rather than 2.9.

The mobi file is created in the same folder as the epub source file:

If you have errors and want to save them to a file for reference, you can find a way to do it in this place in my last post.

Once you have corrected any errors and built a problem-free mobi file, you can now test it on an actual kindle and with KindlePreviewer. (Kindle previewer is also available from Amazon and emulates all of the different kindles. You can download it from here: which is the same place you got kindlegen from.) Once you are happy with it, you can go ahead and upload it to the kindlestore.

I would then go back and make a copy of the folder with the original epub file in it and give it a name like ‘published epub’. You can now edit this using Sigil and change the metadata, title page verso and if relevant the back cover barcode to contain the relevant epub values. Don’t forget to run the edited epub through flightCrew and epubcheck one final time just to be sure there are no issues with the file (click the links for details). When it passes both of these, it can be sent off to Apple or Kobo or your wholesaler or uploaded to your website for download or whatever.

It is important that you retain a copy of the original epub source file in the folder called ‘epub with kindle values’, or whatever else you decided to call it. Should you want to edit your e-book for some reason, you must make sure BOTH new versions are the same. So start with the original epub source, edit that, reconvert it to kindle and then edit the new epub source to reflect the epub metadata etc. If you do issue an update, do consider having a line on the titlepage verso with something like version 1.1 or whatever. If it is a substantial change, you may need new ISBNs.

The process for converting the epub to kindle can be time-consuming. And so you may not want to go back to the epub source and start all over again. If the changes you need to make are very specific, then you could always make them using an html editor. But I would be very careful to get this right. I hope my posts about content.opf will be helpful in this respect.

And finally, I would advise that you make a final check of the metadata wherever it appears in both the mobi and epub versions of your e-book just before hitting the send button and uploading the file for sale. The metadata is extremely important, as it is how the file is identified on computers. In particular, identifying codes, such as the ISBN can, at a cursory glance, look just fine: one ISBN looks much like another. You DO NOT want a mistake in the ISBN, so checking it should be the very last thing you do! (The epub and mobi versions should have different ISBNs! And also bear in mind that the metadata can appear in different places withing the e-book: back cover image, title page verso, content.opf, etc …, so be very thorough!)

And that is the logical end of this series of posts. I have, inevitably left out some things, and will no doubt think of others. A reference post will follow with all the markup and styles I have used. I will also post on how to embed fonts, even though I do not recommend this, just for the sake of completeness. And I will end the sequence with an introduction!

Index to ‘how to …’ posts:

How to ‘unpack’ an epub file to edit the contents and see what’s inside.
How to understand what is inside an epub
How to link the html table of Contents in a Kindle e-book
How to restructure the html table of contents for a Kindle
How to delete the html cover for a Kindle ebook
How to link the cover IMAGE in a Kindle e-book
How to clean up your MS Word file before your get started
How to markup an MS Word file to identify the formats before importing it into an epub
How to create a new blank e-pub using Sigil
How to import your marked-up MS Word file into your ebook using Sigil
How to create and link a CSS stylesheet in an e-book using Sigil
How to replace the markup with CSS styles in your ebook using Sigil
How to style an e-book so it works with the limited CSS styling available to Kindle e-readers
How to understand the syntax of CSS
How to style Small Caps in an e-book
How to split your ebook up into chapters using Sigil
How to sequence your e-book
How to phrase the copyright declarations etc. in an e-book
How to generate the logical table of contents using Sigil
How to understand toc.ncx in an e-book
How to generate the html table of contents in an e-pub
How to style the html table of contents using CSS
How to create an html cover for your epub using Sigil
How to present references and notes in a book
How to use Mark Up to link notes in your e-book
How to present a bibliography in a book
How to use markup to link entries in a bibliography with the notes section
How to index an e-book
How to use the tools in MS Word to create an index
How to alphabetise an index or bibliography
How to adapt the print index in your MS Word file for an e-book using markup
How to adapt cross-references in your print index for e-book and how to use markup to make the links
How to understand content.opf
How to understand and edit the Metadata of an ebook using Sigil
How to understand the manifest in content.opf
How to understand the spine and guide in content.opf
How to test your e-pub using flightCrew in Sigil
How to test your e-pub using epubcheck
How to convert an e-pub to Kindle using kindlegen

1 comment:

  1. What a great assist these posts have been in guiding a newbie like myself through the more arduous than expected task of building a publishable Kindle ebook from epub/Sigil tools. But it did eventually happen! Found the kdp amazon com/community threads also to be very helpful. Thank you again for these contributions to the self-publishing knowledge base!


Twitter Bird Gadget