使用 Java 导入和导出批注
Contents
[
Hide
]
将批注从一个 PDF 复制到另一个 PDF
- 打开源 PDF 并创建一个带有目标页的新目标文档。
- 枚举第一页上的批注,并将每个批注添加到目标页。
- 保存目标文档以保留已复制的批注。
public static void importExport(Path inputFile, Path outputFile) {
try (Document sourceDocument = new Document(inputFile.toString());
Document destinationDocument = new Document()) {
Page page = destinationDocument.getPages().add();
for (Annotation annotation : sourceDocument.getPages().get_Item(1).getAnnotations()) {
page.getAnnotations().add(annotation, true);
}
destinationDocument.save(outputFile.toString());
}
}