FAQ

Frequently asked questions

How do I get the complete text of a book ?

Answer (short):

Epublib has the Book.getContents() method. This gives you all
Resources of the Book that can be reached via the Spine, the
TableOfContents or the Guide.

Answer (long):

An epub file is basically a zip file. It contains HTML files for the
book content, CSS, images and fonts.
It also contains several XML files that contain the book’s title,
author and the order in which the chapters of the book should be read.

Resources

Epublib makes the contents of all the files in the epub zip available via the
Book.getResources() method.

The Spine

The Spine, is the list of html files in the order if you were to read the book
from cover to cover.
The Spine often does not contain the cover page.

The Table of Contents

The Table of Contents contains links to various html files and sections within those files.
There may be more than one Table of Content entry pointing to the same html file.
There may be html files to which there is no Table of Content pointing.

The Guide

The Guide is a collection of links to ‘special’ pages. Examples of these are the cover (which is the only one widely used), the list of images page, the table of contents page, etc.

Conclusion

The problem of this is that none of these methods guarantee to give you the entire contents of the book.
Sometimes large HTML files are split up in pieces to save memory.
These individual pieces will all be in the Spine, but only the first piece will be referred to by the Table of Contents.
The Table of Contents may point to chapters that are not in the Spine or the Guide.
Finally there may be HTML files in the epub file that are referenced by none of these indexes.

How do I display a book’s content on Android ?

Use a  android.webkit.WebView to display the html content.

How do I display a book’s images on Android ?

Make a subclass of android.webkit.WebView that overloads the loadUrl(String) method in such a way that it loads the image from the Book instead of the internet

How do I retrieve a chapter’s title ?

There is no standard way of doing this in the epub spec.
Your options are: Get the contents of the <title>…</title> tag of the current chapter.
Or use the contents of the first h1/h2/h3… element you find in the current chapter.

Using the Table of Contents for this is highly unreliable as the Table of Contents can have duplicate entries pointing at the same chapter (One calling it “Best chapter ever” and the other “really awesome chapter” while the real name is chapter 6).