How to view and convert KFX files in Calibre - Tutorial

Updated: May 13, 2019

This is a rather interesting topic. Over the years, Amazon have changed the Kindle file format several times. Their digital books came in a variety of formats, including AZW, then AZW3 and finally KFX. The last one is a complex archive that combines numerous features, including typesetting engine, fonts, multi-page thumbnails, and also DRM. I noticed this starting with Decay, one of my books published in 2017.

Reading some more, I realized KFX seemed to include DRM even for books that are not meant to use DRM, and I found this quite weird, because as an author, I have specifically chosen not to publish my own works with any sort of lock-in encryption. So this got me thinking. Is there a way to actually convert KFX into the old format, or other e-book formats, and use them in Calibre and other readers, the way the older formats allowed? Follow me.

Teaser

Basic tools, requirements & disclaimer

What you want to do is simple: convert KFX files to other formats - for archiving, backup and publication testing purposes, so you can use them on different e-reader devices. If you try to open a KFX file in a typical e-book reader, you probably won't succeed. For instance, Calibre cannot read this file format natively. The solution is then to convert the file, our task for today.

I spent a good few hours reading about this topic, compiling information, trying to find out all the necessary bits and pieces to get the job done. In the end, I did successfully manage, but it wasn't trivial, and there are still many ifs and buts to the whole thing. So let's start with the tools:

You will need to feel comfortable installing Calibre plugins and working with archives. If you can't do these things easily, you will probably struggle getting the job done here.

Disclaimer

The purpose of this guide is not to teach you how to hax0r your way around. The purpose is to allow you to decrypt your own books and use them on your own devices. In fact, the DeDRM plugin listed above does not work with rented or lent books - it only works for the books you have purchased yourself.

There are also numerous technical limitations on how well the tools listed above work, including the version of Kindle software and such. In my test, I did not encounter any such problems. But please take this into consideration as you read on.

Before you start ... download non-KFX books

When you purchase a Kindle book, and then go to your Kindle library, you can choose different delivery methods. You can send books directly to a Kindle device or reader, and you can also transfer them via USB. This will effectively download the book to your local computer, which you can then copy to the relevant device. For the time being, books downloaded via USB come in the non-encrypted AZW format, but this may change. So this is your first and best options, before doing any fancy conversions! If the book is in your Kindle library, then you are all set.

Calibre plugins setup

After you install and start Calibre, you will need to install the two plugins (Calibre > Preferences > Plugins). KFX Input is available in the list of plugins, although you can also download it manually (see the linked forum thread at the beginning of the page). DeDRM is available from GitHub. Both plugins come as ZIP files. The DeDRM plugin ZIP contains more than just the plugin itself - but it also has what we need, the Calibre plugin.

Calibre preferences

Plugins

To install KFX Input, click on Get new plugins, select, install, restart Calibre.

Plugins, install

KFX Input plugin

Plugin installed

To install DeDRM, download the zip file from GitHub, extract it. Next, in Calibre, click on 'Load plugin from file' in the plugins window, navigate to the Calibre sub-folder in the extracted archive and then select the plugin zip. If you have chosen the "wrong" zip (such as the external zip archive), you will see the It does not contain a top level __init__.py file error. Once you've installed this plugin too, restart Calibre.

DeDRM, wrong zip

DeDRM setup

Your next step is to configure the DeDRM plugin. Open the plugins list, search for DeDRM in the list. Double-click on the plugin, and it will open the customization window. You must configure the plugin, otherwise it will not work. And this is probably the most complex step. Because not everyone has a Kindle device, and this is where it gets complex. There are various technical limitations on different types of devices, like Kindle for Android or Kindle for Mac.

DeDRM

Customize DeDRM

I selected eInk Kindle books - please note I own a Kindle device, and I connected it via USB to my Linux machine, and then copied my Decay book over ( all Decay* titled files, KFX plus folder). When you select this option in the DeDRM customization screen, you need to add a serial number for your Kindle device. It's a 16-digit string composed of numbers and digits (no spaces).

Add KFX book to Calibre

The next step is to add your KFX book to Calibre. If you have already added it to Calibre, remove it and then add it fresh. DeDRM runs on first import only. If you've configured everything correctly, DeDRM will run now. This can take a few seconds.

Add KFX book

While this was happening, in the background, DeDRM configured WINE for Linux, probably so it could install various Windows-based tools it needs to create decryption keys. There's no need for you to do anything manually, but you should be aware of this, especially since it creates a new WINE configuration directly in your home directory, and not as a hidden object (no dot prefix), so this may pollute your home - you will suddenly see drive_c and various WINE reg files there.

And then, it was done. The book was imported. I noticed the cover image was black & white rather than color, but that's easily solvable. I opened the book in the Calibre ebook reader, to verify that I indeed the DRM component was removed.

Convert to other formats

The next step is to convert the book using KFX Input. This is an optional step, but if you want to have your book in AZW3 format, or maybe EPUB or alike, then you can use this plugin. This can be quite useful if you have multiple ebook devices, or want to keep a backup of your own files - although they should all be available in your Kindle library, but still.

Convert KFX file

Conversion complete

I then opened the file in the Calibre ebook reader, to make sure everything is dandy:

Book converted

Conversion complete, ebook reader

And that's it. We're done. Happy times.

Various errors

In case things didn't work as they should, then you will see various errors, apart from the DeDRM plugin ZIP error we've already discussed. First, if you try to open a KFX file in Calibre without the use of the DeDRM plugin, you won't be able to do so. Moreover, if you try to use KFX Input before DeDRM has run, you will not be able to convert the file, even if you did select the option to ignore errors during the conversion process.

Cannot convert

Conclusion

Hopefully, this guide was useful. I have never really needed the ability to open any KFX file in Calibre before, because I'm happy using and reading them on my Kindle. But when it comes to my own books, the books I've written myself and then published WITHOUT DRM, then I expect to actually be able to work with these files, including any pre- and post-publication processing required - after all, this allows me to test how the digital books render on different devices, and make sure that my readers get the best experience.

This isn't a trivial tutorial - it uses Linux (which may already be too much), requires two Calibre plugins, and you need some tweaking to get things working. But in the end, we did succeed. For people who can't be bothered, my advice is to grab the files from your Kindle library using the USB option, this way you won't need to worry about the KFX conversion. Alternatively, this article outlines the steps you need to get the job done. See you out there, and enjoy your books!

Cheers.

You may also like: