How to split up Epub Html into pages according to screen size

五迷三道 提交于 2019-12-02 18:27:21

I have done pagination effect in android like this..

-> create a custom webview class.
-> set below clients and load url then you will get horizontal scrolling with page count.
-> Lock the webview default scroll.
-> For smooth pagination effect instead of moving scroll of webview ,move the entire webview so for one page there would be one webview.
-> Use your own viewflippers to buffer previous and next pages.


I have done all these implementations and I made a product for an organisation.Just I am sharing my idea how to approach towards the best solution.Instead of using third parities and stucking in the middle due to limitation of that sdk ,make every thing your own.

private class MyWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {

            super.onPageStarted(view, url, favicon);
        }
        @Override
        public void onPageFinished(WebView view, String url) 
        {
            super.onPageFinished(view, url);

            final MyWebView myWebView = (MyWebView) view;


                String varMySheet = "var mySheet = document.styleSheets[0];";

                String addCSSRule = "function addCSSRule(selector, newRule) {"
                        + "ruleIndex = mySheet.cssRules.length;"
                        + "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"

                        + "}";

                String insertRule1 = "addCSSRule('html', 'padding: 0px; height: "
                        + (myWebView.getMeasuredHeight()/getContext().getResources().getDisplayMetrics().density )
                        + "px; -webkit-column-gap: 0px; -webkit-column-width: "
                        + myWebView.getMeasuredWidth() + "px;')";



                myWebView.loadUrl("javascript:" + varMySheet);
                myWebView.loadUrl("javascript:" + addCSSRule);
                myWebView.loadUrl("javascript:" + insertRule1);




        }
    }

    private class MyWebChromeClient extends WebChromeClient
    {
        @Override
        public void onProgressChanged(WebView view, int newProgress) 
        {
            super.onProgressChanged(view, newProgress);

            if(newProgress == 100)
            {
                postDelayed(new Runnable() 
                {
                    @Override
                    public void run() 
                    {
                        calculateNoOfPages();
                    }       

                },200);
            }
        }
    }
private void calculateNoOfPages()
    {
        if(GlobalSettings.EPUB_LAYOUT_TYPE == GlobalConstants.FIXED)
        {

        }
        else
        {
            if(getMeasuredWidth() != 0)
            {
                int newPageCount = computeHorizontalScrollRange()/getMeasuredWidth();
                getData().getChapterVO().setPageCount(newPageCount);

            }
        }
    }
@Override
    public int computeHorizontalScrollRange() {
        // TODO Auto-generated method stub
        return super.computeHorizontalScrollRange();
    }

one you load url to

Follow this github account.

FbReader provide some great libraries for epub and pdf reader. Try this....

or

You can Make your own custom WebView by extending WebView. Here you can place and modify all the functionalities you want from your WebView.

My colleague made a reader using this FbReader and It was fabulous.

Atihska

Hey I think this will help you. The answer by Nacho L worked for me. Here HTML book-like pagination?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!