gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:43 24 4
gpt4 key购买 nike

这是我尝试执行的任务,如果有人可以提供帮助,将不胜感激。所以在这段代码中,它将只显示封面。我读了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");

最佳答案

所以我在 http://www.siegmann.nl/static/epublib/apidocs/ 上使用 spine 发现了什么是它仍然按部分工作。所以我试图通过识别计数来弄清楚有多少个部分。然后将这些数字放入 Resource res = spine.getResource(i);。如果你这样做 Resource res = spine.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");

关于android - 如何使用 nl.siegmann.epublib 显示所有页面和所有章节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8259311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com