yshalsager/calibre-with-kfx
About
A Docker image for running Calibre with KFX support to allow conversion of KFX files to other formats.
Systems & InfrastructureMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalCalibre with KFX Docker
A Docker image for converting eBooks using Calibre with KFX support.
KFX is Amazon's proprietary eBook format used for Kindle devices.
Why?
Calibre's KFX Output plugin requires Amazon's Kindle Previewer 4, which isn't available on Linux. This image runs it using Wine.
It also includes kfxgen and Boko for native KFX generation without Previewer or Wine, and KFX Input for converting KFX to other formats.
Usage
You can build the locked image locally, or pull it from Docker Hub:
docker pull yshalsager/calibre-with-kfx
Image variants
| Tags | Default KFX backend | Contents |
|---|---|---|
latest, full, <version> |
previewer |
Complete Calibre payload, all three KFX plugins, Boko, Wine and KP4 |
slim, <version>-slim |
kfxgen |
Headless Calibre, all three KFX plugins and Boko, without Wine/KP4 or speech synthesis |
The slim image retains PDF conversion, fonts, Unicode support, dictionaries and hyphenation. It uses only the GLVND loader libraries needed by headless Qt, not the Mesa/LLVM driver stack. It keeps English and Arabic Chromium UI locales; this does not restrict book languages. It is not a desktop/GPU image and cannot use the Previewer backend.
Downstream applications must provide their own standalone Python. Both variants retain Calibre's embedded Python, but no longer provide an application interpreter as part of their base-image contract. For ebook-converter-bot, copy a pinned official Python runtime from the same Debian trixie release before running its frozen uv sync. The bot also selects its own backends: changing the base image's KFX_BACKEND does not disable its Previewer routes.
Once you have the Docker image, you can run it using the following command:
docker run --rm -it -v "/path/to/local/folder:/app:rw" yshalsager/calibre-with-kfx [input_file] [output_file] [extra args]
Examples:
- Convert to azw3 with extra arguments:
docker run --rm -it -v "$(pwd):/app:rw" yshalsager/calibre-with-kfx epub30-spec.epub epub30-spec.azw3 --dont-compress - Convert to KFX:
docker run --rm -it -v "$(pwd):/app:rw" yshalsager/calibre-with-kfx epub30-spec.epub epub30-spec.kfx - Convert to KFX with approximate page numbers (auto):
docker run --rm -it -v "$(pwd):/app:rw" yshalsager/calibre-with-kfx book.epub book.kfx --pages 0 - Convert natively with the slim image:
docker run --rm -it -v "$(pwd):/app:rw" yshalsager/calibre-with-kfx:slim book.epub book.kfx --kfxgen-open-at-cover
KFX backends
KFX_BACKEND selects the backend when the output is KFX:
previewer(full image default): KFX Output via Kindle Previewer under Wine; preserves existing conversion behavior.kfxgen(slim image default): native generation viaebook-convert, without starting Wine or Xvfb. Also available in the full image.boko(opt-in, both images): native generation viaboko convert, without starting Wine or Xvfb. Accepts EPUB, KFX, AZW3 and MOBI input only; unsupported formats are rejected rather than preconverted.
docker run --rm -it -v "$(pwd):/app:rw" -e KFX_BACKEND=kfxgen yshalsager/calibre-with-kfx \
book.epub book.kfx --kfxgen-open-at-cover
Options are backend-specific and are passed through unchanged. There is no automatic fallback between backends. Non-KFX output ignores KFX_BACKEND.
For previewer, extra args are passed to KFX Output (calibre-debug -r "KFX Output" -- ...). Useful flags include:
--pages Ncreate approximate page numbers if missing (0= auto)--bookmark as EBOK (vs default PDOC)--asin BXXXXXXXXXset an ASIN--logsinclude Kindle Previewer conversion logs--qualityinclude Kindle Previewer quality report--timeoutstop conversions lasting over ~15 minutes
For kfxgen, extra args are ebook-convert options, including:
--kfxgen-open-at-coveropen new books at their cover--kfxgen-disable-approximate-pagesskip estimated page numbers (enabled by default when real pages are missing)--kfxgen-disable-font-embeddinguse the Kindle's selected font instead of embedding publisher fonts--kfxgen-embed-original-imagespreserve original image resolution--kfxgen-disable-native-tableswrite tables as paragraphs
kfxgen does not accept Previewer's --pages, --book, or --asin flags.
For boko, extra args are Boko options, not Calibre or Previewer options. --optimize shrinks images for Kindle; --quiet suppresses progress messages. Approximate page numbers are generated automatically and KFX is marked EBOK. Previewer's --pages, --book, --asin, --logs, --quality and --timeout are not supported.
docker run --rm -v "$(pwd):/app:rw" -e KFX_BACKEND=boko yshalsager/calibre-with-kfx:slim \
book.epub book.kfx
Boko's full CLI is also available independently of KFX_BACKEND, including KFX conversion to EPUB, AZW3, Markdown or text:
docker run --rm -v "$(pwd):/app:rw" --entrypoint boko yshalsager/calibre-with-kfx:slim \
convert book.kfx book.epub
Boko 0.6.0 can produce invalid KFX when re-encoding image-bearing KFX input. Prefer the original EPUB for KFX generation; KFX-to-EPUB extraction is tested separately. There is no automatic fallback or repair.
The native engines can differ from Previewer in formatting. Boko's visual rendering on Kindle is not verified by these conversion tests.
KFX Output is disabled for automatic format selection, so direct ebook-convert book.epub book.kfx uses kfxgen. Explicit Previewer conversion via calibre-debug -r "KFX Output" -- ... requires the full image.
When converting from KFX to other formats, this image uses ebook-convert normally. Any ebook-convert CLI options can be passed as extra args.
The KFX Input plugin also provides a separate CLI (useful for print replica PDF extraction, CBZ creation, resource unpacking, etc):
docker run --rm -it -v "$(pwd):/app:rw" --entrypoint calibre-debug yshalsager/calibre-with-kfx \
-r "KFX Input" -- /app/book.kfx --help
Common KFX Input CLI flags:
--epub(default),--epub2--pdfextract/produce PDF (print replica, comics/children's)--cbzcreate CBZ (print replica, comics/children's)--unpackextract resources to a ZIP--json-contentcreate JSON content/position file--coverforce a generic EPUB cover if missing
KFX Input has one calibre "Convert Books" option: allow_conversion_with_errors (default off). It also has plugin preferences used by its CLI/From-KFX UI (for example splitting landscape comic images when creating PDF).
Building and testing
Requires Docker and mise 2026.11.0 or newer. The offline tracking tests also use Perl's standard socket module and GNU checksum utilities. The image targets Linux amd64, including when built on another architecture.
mise trust mise.toml
mise run versions # inspect the committed full-image versions, without network discovery
mise run build # build target full as calibre-with-kfx:local
mise run test # full-image conversions; prints a fresh temporary output directory
VARIANT=slim mise run versions
VARIANT=slim mise run build # build target slim as calibre-with-kfx:slim-local
VARIANT=slim mise run test # native conversions, RTL/PDF checks, and absence of Wine/standalone Python
mise run test-tracking # offline metadata, variant, and checksum regression tests
Use calibre-with-kfx:local or calibre-with-kfx:slim-local in the usage examples to run a local image. mise run build supplies the required locked build arguments; a bare Docker build still needs them. The last/default Dockerfile target is full.
To test another full image, run IMAGE=ghcr.io/yshalsager/calibre-with-kfx:<tag> mise run test. For slim, use VARIANT=slim IMAGE=ghcr.io/yshalsager/calibre-with-kfx:<tag>-slim mise run test. The manual conversion-test workflow also requires the matching variant; checks are explicit rather than silently skipping a missing full-image runtime.
Calibre and plugin artifacts are prepared in shared builder stages. Slim never needs the Wine/KP4 build stages. Speech data and unused Chromium locales are removed before the slim payload is copied into its final stage, rather than deleted from a retained parent layer. Download/extraction tools and standalone Python are not needed in the conversion runtime.
Versioning
mise.tracking.lock records the versions, artifact URLs, and checksums used by Docker. Labels and GitHub releases read the same lockfile, omitting Wine/KP4 for slim. Calibre versions are discovered through GitHub, but Linux artifacts come from the official versioned archive because GitHub removes older binaries. The Debian base image remains pinned in Dockerfile and updated by Renovate.
Version discovery is isolated in mise.tracking.toml, so normal mise commands do not fetch upstream metadata. To update:
mise trust mise.tracking.toml
mise run update-versions
git diff -- mise.tracking.lock
The weekly version workflow commits lockfile updates; matching pushes build, test, and publish both image variants without creating GitHub releases. Git tags and GitHub releases are created only by weekly scheduled or manual runs. Weekly builds also refresh signed apt dependencies, including copied graphics libraries, when tool versions have not changed. Publication is serialized; both images must pass before either is published, and the tested images are pushed without rebuilding.
A release uses a UTC YYYYMMDD-HHMMSS tag for full and <version>-slim for slim. Only a build of the current master head updates the moving latest, full, and slim aliases; older reruns can publish dated tags without rolling those aliases backward.
Slim's manually copied GLVND libraries come from the same Debian builder. Their license and installed package versions are recorded under /usr/local/share/doc/libglvnd/; include these files in security inventory rather than relying only on the runtime apt database. Other OS dependencies are also not individually locked.
KP4 is tracked as version+etag: Amazon's release notes supply the advertised version, and a HEAD request detects Windows installer replacements. Amazon currently publishes only an MD5 for that installer; it is a content-change check, not strong authenticity verification. The build checks the extracted Windows package version against the advertised version and fails on a mismatch. Mutable vendor URLs can stop serving older locked artifacts.
Boko's Linux amd64 release archive is checksum-verified and its version checked during the shared build, then copied into both variants. Boko is GPL-3.0-or-later; its license is included at /usr/local/share/doc/boko/LICENSE. Corresponding source is available as source.tar.gz in the matching upstream release; /usr/local/share/doc/boko/SOURCE records the exact source URL for the shipped version.
KFX Output stays pinned at 2.22.0 while patches/kfx-output-linux-kp4.patch provides Linux KP4 support. Review the patch and conversion tests before changing that pin. Wine tracking pins the staging metapackage for Debian trixie, whose exact-version dependencies pin the amd64/i386 Wine packages. Apt verifies those dependencies against its signed repository metadata; their hashes and other OS dependencies are not individually recorded in the mise lockfile.
Explore related projects
Loading…