Share this page to your:
Mastodon

Mrs’ latest book needed to be uploaded to Amazon this week. We’ve not done this ourselves for her previous books, but this time it made sense to. That meant figuring out the process.

Amazon publish a guide which seems quite comprehensive but there are odd gaps in it which took some thinking about, so this describes the process that worked for us. I gather it changes fairly often so your mileage may vary, and that adds to the challenge to keep the documentation up to date as well.

One important thing this sorts out is the problem a lot of people have that means the Kindle reader opens the book on the wrong page the first time. This will open it on the cover. Okay, I haven’t tried it on every device, but the ones I tried worked fine.

So we start with a .doc file. It was created with LibreOffice and it has very simple style settings. Almost everything is using the default style except chapter headings. We want italics, of course, and perhaps section breaks, something like this:

                              *

Pull the github template and put all the files into a new directory.

Save your book file as an odt, a necessary step before you save it to html, then export to html. If you’re using Word or some other word processor your process will be different, but you want to end up with an html file and copy it into the template directory (the top level directory, the one that contains the file sed.sed).

Now run sed against your html file. Sed is a linux batch editor which we will use to clean up your html because what your word processor generates tends to be riddled with rubbish you don’t need. Plus the html export (from LibreOffice) will put most of the text in one long line with no line breaks, which is a bit punishing for many text editors. To run sed my command line looked like this:

sed -f sed.sed myfile.html > t.html

That runs sed using a file of commands (sed.sed) and writing the result out to t.html. You will find the sed.sed file in the github directory you pulled earlier. The first thing it does it break up the one long line into shorter ones to make it easier to edit. The rest of sed.sed is a bit specific to me so you will want to edit it to handle the classes you find in your own t.thml file. The general idea is to remove as many class references in the t.html file as you can. Take a look at the /kindle/text.html_template to see how it ought to look (except for the header part which we’ll fix next)

I also convert the obscure names into readable ones where I can so ‘italic’ instead of ‘T3’ and so on. When you’re happy with the t.html file copy it into the new directory and rename it to text.html.

Now manually edit the text.html and remove everything above the body tag, yes everything. Now look at the text.html_template file and copy everything above the body of that file into the top of your text.html file. You’ll see references to css files in that header information. We’ll look at the styles.css file now.

The only css file you need to bother about is styles.css. The class references in your text.html file need to be defined here. If you don’t know much about css try here but css is a big subject, you won’t need to know much but you will need a little. Take a look at the examples in the styles.css file. They might be all you really need.

You can open your text.html file in a browser and get an idea how well your css changes are working.

Next up is the LoremIpsum.opf file. Rename it to something that looks like your title. The opf file is the file that refers to all the others. Open it with a text editor and edit in your title information etc. Do the same with the title.html and copyright.html files.

Now for the table of contents. There are three files much the same here. toc.ncx has a list of chapters with names and links. Check that your chapters have id attributes on them (in text.html) that match the references here. Then you have toc.html and nav.html. All three of these look similar but not quite the same. It is possible we only need two of these three, but I found it just as easy to produce all three.

Be careful to leave the landmarks section at the end of nav.html. This section ensures the kindle opens the book at the beginning the first time. It if it missing the book will open somewhere in the table of contents.

You’ll need a cover image. Use a jpg file

Delete the _template file file from your directory.

Now download and install the Kindle Previewer from here. I used the
Windows one and ran it under Wine on my Linux laptop, it worked fine. You start it, tell it to open your opf file, and it will build and open a mobi file. It is easy to use and it will give you a list of warning and/or errors if you have problems to fix. The resulting mobi file goes into a subdirectory off the directory your opf is in.

kindle-previewer

The only bit that isn’t obvious in the Kindle Previewer is how to see the compilation details (errors, warnings etc) so I’ve marked that above.

Take a look at in in the previewer and you might also like to copy it to a device that runs the kindle software. I used my Android phone. That allowed me to take a good look at it on a ‘real’ device.

Now you are ready to upload the mobi file to Amazon. You will need to load the cover separately as well, even though the cover is already in the file. This is, presumably, so that Amazon can use it on their site.

Previous Post Next Post