Annotations

คู่มือนี้แสดงวิธีการเพิ่ม, ปรับแต่งและลบคําบรรยาย PDF โดยใช้ Annotation การจัดเรียงชั้นใน Aspose.PDF FOSS สําหรับ Java คุณจะเรียนรู้การ สร้างวิดจ์ต, ภาพลักษณ์ข้อความอิสระ, การเร่งฉากและการประทับวงกลม และเพื่อทําให้เรียบหรือ ลบมันโดยใช้ PdfAnnotationEditor.

การระดับความหมาย

การสรุป Annotation class เป็นฐานสําหรับคําอธิบายทั้งหมดของ PDF. คําอาการทั้งหมด ตั้งอยู่บน a Page ใน a Rectangle และเพิ่มผ่านทาง page.getAnnotations().add(annotation).

WidgetAnnotation

WidgetAnnotation เป็นตัวแทนของวิดจ์ต์แบบฟอร์ม การปรากฏตัวถูกควบคุมผ่าน AppearanceCharacteristics,ซึ่งเปิดเผยว่า setBorder(), setBackground(), setRotate(),และ setCaption().

try (Document doc = new Document()) {
    PageCollection pages = doc.getPages();
    Page page = pages.add();
    WidgetAnnotation w = new WidgetAnnotation(page, new Rectangle(0, 0, 100, 50));
    w.getCharacteristics().setBorder(Color.fromRgb(1, 0, 0));
    w.getCharacteristics().setCaption("Submit");
    page.getAnnotations().add(w);
    doc.save("annotated.pdf");
}

FreeTextAnnotation

FreeTextAnnotation แสดงการเรียกข้อความที่สถานที่ที่ถูกกําหนด มันยอมรับ a DefaultAppearance เพื่อกําหนดตัวอักษร ขนาด และสีของข้อความคําบรรยาย.

DefaultAppearance da = new DefaultAppearance("Helv", 12, Color.BLACK);
FreeTextAnnotation fta = new FreeTextAnnotation(page,
    new Rectangle(50, 50, 200, 100), da);
fta.setContents("Review comment here");
page.getAnnotations().add(fta);

setCallout(double[][]) ตั้งเส้น 3 จุดสําหรับการอธิบายคํานวณ. getIntent() กลับคําอธิบายของ FreeTextIntent ค่าค่านิยม.

การแสดงตราการเขียน

HighlightAnnotation และ UnderlineAnnotation การตราข้อความที่ใช้จุดสี่เหลี่ยม. การ getQuadPoints() วิธีการคืน array 8 องค์ประกอบที่กําหนด 4 มุม ของภูมิภาคที่ถูกกําหนดไว้.

try (Document doc = new Document("input.pdf")) {
    PageCollection pages = doc.getPages();
    Page page = pages.get(1);
    HighlightAnnotation h = new HighlightAnnotation(page,
        new Rectangle(100, 200, 300, 220));
    page.getAnnotations().add(h);
    doc.save("highlighted.pdf");
}

การประกอบวงจรและการประชุมความสนใจ

CircleAnnotation ออกลักษณะของตัวอัลลิปซ์ที่ขั้นตั้งที่ถูกให้; CaretAnnotation สัญลักษณ์ จุดการใส่ในข้อความ ทั้งสองขยาย Annotation และมีสีเดียวกันและ อสังหาริมทรัพย์ที่อยู่ชายแดน.

try (Document doc = new Document()) {
    PageCollection pages = doc.getPages();
    Page page = pages.add();
    CircleAnnotation circle = new CircleAnnotation(page, new Rectangle(100, 100, 200, 200));
    circle.setColor(Color.fromRgb(0, 0, 1));
    page.getAnnotations().add(circle);
    doc.save("circle.pdf");
}

การ แทบ ความหมาย

การใช้งาน PdfAnnotationEditor.flattenAnnotations() เพื่อรวมความหมายทั้งหมดเข้ากับ การถ่ายทอดเนื้อหาหน้า ทําให้มันไม่สามารถแก้ไขได้.

try (PdfAnnotationEditor editor = new PdfAnnotationEditor()) {
    editor.bindPdf("annotated.pdf");
    editor.flattenAnnotations();
    editor.save("flat.pdf");
}

การลบคําอธิบายตามชนิด

Call deleteAnnotations(type) ด้วยชื่อประเภทคําบรรยายเพื่อลบข้อบรรณาทั้งหมด ของชนิดนั้นจากทุกหน้าในเอกสารที่ผูกพัน:

try (PdfAnnotationEditor editor = new PdfAnnotationEditor()) {
    editor.bindPdf("input.pdf");
    editor.deleteAnnotations("Highlight");
    editor.save("output.pdf");
}

See Also

 ภาษาไทย