How to implement an ePub reader for an iPad/iPhone app [closed]
Asked Answered
U

4

8

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).

Undertone answered 3/9, 2012 at 5:37 Comment(2)
Hi - the question has already been asked and answered here: #3360258Kaufmann
Yes. As per the answer I think we can display content of XHTML file in uiwebview. But I also want to split pages in a way that it doesn't have any scroll bar.Undertone
H
4

As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:

  1. Unzip the ePub
  2. Read the manifest file and metadata file to find the xhtml documents to display
  3. 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

Hustler answered 3/9, 2012 at 7:5 Comment(5)
Thanks for the reply, I understand the whole process but I have one query As you told "That will display the content just find, 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." Does iBook and other apps which can provide their reader which we can implement/use in our custom application??Undertone
@KanakVaghela no, at least nothing public.Renovate
@KanakVaghela Nir Levy is correct, there is nothing public.Hustler
@KanakVaghela how can we imapelement the landscape mode which is similar to iBook could you help me pleaseLiminal
Upvoted for beautifully explaining the process.Junction
P
4

Use the ePub packaging format and an open-source reader for reference:

Parapet answered 12/3, 2013 at 0:2 Comment(0)
M
1

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

Melise answered 13/5, 2014 at 9:33 Comment(0)
M
1

Use UITextView with pageview controller . (Specify your doubts , if any)

Meneau answered 22/5, 2014 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.