Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:33:31+00:00 2026-06-09T19:33:31+00:00

I am using AePubreader sample code for reading ePub in my app. The issue

  • 0

I am using AePubreader sample code for reading ePub in my app. The issue I am facing is that the last page of the chapters are not rendered properly and they go off the visible area. I had edited AePubreader code in following way to convert in a two page mode in ipad.

-In chaper.m file the webViewDiDFinishLoading has following code :

- (void) webViewDidFinishLoad:(UIWebView*)webView{
    NSString *varMySheet = @"var mySheet = document.styleSheets[0];";


    NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
    "if (mySheet.addRule) {"
        "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
    "} else {"
        "ruleIndex = mySheet.cssRules.length;"
        "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
    "}"
    "}";


NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding-left: 0px;padding-right: 0px; padding-top: 0px; padding-bottom: 0px; height: %fpx;-webkit-column-count: 2; -webkit-column-gap: 0px; ')", webView.frame.size.height];    

    NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
    NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')",fontPercentSize];

    NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:%fpx;')", webView.frame.size.width-200,webView.frame.size.height-200];


    NSString *setFontRule = [NSString stringWithFormat:@"addCSSRule('body', 'font-family: Arial;' , 'font-name: Arial-BoldItalicMT;')"];

    [webView stringByEvaluatingJavaScriptFromString:setFontRule];
    [webView stringByEvaluatingJavaScriptFromString:setImageRule];

    [webView stringByEvaluatingJavaScriptFromString:varMySheet];

    [webView stringByEvaluatingJavaScriptFromString:addCSSRule];

    [webView stringByEvaluatingJavaScriptFromString:insertRule1];

    [webView stringByEvaluatingJavaScriptFromString:insertRule2];

    [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];

    float totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"] floatValue];
    pageCount = (ceilf)((float)totalWidth/webView.frame.size.width);

    NSLog(@"Chapter %d: %@ -> %d pages & totalWidth :: %f", chapterIndex, title, pageCount,totalWidth);

    [webView dealloc];
    [delegate chapterDidFinishLoad:self];

}

In EpubViewController.m webViewDidFinishLoading is as follows:-

- (void)webViewDidFinishLoad:(UIWebView *)theWebView{

    NSString *varMySheet = @"var mySheet = document.styleSheets[0];";

    NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
    "if (mySheet.addRule) {"
    "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
    "} else {"
    "ruleIndex = mySheet.cssRules.length;"
    "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
    "}"
    "}";



NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding-left: 0px;padding-right: 0px; padding-top: 0px; padding-bottom: 0px; height: %fpx;-webkit-column-count: 2; -webkit-column-gap: 0px; ')", webView.frame.size.height];    


    NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
    NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];
    NSString *setHighlightColorRule = [NSString stringWithFormat:@"addCSSRule('highlight', 'background-color: yellow;')"];

    NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:%fpx;')", (webView.frame.size.width/2)-200,webView.frame.size.height-150];

    NSString *setFontRule = [NSString stringWithFormat:@"addCSSRule('body', 'font-family: Arial;' , 'font-name: Arial-BoldItalicMT;')"];

    [webView stringByEvaluatingJavaScriptFromString:setFontRule];

    [webView stringByEvaluatingJavaScriptFromString:setImageRule];

    [webView stringByEvaluatingJavaScriptFromString:varMySheet];

    [webView stringByEvaluatingJavaScriptFromString:addCSSRule];

    [webView stringByEvaluatingJavaScriptFromString:insertRule1];

    [webView stringByEvaluatingJavaScriptFromString:insertRule2];

    [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];

    [webView stringByEvaluatingJavaScriptFromString:setHighlightColorRule];

    if(currentSearchResult!=nil){
    //  NSLog(@"Highlighting %@", currentSearchResult.originatingQuery);
        [webView highlightAllOccurencesOfString:currentSearchResult.originatingQuery];
    }

//  int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] intValue];

//    NSLog(@">>>>>>>>>>>>>>>>>>>>>>>total width is %d",totalWidth);
//    CGFloat moduloResult = (float)(totalWidth/((int)webView.bounds.size.width % 2));

  //NSLog(@"moduloresult is %f",moduloResult);

//  pagesInCurrentSpineCount = (round)((float)totalWidth/(webView.frame.size.width));
    float pageCountofChapter = [[loadedEpub.spineArray objectAtIndex:currentSpineIndex] pageCount];
    pagesInCurrentSpineCount =(ceilf)(pageCountofChapter/2.0);

    UIScrollView* sv = nil;
    for (UIView* v in  webView.subviews) {
        if([v isKindOfClass:[UIScrollView class]])
        {
            sv = (UIScrollView*) v;
            sv.contentSize = CGSizeMake(pagesInCurrentSpineCount*1024, sv.contentSize.height);
        }
    }

//    NSLog(@"TotalWidth :: %d && pagesInCurrentSpineCount :: %d  && currentPageInSpineIndex :: %d",totalWidth,pagesInCurrentSpineCount,currentPageInSpineIndex);

    [self gotoPageInCurrentSpine:currentPageInSpineIndex];
}

