Sunday, May 16, 2010

How to use Kindlegen to create ebooks for your Kindle

Apparently, this has been a pretty popular article so I decided to provide a quick overview if you just want the fast, dirty steps for using kindlegen. If you would like some more detail then read the further explanation below.

2. Unzip the files to the folder where you keep your ebooks (it's really much easier that way)
3. Open your command line and point to the folder containing your ebooks and kindlegen.
4. Enter the command 'kindlegen.exe ebook.html' where ebook.html is the name of the ebook you want to convert. note: in order for kindlegen to make the conversion the file must be in html format.
5. Move the newly created .mobi file to your kindle's ebook directory
6. Enjoy a favorite book or new adventure that you've converted yourself :)


For some reason (not so difficult to imagine) there appears to be no simple explanation of how to use Kindlegen on the internet. This amazed me since I would think lots of people would want to convert and add their own ebooks to the Kindle. Kinlegen can be used to do just that. The catch is, it is only available in the command line. This may be intimidating for some but I guarantee it's not that difficult once you understand how it works. Here's what to do.

1. Get the latest version of kindlegen from Amazon's website (available here at the time of writing this article: http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000234621 )

2. Unzip the files to a chosen location

3. At this point your options open up considerably. You can create a very basic book or a very complex book depending on how dirty you want to get with HTML and XML coding. Among the unzipped files you'll find a folder called 'Sample' that contains a complex book (the Kindle User's Guide) with all of the supporting files that would be needed to create it, you can review how this is all set up if you like. For now, I'm going to just go over the basic book option in order to keep this short. If you would like more in depth info on how to create a complex book (linking images and table of contents, etc.) go ahead and comment or email me directly.

4. Okay, in order to create a simple ebook for the kindle you'll need an HTML file of your ebook. If you go to Project Gutenberg (gutenberg.org) you can download a TON of out of copyright books in HTML format. You can also use PDFs or txt files you've purchased but you'll need to convert them to html (you can use PDFtoHTML and txt2html respectively to do so). Okay, once you have the HTML file, do yourself a favour and put it into the same folder as Kindlegen.

5. Now, open up your command line. In Windows, go to Start > Run and enter cmd then press enter. In Linux, you should be able to find the terminal under Accessories or some other main menu option. Once open, navigate to the location of Kindlegen.
e.g. C:\Documents and Settings\myname\My Documents\ebooks\Kindlegen\

If you are not familiar with a command line then you are probably in Windows and can get there by entering
c:
cd..
cd Documents and Settings\myname\My Documents\ebooks\Kindlegen

