kindlegen plugin for Sigil
#1  Doitsu 10-24-2014, 04:34 PM
[Plugin] KindleGen - Simple KindleGen wrapper

Updated: November 6, 2019
Current Version: "0.5.4"

This plugin is a very simple kindlegen wrapper, which allows you to convert the currently loaded book with kindlegen.

Note that since kindlegen is executed in the background, you'll have to wait a couple of seconds before the messages are being displayed.

Disclaimer: Even though it's unlikely that the plugin will somehow corrupt the epub that you're working on or crash Sigil, you might want to save your ePub in Sigil before running this plugin.

Credits: This plugin uses code originally written by KevinH, nickredding and other KindleUnpack developers. It also uses jhowell's Calibre KFX Output plugin.

System requirements

This plugin requires the Kindlegen binary or Kindle Previewer, which comes with KindleGen. If you uncheck the Use Bundled Python option, you'll also need to install Python, bs4, lxml and Pillow.

Linux users will need to download the kindlegen binary from Amazon and unzip it. The same goes for Windows and macOS users who didn't install Kindle Previewer.


1. Select Manage Plugins from the Plugins menu. Select Use Bundled Python to use the bundled interpreter.
If you haven't updated to Sigil 0.9.0 (or higher) click one of the Auto buttons to detect the path or Set to manually select the Python interpreter path. You also might need to install bs4, Pillow and lxml.
2. Click Add Plugin and select This will install the kindlegen plugin, which you can select via Plugins > Output > KindleGen.
If you want to generate KFX files, you'll also need to install Kindle Previewer 3.x and jhowell's Calibre KFX Output plugin.
Since the Calibre KFX Output plugin doesn't support Linux, you can't generate KFX files with the Linux version of Sigil.

When you run the plugin for the first time you'll need to select the kindlegen location, unless you have installed Kindle Previewer in the default folder. Select either kindlegen.exe (Windows) or kindlegen (macOS, Linux).


By default the plugin will generate .mobi files using the same parameters as Kindle Previewer (master mobi file, no compression, attached source files).

There are two groups of settings:

1. KindleGen settings that are passed on to the KindleGen binary and allow you to:
2. Postprocessing options that allow you to:
Note that if you select any of the post-processing options, you can't upload the generated AZW3/MOBI7/KFX files to KDP!

The plugin will also check for the presence of the following recommended guide/landmarks/metadata items:

Advanced Settings

