Home > bash > Bash script to remove CSS from epub

Bash script to remove CSS from epub

I have a Kobo Reader to read epub eBooks. It is a first generation Kobo and has a flaw: If the epub file contains a CSS stylesheet, the reader (that’s me) cannot adjust the font size via Kobo’s font selection.

Since epub is just zipped HTML with some metadata and conventions, I was able to fix the problem by removing all CSS files from the offending epub. I don’t want any fancy “style” or formatting for the books that I read anyway.

Here is the bash script that I use to automate the task (requires the zip/unzip commands):

file=$1

if [[ $file != *.epub ]]
then
  echo "Usage: $(basename $0) something.epub"
  exit 0
fi

folder=$(basename "$file" .epub)

mkdir "$folder"
unzip -d "$folder" "$file"

find "$folder" -name *.css -exec rm {} \;

cd "$folder" 
zip -r ../"$folder"_nocss.epub .
cd ..
rm -rf "$folder"
Advertisements
Categories: bash
  1. toto
    July 23, 2014 at 13:23

    Can you make a script scan the title inside an epub and mobi file?

  1. October 8, 2011 at 13:42

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: