使用epublib逐页读取epub文件



我正在研究一个应用程序,其中我想使用epublib逐页阅读epub文件并在应用程序中显示,我能够获得书章节明智的所有内容,现在我想获得内容页面明智,如果你有任何想法,请回答,提前感谢

这是我用来获取图书章节内容的代码

    public String getText(String filepath) {
    String linez = "";
    File f = new File(filepath);
    InputStream epubInputStream = null;
    try {
        epubInputStream = new FileInputStream(f);
    } catch (FileNotFoundException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    Book book = null;
    try {
        book = (new EpubReader()).readEpub(epubInputStream);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Spine spine = book.getSpine();
    List<SpineReference> spineList = spine.getSpineReferences();
    int count = spineList.size();
    txtpages.setText("Size:" + Integer.toString(count) + "n");
    StringBuilder string = new StringBuilder();
    for (int i = 0; count > i; i++) {
        Resource res = spine.getResource(i);
        try {
            InputStream is = res.getInputStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is));
            try {
                while ((line = reader.readLine()) != null) {
                    linez = string.append(line + "n").toString();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            // do something with stream
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //webView.loadData(linez, "text/html", "utf-8");

    return linez;
}

您可以使用EpubParser逐页分离epub文件。

相关内容

  • 没有找到相关文章

最新更新