Sunday, February 22, 2015

Kindlegen - Convert EPUB to Kindle MOBI



In trying to expand my Kindle library, I have found that most e-books, or magazines, found online come in PDF format. PDF is not supported on the Kindle and wouldn't read well on the tiny screen, due to PDFs not being designed to reflow the text on a smaller screen. A few e-books will actually come in the e-book reader friendly format, .epub (Electronic Publication), which does support reflow. The trouble is that Kindle doesn't support the EPUB format. Kindle only naively supports the .mobi (Mobipocket) format (and a few other archaic proprietary formats).

Luckily, I was able to use the free Kindlegen, provided by Amazon, to convert the .epub e-book. Kindlegen is supported on Windows, OSX, and Linux.  Kindlegen is a command line tool, but is fairly simple to use. Be aware that the generated .mobi file will be significantly larger than the EPUB format (about 2x-3x larger).

Kindlegen can convert the following formats to the .mobi format:
  • .opf
  • .htm
  • .html
  • .epub
  • .xhtml
  • .zip
  • directory source files
The only trouble I ran into, during conversion, is you have to specify the full path to the file you are converting. If you don't specify the full file path, even though the file is in the same folder, you will get an error about not finding the file specified. You may also notice the .mobi file is built with warnings, due to missing desired headers, but those can generally be safely ignored.

Converting an .epub book to mobi:

C:\temp>kindlegen.exe "c:\temp\pg11.epub"

*************************************************************
 Amazon kindlegen(Windows) V2.9 build 1029-0897292
 A command line e-book compiler
 Copyright Amazon.com and its Affiliates 2014
*************************************************************

Info(prcgen):I1047: Added metadata dc:Title        "Alice's Adventures in Wonderland"
Info(prcgen):I1047: Added metadata dc:Date         "2008-06-27"
Info(prcgen):I1047: Added metadata dc:Creator      "Lewis Carroll"
Info(prcgen):I1047: Added metadata dc:Subject      "Fantasy"
Info(prcgen):I1047: Added metadata dc:Rights       "Public domain in the USA."
Info(prcgen):I1047: Added metadata dc:Source       "http://www.gutenberg.org/files/11/11-h/11-h.htm"
...
Info(prcgen):I1037: Mobi file built with WARNINGS!

Converting an html book to .mobi:
C:\temp>kindlegen.exe "c:\temp\Alice's Adventures in Wonderland, by Lewis Carroll.htm" -o alice.mobi

*************************************************************
 Amazon kindlegen(Windows) V2.9 build 1029-0897292
 A command line e-book compiler
 Copyright Amazon.com and its Affiliates 2014
*************************************************************

Info(prcgen):I1047: Added metadata dc:Title        "
      Alice's Adventures in Wonderland, by Lewis Carroll
    "
Info(prcgen):I1002: Parsing files  0000002
Warning(htmlprocessor):W28003: Value specified for CSS property in content is not supported by Kindle readers. Please re
fer Kindle Publishing Guidelines about usage of property: 'position: absolute' in file: c:\users\kenneth\documents\Alice
's Adventures in Wonderland, by Lewis Carroll.htm
...
Info(prcgen):I1037: Mobi file built with WARNINGS!



No comments: