Thursday, July 1, 2010

Working with ePub files in Flash and the Text Layout Framework

Walflower is an ActionScript framework for working with ePub files in Flash. You can download the code from github at http://www.github.com/maxl0rd/walflower.

EPub is an open-source format that has become one of the most popular ways of distributing non-DRM-protected eBooks. It is essentially a zip file containing a directory of XHTML documents, supporting files like images, and a variety of manifests and metadata that describe the shape of the document, the order it should be read, etc.

Walflower integrates the nice zip library written by nochump, which is not the fastest unzip routine ever seen, but it works quite nicely. It then parses all the book meta-data into various data structures that describe the book. Finally, it works through all the XHTML pages and parses them into TextFlows that can be displayed with the Text Layout Framework, as described in a previous post.

There is a sample project up in the repo that shows this in action here: http://github.com/maxl0rd/walflower/tree/master/examples/EPubExample/

It does not generate any output yet, but it would be a good starting point for a project based on this lib. The process of making sense of this file format was rather horrible, and I hope this code is useful to anyone on the same path.

You can see an example eBook reader that was made with this library over here:
walflower halloween book teaser.

5 comments:

  1. Hi Max,

    I am Uday Bhaskar from India. I am using your files of EPubExample in my project to read epub format in flex, to display the book content on stage i am not getting any clue. please help me, how I can do that? Thank you in Advance.

    ReplyDelete
  2. Hi Uday

    The walflower project that I am showing here does not include any display code. It only unzips and parses epubs into data structures, and translates xhtml into textflow.

    You will have to learn how to use the Text Layout Framework, and write your own display code to paginate and style a document to create an epub reader from this. Luckily, using TLF is documented on many places on the web.

    ReplyDelete
  3. Hi Max
    May I download Walflower v2.0 source code.
    Thank you.

    kevin chao

    ReplyDelete
  4. I see it's been quite some time since you blogged on this project or made any changes to the git repo. I'm interested in doing something similar, and if you're willing, I would love to see the code used in your demo application (the one that actually displays content). Would you mind sharing it?

    ReplyDelete
  5. Hi
    This is a way to read ePub format I want to get output in ePub format. please can you have any solution or example please explain it...

    Vinitkar Tripathi
    Spark'ans.

    ReplyDelete