View Single Post
Old 10-16-2017, 08:51 AM   #1
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
jhowell's Avatar
Posts: 1,983
Karma: 20234780
Join Date: Nov 2011
Location: Florida
Device: Oasis 2, Fire, iPad Air 2, Nexus 7
[Conversion Plugin] KFX Input

KFX Conversion Input Plugin

The KFX Input plugin allows books in Amazon KFX format to be converted to other e-book formats, such as EPUB, for archival and for reading on alternate devices.

Amazon uses KFX format for the delivery of most e-books to customers. It supports advanced features, including Enhanced Typesetting and Page Flip, on Amazon apps and devices. All books delivered by Amazon in KFX format have DRM encryption. Information about the KFX format can be found in the KFX Format thread and the MobileRead Wiki (KFX).

Amazon's KF8 (azw3) format is superior to KFX as a source for conversion. This plugin has limited usefulness as long as KF8 is still easily obtainable. Some cases where KF8 is not available are Indic language books/dictionaries, books produced using Kindle Create, Kindle in Motion books with animation, and Interactive Textbooks with A/V media. Extra effort is usually required to avoid KFX when using Kindle for PC/Mac.

As delivered by Amazon, books in KFX format are usually composed of multiple KFX container files. The entire set of KFX files that make up the book is required for successful conversion. Since calibre handles all e-book formats as a single file, this plugin accepts a ZIP archive with the extension ".kfx-zip" containing multiple KFX files. This will appear in calibre as KFX-ZIP format.

Alternatively, an entire book's content may be contained within a single monolithic KFX container file with a ".kfx" extension, as produced by the KFX Output plugin. The KFX Input plugin accepts this format (KFX) as an alternative to the multi-container format (KFX-ZIP).

Warning: Monolithic KFX is different from the files delivered by Amazon with a ".kfx" extension! Those contain only part of the book's content and cannot be converted individually.

Amazon's Kindle Textbook Creator and Kindle Create software export books in KPF (Kindle Package Format), a KFX variant proprietary to Amazon. This plugin allows conversion of KPF, so that the author has greater control over the finished book.


Install the plugin and restart calibre as described in the Introduction to plugins thread.


A book must have either KFX (monolithic), KFX-ZIP, or KPF format for conversion to be possible. The plugin is activated by selecting the proper input format when converting books in calibre.

If the results of a conversion appear incorrect, it is recommended that the conversion job log be checked for errors and warnings. Please report problems in this MobileRead thread.

You can view the conversion job log after an error occurs to see additional information on why the conversion failed. To access the log, either click on the "Jobs: 0" label in the lower right corner of the calibre window or use the Alt-Shift-J keyboard shortcut to activate the Jobs dialog. Select the failed conversion job from the list (the most recent will be first) and click the "Show job details" button. To copy the log to the clipboard under Windows, click within the log text then press Ctrl-A (select all) and Ctrl-C (copy). You can then paste it wherever you like.

A command line interface is also available. (See below.)

Reading book metadata:

The KFX Input plugin also contains a Metadata Reader plugin, which will extract book metadata and cover images on import. It is also activated by the "Set metadata for the book from the selected format" and "Set the cover for the book from the selected format" buttons in the single Edit Metadata dialog. ("Set metadata from the e-book files" and "Change cover - Set from e-book files" in bulk Edit Metadata.)

The supported fields are: title, author, language, publisher, publication date, description, cover, and "mobi-asin" identifier (ASIN).

Importing KFX books into calibre for conversion:

Users of this plugin must manually import KFX books into calibre.

First, the main KFX file for the book to be imported must be located.
  • For Kindle for PC/Mac version 1.19 or greater the "My Kindle Content" folder will contain a sub-folder for each book, named with the ten character ASIN of the book followed by "_EBOK". The ASIN for each book is shown in the "Product details" of the book's Amazon web page. The main file for the book will have an ".azw" extension, regardless of whether or not it is in KFX format. When locating books it may be helpful to sort "My Kindle Content" by date so that the newest book sub-folders appear first.
  • On e-ink Kindle devices connected via USB, the main file for each book is contained in the "documents" folder. These contain both the title of the book and the ASIN. Books in KFX format will have a ".kfx" extension.
  • No workable import method currently exists for Fire tablets or the Kindle for iOS/Android apps.

The main KFX file will have DRM encryption and must be replaced by an equivalent file with the DRM removed. A standalone program that can remove DRM from individual KFX files is available at Apprentice Harper's GitHub. That program only works in conjunction with Kindle for PC. Detailed instructions for DRM removal are not allowed on MobileRead so the steps for using that program are not described here. If help is needed raise an issue at GitHub.

