我希望能够替换PDF文档中的书签(内容),例如从“ 1.开始”到“ <1.开始>”,并将替换的PDF保存到TXT文件中。
我使用Java的pdfbox库完成了从PDF到txt的转换。然后,我完成了书签(内容)的提取,并使用String保存了所有书签,该字符串已成功写入TXT文件。但是,在转换书签(内容)之后,我无法成功保存转换书签的PDF。
// Used to save bookmark strings
private static String res = "";
// Recursive calls to get bookmark
private static void printBookmark(PDOutlineNode bookmark, int indentation) throws IOException {
PDOutlineItem current = bookmark.getFirstChild();
while (current != null) {
res += "<" + indentation + ">" + current.getTitle() + "\n";
// Can I add some code here to change the bookmark of the loaded PDDocument?
// I tried to define temp_current, temp_bookmark to store the desired value and
// finally assign it to the PDDocument object, but it failed.
printBookmark(current, indentation + 1);
current = current.getNextSibling();
}
}
对书签的任何更改都不会影响我从PDF保存为txt的文件。