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"

2 thoughts on “Bash script to remove CSS from epub

Leave a comment