Epub Reader

From: http://ideveloperworld.blogspot.in/2011/02/epub-reader.html


(Reference: http://stackoverflow.com/questions/1388467/reading-epub-format


http://stackoverflow.com/questions/9358311/pagination-and-images-in-epub-books?rq=1

)

(Build a digital book with EPUBhttp://www.ibm.com/developerworks/xml/tutorials/x-epubtut/index.html)


Here are the steps to create an ePub reader.

1) create a view with a UIWebView


2) download the EPUB file


3) unzip it to a subdirectory in your app's documents folder .


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.

Thanks to Euan(Stackoverflow.com)

You can download the sample code from here
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值