如何使用 nl.siegmann.epublib 显示所有页面和所有章节

发布于 2024-12-18 00:49:53 字数 1248 浏览 0 评论 0原文

这就是我尝试执行的任务,如果有人可以提供帮助,将不胜感激。所以在这段代码中它将只显示封面。我读了 http://www.siegmann.nl/static/epublib/apidocs/您可以使用 getSpine() 来获取所有内容,但它只在我的案例中显示一件事,即封面页。

webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
AssetManager am = getAssets();
try {
    InputStream epubInputStream = am.open(bookName);
    book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e) {
    Log.e("epublib", e.getMessage());
}

Spine spine = book.getSpine(); 
for (SpineReference bookSection : spine.getSpineReferences()) {
    Resource res = bookSection.getResource();

    try {
        InputStream is = res.getInputStream();
        StringBuffer string = new StringBuffer();
        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");

This is what I tried to perform the task if anyone can help out it would be most appreciated. So in this code it will display just the cover page. I read http://www.siegmann.nl/static/epublib/apidocs/ that you could use getSpine() to get everything but it only displayed one thing on my case which is cover page.

webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
AssetManager am = getAssets();
try {
    InputStream epubInputStream = am.open(bookName);
    book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e) {
    Log.e("epublib", e.getMessage());
}

Spine spine = book.getSpine(); 
for (SpineReference bookSection : spine.getSpineReferences()) {
    Resource res = bookSection.getResource();

    try {
        InputStream is = res.getInputStream();
        StringBuffer string = new StringBuffer();
        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");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最冷一天 2024-12-25 00:49:53

那么我在 http://www.siegmann.nl/static/epublib/ 上使用脊柱的结果apidocs/ 的优点是它仍然按部分工作。所以我试图通过识别计数来找出有多少个部分。然后将这些数字放入 Resource res = spin.getResource(i); 中。如果你这样做 Resource res = spin.getResource(2); 它将显示 2 的书脊,这应该是第 2 章,除非有人弄乱了 epub 的格式。

Spine spine = book.getSpine(); 
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
tv.setText(Integer.toString(count));
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");

So what I figured out using spine on http://www.siegmann.nl/static/epublib/apidocs/ is that it still works by sections. So I tried to figure out how many sections are there by identifying count numbers. Then placed those numbers in Resource res = spine.getResource(i);. If you would do Resource res = spine.getResource(2); It would display the spine of 2 which should be chapter 2 unless someone messes up the format of the epub.

Spine spine = book.getSpine(); 
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
tv.setText(Integer.toString(count));
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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文