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

إضافة تعليق توضيحي نصي

  1. افتح ملف PDF الإدخال وحدد الصفحة التي يجب وضع التعليق النصي عليها.
  2. أنشئ TextAnnotation، حدد مستطيله، واضبط عنوانه، وموضوعه، وعلاماته، ولونه.
  3. أضف التعليق إلى الصفحة واحفظ المستند المحدث.
public static void textAnnotationAdd(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        TextAnnotation textAnnotation = new TextAnnotation(
                document.getPages().get_Item(1), new Rectangle(299.988, 613.664, 428.708, 680.769, true));
        textAnnotation.setTitle("Aspose User");
        textAnnotation.setSubject("Inserted text 1");
        textAnnotation.setFlags(AnnotationFlags.Print);
        textAnnotation.setColor(Color.getBlue());

        document.getPages().get_Item(1).getAnnotations().add(textAnnotation, false);
        document.save(outputFile.toString());
    }
}

إضافة ملاحظة نصية حرة

  1. حمِّل ملف PDF المصدر وحدد الصفحة المستهدفة والمستطيل للملاحظة النصية الحرة.
  2. أنشئ FreeTextAnnotation، تهيئة المظهر الافتراضي وضبط العنوان واللون.
  3. أضف التعليق إلى الصفحة واحفظ النتيجة.
public static void freeTextAnnotationAdd(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(
                document.getPages().get_Item(1),
                new Rectangle(299, 713, 308, 720, true),
                new DefaultAppearance());
        freeTextAnnotation.setTitle("Aspose User");
        freeTextAnnotation.setColor(Color.getLightGreen());

        document.getPages().get_Item(1).getAnnotations().add(freeTextAnnotation);
        document.save(outputFile.toString());
    }
}