Monday, November 2, 2009

Tweaking ePubs: It's just a ZIP file!

Did you know that any eBook in the EPUB format is just a ZIP file but with the .epub file extension? EPUBs normally contain multiple files in different formats: XHTML, XML, JPG, etc. If you rename any .epub file to .zip, you can open it in any file compression software.

Since Atlantis automatically generates all the required EPUB components, and puts them into a ZIP file in the proper order, you do not necessarily need to know what's inside your EPUB books generated by Atlantis. But if you are familiar with the EPUB specification, at times you might need to make minor adjustments to your EPUBs not possible directly through the GUI of Atlantis.

So how to modify individual files within the EPUB package?

Since EPUBs are actually ordinary ZIP files, you can change their file extension to .zip, and open in your ZIP software. Then extract files of interest, modify them in a text editor, and put back in the ZIP file. File extension has to be changed back to .epub.

But there is one important detail to remember when you modify an EPUB file in a ZIP software. The first file in any proper EPUB package must be "mimetype". It is always a 20-byte ASCII file containing this string of text:


Even more, this file must be always stored within the EPUB package in uncompressed form.

So before tweaking your EPUB files with a ZIP software, you should be sure that it will preserve the original order of files, and leave the "mimetype" file uncompressed. Not every ZIP software will allow such "delicate" changes to a ZIP file.

But we can suggest an alternative solution to EPUB tweaking. The tweak_epub utility will allow you to adjust any text file from an EPUB package in a quite convenient way. You can download this utility from our site. Just click the following link:

and download a small file "tweak_epub.exe" (~100 KB) to any folder on your hard disk.

This utility does not require installation. Just run this "tweak_epub.exe" whenever you need to tweak an EPUB file.

It will display the "Open EPUB" window:

Direct it to the EPUB file of interest, and click "Open".

It will display another window with a complete list of files contained within your EPUB:

Click a file that you would like to modify (on the below screen capture – a file with CSS styles), then the "Edit File..." button:

The selected file will be opened in Notepad:

When you are done with editing this file, click the cross button in the title bar of Notepad, or press Alt+F4. You will get a confirmation message from Notepad:

Click "Yes" if you want to save changes.

The "Save Changes" button of the "tweak_epub" utility will become enabled:

You can click this button to complete editing the EPUB file, and save all the modified text files back to the EPUB package. Of course, you can always click the "Cancel Changes" button if you do not want to save changes to the EPUB file.

By the way, it is recommended to make a copy of the original EPUB file before tweaking it. Just in case you make an editing mistake.


Anonymous said...

Great tool that tweak epub. Thank you.

I just wish I could edit in the same way, DRM protected books that I bought.

Atlantis Word Processor Team said...

Sorry, but we do not provide assistance with DRM removal. You can google for DRM removal tools.

none said...

I have a few images at the start of my eBook that I would like to incorporate into the navigational TOC. The first page --the "title page"-- is automatically included without me doing anything. I don't see a way of adding the additional images to the TOC from within the Atlantis, so I was wondering if I can use this tweak tool to modify the TOC.ncx to add those items?

Atlantis Word Processor Team said...

No tweaking is needed. You can easily refer from the NCX to any location within your book text. Just add a "hidden heading" immediately before that location (in your case – before an image). Click here for details.
Please reply if you want me to explain this technique in more details.

Anonymous said...

Cómo puedo cambiar el margin-top con el tweak-epub.exe. Normalmente pone un 5%, le pongo otra cantidad y no funciona. ¿Qué puedo hacer?

Atlantis Word Processor Team said...

Regrettably there is no perfect way to encode page margins in EPUBs that would work identically on any eBook reader. But you will find some suggestions here.

Walt said...

It would be nice if I could right click on an epub and select open with tweak-epub and not have to search through the file structure to find the epub I just said to open.

It should pass the filename and path to tweak-epub when you open it using the Open with feature.

Atlantis Word Processor Team said...

OK, it is now possible with the latest version of the tweak_epub utility. Please just redownload the new version of the utility. Thanks.

Bdc Dbt said...

Thank you. This is a great little utility.
It is possible to use the free software Sigil for editing epubs as well, but it can be quite slow as it basically parses the entire book each time you make a change.

One thing I've found with my Sony eReader is that it gives "Page Error" if any html or xhtml section is larger than about 256KB.

Is there a way of setting up Atlantis so that it splits the chapters when they get to a given size?
Mostly it's not a problem, because it splits when there is a new heading in the text, but some docs have every long sections without a chapter break, and that 's when you run into trouble.
Manual splitting is easy in Sigil, but it's more than tweak_epub can handle.

Atlantis Word Processor Team said...

Atlantis Word Processor does not generate EPUB chapter files larger than 300 KB.

If your Atlantis Word Processor is not up-to-date, please upgrade to the latest version.

Tahlia Newland said...

What a wonderful tool. Thank you

Unknown said...

Your tweak_epub.exe causes an alert on my Norton which results in its being quarantined.

Atlantis Word Processor Team said...

This is a false positive.