ebook file format conversion

calibreWhile writing The Ethics of Anarcho-Capitalism, I made heavy use of the excellent Calibre software suite to create and view ebooks. Specifically, I used the ebook-convert program to generate .mobi and .epub files. Then I used the Calbre ebook viewer to check the results.

On Ubuntu you can install Calibre with the following command:

    sudo apt install calibre-ebook

Then you can convert an html file to .epub with

    ebook-convert book.html book.epub

To make things easy, I used the following bash script (pastebin). It makes use of a few options and outputs to a few different formats.

#!/bin/bash
set -e

# helper script for running ebook-convert, available from Calibre (calibre-ebook.com)
# sudo apt install calibre

title=”the Ethics of Anarcho-Capitalism”
author=”Kristopher A. Borer”
cover=”–cover=cover_front.png”
language=”–language=English”
tags=”–tags=anarcho-capitalism,ethics,libertarianism,freedom,liberty,capitalism,anarchism”
heuristics=”–enable-heuristics”

options=”$cover $language $tags $heuristics”
output_directory=”ebooks”
mkdir -p $output_directory

# consolidate parts into book body
tmp_file=$(mktemp -p $output_directory)
mv $tmp_file $tmp_file.html
book_body=$tmp_file.html
cp front_matter.html $book_body
cat chapters.html >> $book_body
cat back_matter.html >> $book_body

# generate digital book formats
filename=”the_ethics_of_anarcho-capitalism”
ebook-convert “$book_body” “$output_directory/$filename.epub” $options –authors=”$author” –title=”$title” –output-profile=”tablet”
ebook-convert “$output_directory/$filename.epub” “$output_directory/$filename.mobi” –output-profile=”kindle”
ebook-convert “$output_directory/$filename.epub” “$output_directory/$filename.docx”

rm $book_body

Your setup may be more simple if you are only targeting one output format or if you have your front and back matter in the same file as your chapters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: