是否可以删除选定的书签(又名轮廓)?

Is it possible to remove selected bookmarks (aka outlines)?

可以使用 iText 7 从文档的大纲树中删除现有书签吗? PdfOutline class 有添加轮廓的方法,但有 none 删除轮廓的方法。

我尝试有选择地将大纲复制到列表中,使用 PdfDocument.getCatalog.remove(PdfName.Outlines) 删除所有现有大纲,然后用我的列表元素重新填充文档大纲。新大纲以我想要的方式出现,但是当我单击任何书签时,它们将我带到文档中的错误位置。

使用 7.1.12-SNAPSHOT 版本,您已经可以使用 public API:

删除大纲(及其所有子项递归)
PdfOutline root = pdfDocument.getOutlines(true);
// Getting third child (as indices are 0-based)
PdfOutline toRemove = root.getAllChildren().get(2);
// Removing outline and all its children recursively (so we are removing a subtree)
toRemove.removeOutline();