我使用“Siegmann epublib”库来提取 android 项目中 epub 文件的内容。我可以显示这本书的全部内容并对其进行分页;但是我应该如何找到目录和这些页面之间的相关性?因为目录具有树形结构,但资源(本书的内容)是一个没有任何深度的列表。
这是我获取总内容的代码:
List<Resource> resources = book.getContents();
StringBuilder total = new StringBuilder();
for(int i = 0;i < resources.size();i++){
Resource resource = resources.get(i);
String htmlData = new String(resource.getData());
total.append(TextTools.htmlToText(htmlData));
}
这就是我获取目录的方式:
List<TOCReference> tocReferences = book.getTableOfContents().getTocReferences();
for(int i = 0;i < tocReferences.size();i++){
// Get tree structure of table of contents
// If has children use a nested loop to get them...
}