如何使用PDFBox删除PDF文件中的注释

How to delete annotations in PDF file using PDFBox

我想删除 PDF 文件中所有现有的注释。我在 PDFBox Annotaions API 中找不到任何直接方法或 API。请提供解决问题的任何指示。

在此先感谢您的帮助。

假设您有一个 PDPage 对象,只需这样做:

pdPage.setAnnotations(null);

这是 1.8.* 版 PDFBox 的完整代码:

PDDocument document = PDDocument.loadNonSeq(new File(pdfFilename), null);
List<PDPage> pdPages = document.getDocumentCatalog().getAllPages();
for (PDPage pdPage : pdPages)
{ 
    pdPage.setAnnotations(null);
}
document.save(new File(...));
document.close();