Once DRM has been removed, the main file can be imported to calibre using "Add Books" function or drag-and-drop. This activates a File Type Plugin contained within the KFX Input plugin. When the main KFX file that is only part of a book is imported, the plugin automatically gathers the rest of the files and combines them into a KFX-ZIP archive. A second File Type Plugin is then activated, which will package the KFX-ZIP archive into a monolithic KFX file that can be sideloaded, viewed using Kindle Previewer 3, or converted to other e-book formats.

If import is successful the book entry in calibre will show KFX as a format. If the resulting format is KFX-ZIP instead then the import was unsuccessful, likely due either the KFX-ZIP archive being incomplete or containing content with DRM.

Information on the reason for import failure can be obtained from a log file. Click the Preferences drop-down menu and choose "Restart in debug mode". Re-import the book and then close calibre. A log file will appear.

Simplified import plans:

The Handling KFX files in Calibre thread contains a technical discussion of how the import of KFX books is intended to work.

A future version of calibre could possibly allow easier import of books in KFX format from Kindle for PC/Mac (using Connect to folder) and from Kindle devices (using the Kindle device GUI).

Hopefully, the commonly used DRM Tools will eventually be updated to automatically remove DRM from the KFX-ZIP variant of KFX format. Until then, users of this plugin must perform manual DRM removal when importing KFX books.

Command Line Interface:

The KFX Input plugin command line interface bypasses the calibre conversion pipeline and can result in an EPUB that more closely matches the content and formatting of the original book. Conversion using this method is required for books with special formatting, such as fixed layout comics.

usage: calibre-debug -r "KFX Input" -- [-h] [-e EPUBVERSION] infile [outfile]

Convert e-book from KFX to EPUB

positional arguments:
  infile                Pathname of the .azw8, .kfx, .kfx-zip, or .kpf file to
                        be converted to .epub
  outfile               Optional pathname of the resulting .epub file

optional arguments:
  -h, --help            show this help message and exit
                        EPUB version to generate: 2.0, 3.0, 3.1


The KFX format is undocumented and has changed over time. Some books may fail to convert or result in incorrect content or formatting.

Some specialized variants of KFX cannot be converted using this plugin, including Kindle in Motion and KFX format dictionaries.

KFX is more highly processed than Amazon's KF8 (azw3) format, causing some details in the markup of the original e-book provided by the publisher to be lost during conversion. The exact HTML tags and styles originally used in the book are not retained in KFX format. However, all of the text and most of the formatting should be preserved. Images may be reduced in resolution or converted to black and white to match the capabilities of the device on which they are viewed. These limitations make KFX less suitable for archival and conversion when compared with KF8.

All books currently supplied by Amazon in KFX format have DRM. This plugin only supports KFX files without DRM encryption. Removal of DRM is not within the scope of this plugin.

This plugin does not contain a copy of the KFX symbol table. Some error messages may refer to KFX symbols in numeric form (such as $123). Interpreting these is not within the scope of this plugin.

This plugin requires calibre version 2.0 or later. Version 2.74 or later is required for automatic import of KFX format. Version 3.9 is later is required for conversion of books from e-ink Kindles containing JPEG-XR images.

Version History:

Version 1.1.0 - 31 Jan 2018

Added a built-in File Type Plugin to automatically gather the component files of a book and produce KFX-ZIP format during book import. This eliminates the need for the user to produce KFX-ZIP files manually, simplifying the process of importing KFX books into calibre. (DRM removal must still be accomplished by other means, prior to import.)

Added another built-in File Type Plugin to combine the components of a KFX-ZIP into monolithic KFX format. This process will only succeed if all of the components of the book are present in the KFX-ZIP and do not contain DRM. This makes it easier to determine whether on not the import was successful since a successful import will result in KFX format and an unsuccessful one will result in KFX-ZIP format.

Added a Metadata Reader Plugin to extract KFX book metadata. This allows the title, author, and other metadata to appear in the calibre book entry when importing a KFX book.

Ignore approximate page numbers created by the KFX Output plugin.

Handle changes to KPF format produced by Kindle Create and Kindle Previewer 3.17.1.

Fix KPF format not being accepted for conversion using the GUI interface.

Allow conversion of additional KFX features.

Improve detection of unsupported KFX features.

Version 1.0.1 - 16 Oct 2017

Remove extraneous files that were inadvertently included in the initial release.

Version 1.0.0 - 16 Oct 2017

Initial release.

Attached Files
File Type: zip KFX (102.6 KB, 3557 views)

Last edited by jhowell; 01-31-2018 at 10:52 AM. Reason: version 1.1.0
jhowell is offline   Reply With Quote