استيراد وتصدير التعليقات التوضيحية باستخدام Java

نسخ التعليقات التوضيحية من PDF إلى آخر

  1. افتح ملف PDF المصدر Document.
  2. أضف Page إلى الوجهة Document.
  3. أضف كل Annotation إلى الهدف Page.
  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());
    }
}