I want to implement an ePub reader for the iOS platform. Please suggest any open source code for book flipping animation, bookmarks, font-size customization and single page view (without scroll bars).
As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:
- Unzip the ePub
- Read the manifest file and metadata file to find the xhtml documents to display
- Load the xhtml documents into a UIWebView using a file:/// URL to the unzipped document
If you want to ensure that the documents don't hit the network you'll need to implement a custom NSURLProtocol and serve the bytes for the files yourself as file:/// allows cross domain access.
That will display the content just fine, but the "hard" part is moving between the documents (which usually represent a whole chapter). This is the work that iBooks and other apps do for you.
NOTE: For the UIWebView to display the content correctly, you have to ensure that the file has a .xhtml extension when using file:/// urls. If you implement your own URL protocol handler, you need to make sure the protocol handler returns the correct xml content type for xhtml, namely:
application/xhtml+xml
Use the ePub packaging format and an open-source reader for reference:
Try this steps :
Source code: AePubReader
Implementation:
Step 1: Create a view with a UIWebView
Step 2: Download an EPUB file and import into your project
Step 3: Unzip EPUB file to a subdirectory in your app's documents folder.
Step 4: Parse the XML
file from directory META-INF/container.xml
. If this file directory doesn't exist means, your EPUB file is invalid.
Step 5: In this XML
, find the first "rootfile
" with media-type application/oebps-package+xml
. This is the OPF file for the book.
Step 6: Parse the OPF file (also XML)
Step 7: Now you need to know what the first chapter of the book is.
- Each in the element has an id and an href. Store these in an
NSDictionary
where the key is the id and the object is the href. - Look at the first in the . It has an idref attribute which corresponds to one of the ids in (Step 7a). Look up that id in the
NSDictionary
and you'll get an href. - 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 (Step 3), plus the base
NSDictionary
of the OPF file in (Step 6).
Step 8: Create an NSURL
using fileURLWithPath:, where the path is the full path from (Step 7c). Load this request using the UIWebView you created in (Step 1).
Step 9: You'll need to implement forward / backward
buttons or swipes
or something so that users can move from one chapter to another. Use the to work out which file to show next. Then the XML
are in the order they should appear to the reader.
These step got referred from this link
Use UITextView with pageview controller . (Specify your doubts , if any)
© 2022 - 2024 — McMap. All rights reserved.