כיצד לעבוד עם Annotations ב- Java

כיצד לעבוד עם Annotations ב- Java

מדריך זה מראה כיצד ליצור, לספור, להסיר ולשפוך את ההערות PDF באמצעות Aspose.PDF FOSS for Java. You will learn to add widget, free-text, and highlight תגיות ושימוש PdfAnnotationEditor על פעולות המוניות.

הוסף וידג’ט Annotation

WidgetAnnotation מייצג וידג’ט בקרת צורה.הגדיר את הצבע הגבול ואת הסימן דרך AppearanceCharacteristics.לאחר הגדרת ההרשמה, הוסף אותה לדף הצגת ההודעה והשמירה על המסמך:

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

הוסף הודעה טקסט חינם

א FreeTextAnnotation מציג הערה טקסט במקום מסוים בדף. המראה הנדרש מגדיר את האותיות, גודל וצבע הטקסט של ההערה:

try (Document doc = new Document()) {
    PageCollection pages = doc.getPages();
    Page page = pages.add();
    DefaultAppearance da = new DefaultAppearance("Helv", 12, Color.BLACK);
    FreeTextAnnotation fta = new FreeTextAnnotation(page,
        new Rectangle(100, 300, 350, 350), da);
    fta.setContents("Review this section carefully.");
    page.getAnnotations().add(fta);
    doc.save("freetext.pdf");
}

הוסף הערה מפורטת

HighlightAnnotation מסמן באופן חזותי אזור טקסט בדף.מיקום זה משתמש א Rectangle זה מכסה את הטקסט כדי להדגיש, ולאחר מכן להוסיף אותו לתוך ההערה אוסף :

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, 400, 220));
    page.getAnnotations().add(h);
    doc.save("highlighted.pdf");
}

סופר פרסומות בדף אחד

גישה ישירה לאוסף ההערות של הדף כדי לספור או לנתק את ההודעות:

try (Document doc = new Document("input.pdf")) {
    PageCollection pages = doc.getPages();
    Page page = pages.get(1);
    int count = page.getAnnotations().size();
    System.out.println("Annotations on page 1: " + count);
}

להסיר הודעות לפי סוג

שימוש PdfAnnotationEditor להסיר את כל ההערות של סוג מסוים מתוך מסמך. שיחת טלפון deleteAnnotations(type) עם שם סוג ההרשמה, אז לשמור:

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

תגיות Annotic

תוויות מתגלגלות משלבות אותם באופן קבוע לתוכן הדף, כך שהם כבר אינם ניתן לערוך או להסיר כנושאים נפרדים:

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

ראה גם

 עברית