Unpack, modify and repack an epub file

Although epub format e-books are simple ZIP archives, care has to be taken in how unzip and zip are used to manipulate them.

mkdir wrk && cd wrk
unzip -O UTF-8 old.epub
nano OEBPS/one_of_the_files.xhtml
zip -rX ../new.epub mimetype META-INF/ OEBPS/

Without using the -O option when unpacking UTF-8 file names are likely to get corrupted. For the repack, use of -X is required and the directory order in the archive has to be as given above, otherwise the epub file will not be recognised by most e-readers.

As an aside, modifications can be easily tested using a web browser. Each page in the e-book is represented as an xhtml document, which can be opened by pointing the browser to file:///home/user/wrk/OEBPS/one_of_the_files.xhtml (for example).

Leave a Reply

Your email address will not be published. Required fields are marked *