Import and Export Annotations using Java
Contents
[
Hide
]
Copy annotations from one PDF to another
- Open the source PDF and create a new destination document with a target page.
- Enumerate the annotations on the first source page and add each one to the destination page.
- Save the destination document to persist the copied annotations.
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());
}
}