Java를 사용하여 주석 가져오기 및 내보내기

한 PDF에서 다른 PDF로 주석 복사

  1. 원본 PDF Document를 여세요.
  2. 대상 Document에 Page를 추가하세요.
  3. 대상 Page에 각 Annotation을 추가하세요.
  4. 대상 페이지의 Annotation 항목을 읽거나 반복하세요.
  5. 업데이트된 PDF Document를 저장하세요.
  6. 첫 번째 원본 페이지에 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());
    }
}