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.

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”

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

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

# generate digital book formats
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: