After a lot of search, i finally found a solution to read ePub files for iphone.Few months before i had posted a question in stackerflow.com about a reader for ePub files in iphone.So many peoples answered with their ideas.From the various answers got from there i finally created a reader for ePub.
Here are the steps to create an ePub reader.
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
Here are the steps to create an ePub reader.
- Create a view with a UIWebView
- Download the EPUB file
- Unzip it to a subdirectory in your app's documents folder
- Parse the XML file at META-INF/container.xml (if this file doesn't exist the EPUB is invalid) using TBXML, linked above
- In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book
- Parse the OPF file (also XML).
- 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
- (c) Look up that id in the NSDictionary and you'll get an href.
- (d) 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
Thanks so much for your brilliant work. You save my life.
ReplyDeleteyes, i find it. thx a lot
ReplyDeleteGreat exemple....
ReplyDeleteVery clearfull and descriptive.
I used it with instruments and shows 38 mem leak... Do you know how to solve it??
Thanks!! :)
Thank you so much. Saved me a lot of time.
ReplyDeletegreat example...
ReplyDeleteWow, Great tutorial. Is there a way to include a search a word capability? Thanks in advance
ReplyDeleteThanQ dear
ReplyDelete@Sreelal: I am getting strange behaviour of this ePub reader..It automatically displays all fonts in BOLD..Can you tell me the solution??
ReplyDeleteThis puts me a step ahead. Thanks!
ReplyDeleteThis comment has been removed by the author.
ReplyDeletemaybe you can add this code to swipe the page
ReplyDeleteUISwipeGestureRecognizer *rightSwipeRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoNextPage)] autorelease];
[rightSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
UISwipeGestureRecognizer *leftSwipeRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoPrevPage)] autorelease];
[leftSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[_webview addGestureRecognizer:rightSwipeRecognizer];
[_webview addGestureRecognizer:leftSwipeRecognizer];
Thanks this tutorial , it help me a lot !
PS.How to read the book not using scroll down ?I think like page control is batter than scroll down reading : )
Is there a way to include a search a word capability? Thanks in advance
ReplyDeleteTo Ronak :Maybe you can check this sample
ReplyDeletehttps://github.com/fedefrappi/AePubReader
Thanks a alot sir
Deletesometimes i think why to share my code on net when i put so much efforts on it for months, but seeing such codes i realized there is nothing wrong in sharing our code with other developers it really helps .
Respected Sir,
ReplyDeletehere i am using the sample for parsing the epub as "https://github.com/fedefrappi/AePubReader "
But how can i bookmark the page while changing the font size as well as the font family
Kindly help Me Sir...
Did you get the answer of this if yes then please can you share
DeleteNo, still i didnt receive any answers , if you have any ideas means kindly share with me
DeleteThanks for wonder full tutorial it was very useful for me but as I am new to XPATH, i need small help.
ReplyDeleteHere is my scenario -
Let suppose i have already
href = @"abcdef1 "
but inside my toc.ncx i have an entry that is "abcdef1#tocmarker-1" corresponding to href of .opf
I have to find the node for "abcdef1#tocmarker-1"
using function
- (void) parseOPF:(NSString*)opfPath- (void) parseOPF:(NSString*)opfPath
{
NSString* xpath = [NSString stringWithFormat:@"//ncx:content[@src='%@']/../ncx:navLabel/ncx:text", href];
NSArray* navPoints = [ncxToc nodesForXPath:x namespaceMappings:[NSDictionary dictionaryWithObject:@"http://www.daisy.org/z3986/2005/ncx/"
}
how can i get node by nodesForXPath in above function for , src="abcdef1#tocmarker-1"
I am not sure how it can be done in objective C.
If possible please help me
Dear Sandeep.
DeleteI am also struggle with the same issue., pls share the idea with me if you got any solution ..
Thanks.,
Manik.,
Respected Sir,
ReplyDeletehow can we implement the pagecurl animation in similar to ibook, kindly help me sir
How to mock the same steps for the the Android? Any idea?
ReplyDeleteThanks!
How to add bookmarks and highlighting in epub
ReplyDeleteHey did u get ny soln 4 dis...I m workin on same prjct but on Android & I m facing d same issues....do tell me if u get ny soln !!!
Delete@Nishant - i am also trying to implement an android epub using monocle js library. It is working good in mobiles where as in Tablets it is not working properly.
DeleteCould you suggest any other library for android.
Well, I am afraid I have no idea regarding this. I am a student & a beginner in Android.
Delete& by the way did you get any way for highlighting text permanently?
i downloaded this project, but m getting this errors,
ReplyDeleteld: warning: ignoring file /Users/krunal/Downloads/EpubReader/libz.1.2.3.dylib, missing required architecture i386 in file
Undefined symbols for architecture i386:
"_inflateEnd", referenced from:
_unzCloseCurrentFile in unzip.o
"_inflateInit2_", referenced from:
_unzOpenCurrentFile3 in unzip.o
"_get_crc_table", referenced from:
_unzOpenCurrentFile3 in unzip.o
_zipOpenNewFileInZip3 in zip.o
"_crc32", referenced from:
_unzReadCurrentFile in unzip.o
_zipWriteInFileInZip in zip.o
-[ZipArchive addFileToZip:newname:] in ZipArchive.o
"_inflate", referenced from:
_unzReadCurrentFile in unzip.o
"_deflateInit2_", referenced from:
_zipOpenNewFileInZip3 in zip.o
"_deflate", referenced from:
_zipWriteInFileInZip in zip.o
_zipCloseFileInZipRaw in zip.o
"_deflateEnd", referenced from:
_zipCloseFileInZipRaw in zip.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
how to solve this any idea ?
If you're attempting to build/run for iOS 5.x+, then try removing the 1.2.3 library and adding 1.2.5 in the 'Linked Frameworks and Libraries' section of the project target summary.
Deletethank you it's working :)
DeleteHi friends,
ReplyDeleteThis tutorial and sample code is very useful for me..
Thank u so much for ur great effort..
Please anyone guide me about,
1.How can i find the page size and no.of pages in each chapter?
2.How to setup horizontal scroll instead of vertical?
Please anyone help me..
Thanks in advance..
Hi. this is very great tutorial..
ReplyDeleteI'm using https://github.com/fedefrappi/AePubReader for my application.. My client requirement is to show two pages in ipad landscape mode.. like iBook application.. does any one have idea to implement.. Please share me link.. or mail me to bhilwadi.madhu@gmail.com . thanks
I have problem like fueqotusecog.
ReplyDeleteHow can I resolve this error.
Thanks
thank you so much!!!!
ReplyDeleteHi..
ReplyDeleteThis is very good example. but I want some more features in it. Any body know how to add annotation to this library.
Thanks In advance. Please help me out.
Hi...
ReplyDeleteI am working with custom epub book reader where I have a book.html file as a book and a book.properties and content.toc file I want to create a book (book.html) reader using UIWebView with pagination with all the features of book reader. Please help me how can I implement this ? I have googled lots of search but unable to find any good tutorial which read a single html file with pagination and all the features.
hello its really gr8 app...But m having one prblem...actually m downloading epub file from server in my app's document directory but my epub is not opening...i hav used your code for open it ...but UnzippedEpub folder is not creating in app's document folder..pls help me for this issue...
ReplyDeleteHi ,
DeleteIs that issue fixed?
I'm getting an error on XMLHandler.m file at [_parser parse]; line, can any one solve this problem. thanks in advance.
ReplyDeletehi guys,
ReplyDeletei need epub reader for arabic, can anyone help me ? if so then please send me code by email : umair2071@ymail.com.
i will be very thankful :)
@Zahid Hossain,
ReplyDeletereplace your code with this it will work perfect,
dispatch_queue_t reentrantAvoidanceQueue = dispatch_queue_create("reentrantAvoidanceQueue", DISPATCH_QUEUE_SERIAL);
dispatch_async(reentrantAvoidanceQueue, ^{
_parser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL fileURLWithPath:strPath]];
_parser.delegate=self;
if (![_parser parse]) {
NSLog(@"There was an error=%@ parsing the xml. with data %@", [_parser parserError], [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:strPath]] encoding: NSASCIIStringEncoding]);
}
//[_parser release];
});
dispatch_sync(reentrantAvoidanceQueue, ^{ });
hi guys,
ReplyDeletei need epub reader for arabic, can anyone help me ? if so then please send me code by email : umair2071@ymail.com.
i will be very thankful :)
I have to bookmark page or highlight text, can you guide how I can do this ?
ReplyDeleteThanks
Showing ld: library not found for -lz.1.2.3
ReplyDeleteclang: error: linker command failed with exit code 1 (use -v to see invocation)
Nice Blog
ReplyDeletePython Full stack Training Institutes in KPHB, Hyderabad
Python Full stack Training Institutes in KPHB, Hyderabad