Я хочу иметь возможность заменять закладки (содержимое) в документах PDF, например, «1. Пуск» на «<1. Пуск>», и сохранять замененный PDF-файл в файлы TXT.
Iиспользовал библиотеку 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.