如何使用 nl.siegmann.epublib 显示所有页面和所有章节
这就是我尝试执行的任务,如果有人可以提供帮助,将不胜感激。所以在这段代码中它将只显示封面。我读了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么我在 http://www.siegmann.nl/static/epublib/ 上使用脊柱的结果apidocs/ 的优点是它仍然按部分工作。所以我试图通过识别计数来找出有多少个部分。然后将这些数字放入
Resource res = spin.getResource(i);
中。如果你这样做Resource res = spin.getResource(2);
它将显示 2 的书脊,这应该是第 2 章,除非有人弄乱了 epub 的格式。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 doResource 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.