Import and Export Annotations using Java
Contents
[
Hide
]
Copy annotations from one PDF to another
- Open the source PDF Document.
- Add a Page to the destination Document.
- Add each Annotation to the target Page.
- Read or iterate through the Annotation items on the target page.
- Save the updated PDF Document.
- Enumerate the Annotation items on the first source page and add each one to the destination page.
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());
}
}