0
我正在使用Apache PDFBox版本2.0.x.我正尝试使用书签搜索PDF,当我打开目标时,我应该能够获得书签所指的Pagenumber。这是我的代码打印所有书签。我可以做,如果我的标题搜索文本匹配,那么这是我的目标书签等号像searchText.equals(current.getTitle())
如何使用PDFBox获取PDF中的书签内容的页码数
public static void printBookmark(PDOutlineNode bookmark, String indentation) throws IOException {
PDOutlineItem current = bookmark.getFirstChild();
COSObject targetPageRef = null;
while (current != null) {
System.out.println(indentation + current.getTitle());
printBookmark(current, indentation + " ");
current = current.getNextSibling();
}
}
搜索。任何人之前尝试过?
请将'PDPageFitWidthDestination'替换为'PDPageDestination',并为'current.getDestination()'添加一个实例检查。不能保证你每次都很幸运:-) –