Reading Epub Format

Reading ePub format

The EPUB format brings together a bunch of different specifications / formats:

  • one to say what the content of the book should look like (a subset of XHTML 1.1 + CSS)
  • one to define a "manifest" that lists all of the files that make up that content (OPF, which is an XML file)
  • one to define how everything is packaged up (OEBPS: a zip file of everything in the manifest plus a few extra files)

The specs look a bit daunting but actually once you've got the basics (unzipping, parsing XML) down it's not particularly difficult or complex.

You'll need to work out how to download the EPUB, to unzip it somewhere, to parse the manifest and then to display the relevant content.

Some pointers if you're just starting out:

  • parse xml
  • unzip

To display content just use a UIWebView for now.

Here's a high level step by step for your code:

1) create a view with a UIWebView

2) download the EPUB file

3) unzip it to a subdirectory in your app's documents folder using the zip library, linked above

4) parse the XML file at META-INF/container.xml (if this file doesn't exist the EPUB is invalid) using TBXML, linked above

5) In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.

6) parse the OPF file (also XML)

7) now you need to know what the first chapter of the book is.

a) each <item> in the <manifest> element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.

b) Look at the first <itemref> in the <spine>. It has an idref attribute which corresponds to one of the ids in (a). Look up that id in the NSDictionary and you'll get an href.

c) this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (3) plus the base directory of the OPF file in (6))

8) create an NSURL using fileURLWithPath:, where the path is the full path from (7c). Load this request using the UIWebView you created in (1).

You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the <spine> to work out which file to show next - the <itemrefs> in the XML are in the order they should appear to the reader.

where to find epuf format?

EPUB format can be found on (at this posting time)

EPUB Open Container Format (OCF) 3.2

Final Community Group Specification 08 May 2019

https://www.w3.org/publishing/epub32/epub-ocf.html

and for an older specification,

Open Packaging Format (OPF) 2.0.1 v1.0.1

Recommended Specification September 4, 2010

http://idpf.org/epub/20/spec/OPF_2.0_latest.htm

Android - epub reader to read .epub files..

Look at Epublib – a java epub library it supports in the Android.

EPUB is simply a ZIP file containing HTML, CSS, images, and metadata.

So you can use WebView to display that HTML pages. Or possible convert it to in .png or bitmap then use in ImageView.

tutorial to create e-book read application - epub file formate

There is a full tutorial for creating mobi and epubs on www.katiebooks.ca.

How to read epub files using javascript

Readium Foundation just released Readium Web Components: see http://readium.org/news/announcing-readiumjs-a-javascript-library-for-browser-based-epub-3-reading (code: https://github.com/readium/Readium-Web-Components )

Alternatively, you might want to have a look at FuturePress: http://www.futurepress.org/ (code: https://github.com/fchasen/epub.js/ )

Finally, TEA also has something you might find interesting: https://github.com/TEA-ebook/teabook-open-reader

EPUB reader/viewer in PHP

Epub.js is a javascript library for rendering ePub's in the browser, across many devices.
https://github.com/futurepress/epub.js/
It's very easy to use epub.js with php. I wrote a module to integrate it with Drupal https://drupal.org/project/epub.

How do I display epub format book in pure HTML5/CSS/Jquery

Is it possible to display epub format books in web browser using pure HTML5, CSS and jQuery?

Yes, it is possible.

Why do you want to write an epub reader? There are already many out there.

In any case, your question is a specific form of the generic question, is is possible to write an an ebook reader for epubs? Obviously, yes it is, may have been written. If you can write it in one language or for one platform, you can write it in or for another.

But actually, you don't even need to write a reader, since epubs are just little websites in a can. Unzip the epub file somewhere on your server, and navigate the browser to one of the pages. Voila, you're reading. You want a table of contents? Navigate to the toc.xhtml or equivalent file and there you go.

What about moving from one page to the next? You'll need to know what order the pages are supposed to be displayed in. Write a small server component which parses the file normally called content.opf, and based on the order of the files in the manifest element, emit some HTML which has a forward and back button and an iframe to show the content. While you're at it, parse out the title and other interesting metadata. All this is essentially what epubjs does.

But I intuit from your question that you want to do this entirely on the client/browser side. Well, that too has already been done, in the form of Readium, which you should take a look at. Use your favorite JS unzipping library (warning, can be slow) to unzip the epub file, and write a bit of JS to parse the metadata and throw up the pages, again most likely in iframes with some chrome around them.

But what if you want paginated output, which people have come to expect from ebook readers? This is where things start to get hairy, and is probably a good place to step back and ask yourself once again why you're doing this. Anyway, if you decide you really want paginated display, then you're going to need to figure out some combination of logic involving windowing, framing, clipping, offsetting, and/or using "regions" to help you here. Some ebook readers just punt here, and say, what's wrong with scrolled/unpaginated output anyway?

But ebook readers do many other things. For instance, most would allow you to change line spacing, or margins, or font sizes. How do these user settings interact with the styling in the book's CSS files? Some readers take the approach of parsing the CSS (there are libraries for that too) and rewrite it to get the results you or your user wants.

Prefer an app instead of a browser app? Wrap the whole shebang in PhoneGap.

You're going to have to worry about many, many other things to make a competent reader. Just off the top of my head, that includes displaying the "guide" or "landmarks" some books specify, remembering reading location and user options from session to session, and probably providing some kind of bookshelf functionality.

Although some client-side ebook readers do use jQuery, keep in mind that since epubs are HTML5/CSS2.5/JS, the content itself can only be reliably displayed by a modern browser. But if you have a modern browser, you don't need 90% of the hair in jQuery which is designed for cross-browser compatibility. You'd be better off with more lightweight components, such as Backbone and/or Underscore. You probably don't even need a selector library, since you'll have querySelector.

Good luck!



Related Topics



Leave a reply



Submit