You can change two advanced settings by editing kindlegen.json entries. (These entries will most likely be terminated by a comma which you mustn't delete.)

* For best results you shouldn't select Generate KFX and Generate AZW3/Mobi, because in this mode the Calibre KFX Output plugin can't fix problems with the source files. If you only select Generate KFX, the Calibre KFX Output plugin will attempt to fix some problems that are known to cause the KFX conversion to fail.

You can see all corrections in the Calibre KFX Output plugin log. For example:

Preparing C:\Users\User\AppData\Local\sigil-ebook\sigil\plugins\KindleGen\temp.epub for conversion
Unquoted OPF guide reference: Text/%40847-h%40847-h-0.htm_split_001.html#pgepubid00001
Unquoted NCX TOC reference: Text/%40847%40847-h%40847-h-0.htm_split_000.html
Saved cleaned conversion input file to C:\Users\User\Desktop\book_cleaned.epub
If you want to keep the cleaned epub file, change "save_cleaned_file": false to "save_cleaned_file": true.

(If Preparing... is followed by Saved cleaned conversion input file... or Converting..., the Calibre KFX Output plugin didn't update the input files.)

** According to the Kindle Publishing Guidelines, the SRL has been deprecated. (You can disable the SRL check by changing "check_srl": true to "check_srl": false.)

License: GNU General Public License v3 (GPL-3)
[zip] (26.7 KB, 55 views)

#2  KevinH 10-28-2014, 09:07 AM
Hi Doitsu,

Already 19 downloads .... Great Work.

Thank you!


#3  dhdurgee 11-05-2015, 02:36 PM
I am trying this out on my linux mint 17.1 rebecca x64 system, but unfortunately am getting errors:
================================================== ==
Status: success

Running KindleGen ... please wait

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

Info:I9006ption: -c1: Standard DOC compression
Info:I9014ption: -verbose: Verbose output
Info(prcgen):I1047: Added metadata dc:Title ""Sweet Young Things""
Info(prcgen):I1047: Added metadata dcate "2015-11-03"
Info(prcgen):I1047: Added metadata dc:Creator "Kristine Kathryn Rusch"
Info(prcgen):I1047: Added metadata dc:Contributor "calibre (1.25.0) []"
Info(prcgen):I1047: Added metadata dc:Source "Free Fiction Monday 2014/11/17"
Info(prcgen):I1052: Kindle support cover images but does not support cover HTML. Hence using the cover image specified and suppressing cover HTML in content. URL: /OEBPS/Text/cover.xhtml
Info(prcgen):I1002: Parsing files 0000001
Info(prcgen):I1003: Parsing file URL: part0000_split_002.html
Info(cssparser):I10004: @rules other than @import, @charset and @font-face are not supported.
Info(prcgen):I1015: Building PRC file
Info(prcgen):I1006: Resolving hyperlinks
Info(prcgen):I1010: Writing hyperlinks
Info(prcgen):I1049: Building table of content URL: /OEBPS/toc.ncx
Error(prcgen):E24010: Hyperlink not resolved in toc (One possible reason can be that the link points to a tag with style display:none):/OEBPS/Text/titlepage.xhtml#
Error(prcgen):E24001: The table of content could not be built.
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):I1038: MOBI file could not be generated because of errors!

Kindlegen failed.

Please click OK to close the Plugin Runner window.

================================================== ==

What do I need to do to get this working?


#4  HarryT 11-05-2015, 02:54 PM
The error seems pretty clear; there's an invalid hyperlink in the TOC.

#5  dhdurgee 11-05-2015, 04:33 PM
Quote HarryT
The error seems pretty clear; there's an invalid hyperlink in the TOC.
I never created a TOC for this epub. It is a short-story and as such a TOC is unnecessary. All I really want in this epub is the cover and the text.

I ran the validator and get the following errors:

OEBPS/Text/titlepage.xhtml N/A This OPS document is reachable but not present in the OPF <spine>. "Reachable" means that a reference of some kind that points to this resource exists in the epub.

OEBPS/Text/titlepage.xhtml N/A This resource is reachable but not present in the OPF <manifest>. "Reachable" means that a reference of some kind that points to this resource exists in the epub.

OEBPS/toc.ncx 17 This <content> element's "src" attribute value is "Text/titlepage.xhtml", but that file does not exist.

I don't see a way to remove the TOC or to modify the OPF anywhere.

I was able to use ebook-convert from calibre to create a .mobi from this file, so I am surprised that kindlegen has problems with it.


#6  HarryT 11-05-2015, 04:36 PM
All those errors seem to be saying the same thing: that you're referencing a file called "titlepage.xhtml", but the file doesn't exist.

#7  eschwartz 11-05-2015, 04:38 PM
calibre is a better piece of software than kindlegen -- and you're surprised to hear that?

#8  dhdurgee 11-05-2015, 04:39 PM
Quote HarryT
All those errors seem to be saying the same thing: that you're referencing a file called "titlepage.xhtml", but the file doesn't exist.
Correct, a file that is not needed for a short story does not exist. How can I change whatever needs to be changed to remove these references to an unnecessary file?


#9  eschwartz 11-05-2015, 04:40 PM
Regenerate your Toc.ncx (semantic ToC) -- or manually edit it -- to get rid of the reference to that nonexistent file...

#10  dhdurgee 11-05-2015, 04:48 PM
Quote eschwartz
Regenerate you Toc.ncx (semantic ToC) -- or manually edit it -- to get rid of the reference to that nonexistent file...
Duh! Somehow I never expected it to be that easy. I was able to use kindlegen without problems after doing as you suggested.

The .mobi kindlegen made is substantially larger than the one ebook-convert made, over twice the size. Perhaps I need to tweak the kindlegen.ini settings to deal with this. I have both a K3 WiFi and a KT2, so I need a file that both can read, so I would appreciate some pointers.


  Next »  Last »  (1/14)
Today's Posts | Search this Thread | Login | Register