Using kindlegen to make a Kindle book

These notes refer to the Linux version of kindlegen.

Using Kindlegen is pretty straight forward, it can process HTML files into mobi format reasonably painlessly, but I did run into a couple of small issues.

I used an HTML file with the following basic format:

<html>
<title>BOOKTITLE</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<meta name="cover" content="/home/user/fullpath/to/cover.png">
<body style="margin-top: 100px; margin-bottom: 100px; margin-right: 50px; margin-left: 50px;" >

<h2>Contents</h2>
<a href="#s1">section1</a><br>
<a href="#s2">section2</a><br>
<a href="#s3">section3</a><br>
<a href="#s4">Footnotes</a><br>

<h2 id="s1">section1</h2>
<p>BLAH BLAH BLAH BLAH <sup><a href="#fn1" id="r1">[1]</a></sup>

<h2 id="s4">Footnotes</h2>
<p id="fn1"><a href="#r1">[1]</a>Interesting stuff</p>

Which can then be processed with kindgen simply as:

kindlegen myfile.html

And a mobi file will be generated with the same name as the html file, and in the same directory. Initially I ran into issues processing the cover file and kept getting the error “Cover file not found”. Unlike all the over images in the html file, the meta tag pointing to the cover image has to be the full local path to the file, rather than relative to the html file.

It should also be noted that the CSS linked will be ignored by kindlegen, this makes it easier to process HTML files you’re also using elsewhere.