使用 Java 导入和导出批注
Contents
[
Hide
]
将批注从一个 PDF 复制到另一个 PDF
- 打开源 PDF Document。
- 将一个 Page 添加到目标 Document。
- 将每个 Annotation 添加到目标 Page。
- 读取或遍历 Annotation 目标页上的项目。
- 保存更新后的 PDF Document。
- 枚举第一个源页面上的 Annotation 对象,并将每个对象添加到目标页面。
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());
}
}