pagination and images in ePub books

I build a epub engine that can read ePub books with many features like pagination, add note, highlight, search, etc. Everything is working fine but am stuck with 2 problems.

These are the JavaScript functions I use to paginate:

function setupBookColumns(){
    var body = document.getElementsByTagName('body')[0].style;
    body.marginLeft = 0;
    body.marginRight = 0;
    body.marginTop = 0;
    body.marginBottom = 0;


    var bc = document.getElementById('book-columns').style;

    bc.width = (window.innerWidth * 2) + 'px !important';
    bc.height = (window.innerHeight-kMaxFont) + 'px !important';
    bc.marginTop = '0px !important';
    bc.webkitColumnWidth = window.innerWidth  + 'px !important';
    bc.webkitColumnGap = '0px';
    bc.overflow = 'visible';

    if ( gCurrentPage < 0 )
        gCurrentPage = 1;
    gProgress = gPosition = 0;

    var bi = document.getElementById('book-inner').style;
    bi.marginLeft = '0px';
    bi.marginRight = '0px';
    bi.padding = '0';

    gPageCount = document.body.scrollWidth / window.innerWidth;

    // Adjust the page count to 1 if it's invalid
    if (gPageCount < 1) {
        gPageCount = 1;
    }
}


function paginate()
    {   

    if (gClientHeight == undefined) {
        gClientHeight = document.getElementById('book-columns').clientHeight;
    }

    var leftBlocker = document.getElementById('left-blocker');
    var parent = leftBlocker.parentNode;
    parent.removeChild(leftBlocker);
    leftBlocker.style.left = '-200px';

    var rightBlocker = document.getElementById('right-blocker');
    parent.removeChild(rightBlocker);
    rightBlocker.style.left = '-200px';

    setupBookColumns();

    parent.appendChild(leftBlocker);
    parent.appendChild(rightBlocker);
}

I load the html file (Chapter file) in a webView when its finish loading I call the paginate function which I posted above .. this give a number of pages based on the amount of text, size of text, the frame of what hold text (in my case the webView) .. so that I can goForward and goBack using a JavaScript function.

  • Integrating Ruby on Rails with Epub.js
  • FInding out when page is being viewed in EPUB FXL via Javascript
  • How to highlight text permanently in WebView in Android?
  • Javascript firing intermittently when turning page in iBooks
  • What javascript works as expected in epub using iBooks?
  • Epub.js - Phonegap not working because of blob URI