6 Once your command line is pointing to the folder where you have kindlegen and the HTML file (we'll call it ebook.html in our example but you would put in the name of the HTML file you are converting) all you have to do is type

kindlegen.exe ebook.html

For some reason in Linux I had to enter the exact file path so it would be something like this:

/media/disk/Documents/ebooks/kindlegen/kindlegen /media/disk/Documents/ebooks/kindlegen/ebook.html

7. You'll notice that a new file is created in the directory called ebook.mobi. Connect your Kindle to your PC and drop the file into the same folder as your other ebooks.

8. Eject your Kindle, disconnect it and then start the Kindle. If you've done everything correctly you should see the ebook now available in your home screen.

Congrats, you can now take any HTML file you have available to you and create your own ebook for reading on the Kindle. Cheers!


Oh, as a final note - Again, you could get much more in depth in the process and use an OPF and NCX file but you should only need that if you are getting serious about publishing. You can open Kindlegen's help by simply typing kindlegen.exe or kindlegen without any filename following it. This will bring up all of the kindlegen options. Happy reading!

12 comments:

  1. Thank you - I did manage to generate a mobi file but, not having a Kindle, it all kind of goes downhill from there! The message I got was that it was generated with errors (no clue as to what they were!)

    Will have to find out a lot more yet I guess.

    btw, this process is barbaric - talk about going back 30 years!

    ReplyDelete
  2. Hey Casa Adsubia - thanks for the response. Yeah, I'm not sure why Amazon didn't provide a simple gui frontend for kindlegen but there you have it.

    The generated errors are most likely from the fact that no ncx file is included and the html hasn't been prettied up for specifically for Kindlegen. You can test .mobi files you've created by using Amazon's test app, or you can set up a kindle account and run the kindle app on your pc or ipod/iphone.

    ReplyDelete
  3. PLEASE HELP!
    1) On June 27 Amazon issued a Press Release that Kindle will now support embedded audio.
    2) I downloaded Kindlegen and on page 27-28 there are instructions on how to embed audio into the file.
    3) I've been in email contact with Amazon (Digital Text Platform) and they say that even though they will CONSIDER ME for a beta group of book publishers that does this exact thing, Kindle does not now support embedded audio files.
    Bottom line is that I have a book in which i want embed several audio files, exactly as described in the Kindlegen manual. Will it play on Kindle?
    Thanks so much.

    ReplyDelete
  4. I am a first time Kindle publisher. I created a .mobi from a .htm from a .docx using KindleGen. I have the table of contents working properly within the text, but Kindle for pc does not recognize it and allow the user to "Go to." I do have it bookmarked as TOC. Can I fix my problem within the formats I am currently working, or will I need to learn about .OPF and .NCX? If I need them, can you recommend any good tutorial sites that would explain how to fix my TOC problem?

    By the way, I found this page very helpful if brief. You are right, there are no simple walkthroughs of how to use KindleGen. I had to figure most of it out on my own.

    Thanks for any help you can offer!

    ReplyDelete
  5. Stephen, you should be able to embed an audio file as a link that will open up in the kindle audio player (similar to how you link to an mp3 file within a webpage). Give me a little time to test some embedded links and see if I can give you an answer in the next couple days.

    Jessi - Congrats on finishing your book and working on your publication! Your frustrations are probably a result of the garbley gook html exported from microsoft word (right click the .htm file and open with notepad). Here's a few options you can try:

    - I HIGHLY recommend trying the conversion in Calibre (http://calibre-ebook.com/). Just convert the book to .mobi from the .htm file. I haven't tried it with docx exported files but it has handled some other problem books I've had. It's free and definitely worth a try.

    - If you know HTML you can edit the exported .htm file to remove the extra Microsoft code. You could do it in Notepad which would probably be a nightmare. Try it in Notepad++ (I'm assuming you're in Windows). You'll also get a really good idea of how the whole coding of your book comes together.

    - Similarly, you could copy all of the text of your book into an empty html document and edit the code that way. The links in your TOC can point to a different location in the same document. (see here: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_link_locations)

    - If you're not a coder then you probably don't want to bite off the whole .opf / .ncx option but it is a definite option which isn't too hard to figure out by looking at the sample file provided with kindlegen. If you want FULL control of the layout of your book then this is the option for you.

    If none of these options work for you let me know and I'll send you an example of how you can make it work and then you can just plug your text into it. Or, if you feel safe doing it, you could send me your book and I'll send back the .mobi. I'm honest. Promise. But I probably wouldn't send my work to someone who could run with it.

    ReplyDelete
  6. Hi again Richie

    casadsubia here again !! I've managed to download the Kindle previewer on my PC but, when the mobi file displays, it's too wide for the simulated Kindle screen. Altering the source file (word document) makes no difference no matter what I do.

    So...... any idea what I'm doing wrong please. Beginning to wonder if potential fame is worth all this hassle lol

    ReplyDelete
  7. Sorry for the VERY late responses. The holidays are killing me this year.

    Stephen - your solution is here:
    http://s3.amazonaws.com/kindlegen/AmazonKindlePublishingGuidelines.pdf
    Search for the phrase "embedded audio" and there are step by step instructions on how to add an embedded audio link right into your ebook. Fortunately, the kindle uses HTML5 attributes (YAY!) so you can just use audio tags.

    Casa_Adsubia - here's a few solutions:
    First, make sure you're using the kindle previewer which can be obtained here: http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000234621

    Next, you might want to try making the conversion in Calibre which is really REALLY handy for converting without kindlegen.

    If that still doesn't work, you might have to get into the html and specify the size and location of your image. If you right click the file and open it in a text editor (like notepad) then you can ctrl+F and look for "img src" which will take you to the image links. Use the info from this website: http://www.w3schools.com/tags/tag_IMG.asp to adjust the image. The kindle's resolution is 600x800 so a full page image would be those dimesions. Something like < img src="myimage.jpg" align="middle" width="300" /> should work fine. Experiment a bit and let me know if you get it worked out.

    Happy reading and Merry Christmas! -Richie

    ReplyDelete
  8. If somebody wants to test the kindlegen tool before installing or struggling with the command line, the online kindle converter www.onlinekindleconverter.com is using kindlegen.

    Kind regards

    ReplyDelete
  9. You can make it so that it executes without specifying the path in linux by copying it to /usr/bin .

    The command is 'mv kindlegen /usr/bin' once you've got it extracted.

    ReplyDelete
  10. Can you geneate the ebook file on your computer then get it onto your kindle another way?

    ReplyDelete