I have noticed that when the pages calculated are in odd numbers the last page of the chapter is not rendered properly ? Also , is there any alternative library available which provides two page mode support to accurately render epub?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:33:32+00:00Added an answer on June 9, 2026 at 7:33 pm

    @dineshprasanna do following changes in your project.

    in chapter.m file

    - (void) webViewDidFinishLoad:(UIWebView*)webView{
        NSString *varMySheet = @"var mySheet = document.styleSheets[0];";
    
    
        NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
        "if (mySheet.addRule) {"
            "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
        "} else {"
            "ruleIndex = mySheet.cssRules.length;"
            "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
        "}"
        "}";
    
    //  NSLog(@"w:%f h:%f", webView.bounds.size.width, webView.bounds.size.height);
    
    
    
       NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding-left: 50px;padding-right: 50px; padding-top: 50px; padding-bottom: 50px; -webkit-column-gap: 100px;height: %fpx; -webkit-column-width : %fpx')", webView.frame.size.height-100,webView.frame.size.width/2-200];    
    
        NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
        NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')",fontPercentSize];
    
    //    NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:auto;')", webView.frame.size.width *0.75];
        NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:%fpx;')", webView.frame.size.width/2-200,webView.frame.size.height-200];
    
    
        NSString *setFontRule = [NSString stringWithFormat:@"addCSSRule('body', 'font-family: Arial;' , 'font-name: Arial-BoldItalicMT;')"];
    
        [webView stringByEvaluatingJavaScriptFromString:setFontRule];
        [webView stringByEvaluatingJavaScriptFromString:setImageRule];
    
        [webView stringByEvaluatingJavaScriptFromString:varMySheet];
    
        [webView stringByEvaluatingJavaScriptFromString:addCSSRule];
    
        [webView stringByEvaluatingJavaScriptFromString:insertRule1];
    
        [webView stringByEvaluatingJavaScriptFromString:insertRule2];
    
        [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
    
        int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] floatValue];
        pageCount = (ceilf)((float)totalWidth/webView.frame.size.width);
    
        if (totalWidth % (int)webView.frame.size.width != 0)
        {
            UIScrollView *scrollV = [self getScrollViewFromWebView:webView];
            scrollV.contentSize = CGSizeMake(pageCount*(webView.frame.size.width), webView.scrollView.contentSize.height);
    
        }
    
    
        NSLog(@"Chapter %d: %@ -> %d pages & totalWidth :: %d", chapterIndex, title, pageCount,totalWidth);
    
        [activityIndicator removeFromSuperview];
        [activityIndicator stopAnimating];
        [webView dealloc];
    
    
        [delegate chapterDidFinishLoad:self];
    
    }
    

    in your epubviewcontroller file :-

    - (void)webViewDidFinishLoad:(UIWebView *)theWebView{
    
        NSString *varMySheet = @"var mySheet = document.styleSheets[0];";
    
        NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
        "if (mySheet.addRule) {"
        "mySheet.addRule(selector, newRule);"                               // For Internet Explorer
        "} else {"
        "ruleIndex = mySheet.cssRules.length;"
        "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
        "}"
        "}";
    
    
    
    //    NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'PADDING-LEFT: 25px; padding-top: 100px; padding-right: 25px; height: %fpx; -webkit-column-gap: 50px; -webkit-column-width:%fpx;')", webView.frame.size.height-200, (webView.frame.size.width/2-100) ];
    
        NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding-left: 50px;padding-right: 50px; padding-top: 50px; padding-bottom: 50px; -webkit-column-gap: 100px;height: %fpx; -webkit-column-width : %fpx')", webView.frame.size.height-100,webView.frame.size.width/2-200];     
    
    
        NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
        NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];
        NSString *setHighlightColorRule = [NSString stringWithFormat:@"addCSSRule('highlight', 'background-color: yellow;')"];
    
        NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:%fpx;')", (webView.frame.size.width/2)-200,webView.frame.size.height-200];
    
        NSString *setFontRule = [NSString stringWithFormat:@"addCSSRule('body', 'font-family: Arial;' , 'font-name: Arial-BoldItalicMT;')"];
    
        [webView stringByEvaluatingJavaScriptFromString:setFontRule];
    
        [webView stringByEvaluatingJavaScriptFromString:setImageRule];
    
        [webView stringByEvaluatingJavaScriptFromString:varMySheet];
    
        [webView stringByEvaluatingJavaScriptFromString:addCSSRule];
    
        [webView stringByEvaluatingJavaScriptFromString:insertRule1];
    
        [webView stringByEvaluatingJavaScriptFromString:insertRule2];
    
        [webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
    
        [webView stringByEvaluatingJavaScriptFromString:setHighlightColorRule];
    
        if(currentSearchResult!=nil){
        //  NSLog(@"Highlighting %@", currentSearchResult.originatingQuery);
            [webView highlightAllOccurencesOfString:currentSearchResult.originatingQuery];
        }
    
    
        float pageCountofChapter = [[loadedEpub.spineArray objectAtIndex:currentSpineIndex] pageCount];
        pagesInCurrentSpineCount =pageCountofChapter;
    
        int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] floatValue];
    
        if (totalWidth % (int)webView.frame.size.width != 0)
        {
            UIScrollView *scrollV = [self getScrollViewFromWebView:webView];
            scrollV.contentSize = CGSizeMake(pagesInCurrentSpineCount*(webView.frame.size.width), webView.scrollView.contentSize.height);
    
        }
    
        [self gotoPageInCurrentSpine:currentPageInSpineIndex];
    }
    

    Hope this will help you. Arrange the padding and margin as per your requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using AePubReader for reader ePub files. How can i add page curl
Using Yii, I want to delete all the rows that are not from today.
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using Server.Transfer to show a page that informs the user that the web site
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
Using report builder 3.0, I have a report that queries a cube. How do
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
Using Github's Issue Tracker, how can one create an issue tied to an organization

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.