Example usage for com.lowagie.text.pdf PdfWriter addAnnotation

List of usage examples for com.lowagie.text.pdf PdfWriter addAnnotation

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter addAnnotation.

Prototype

public void addAnnotation(PdfAnnotation annot) 

Source Link

Usage

From source file:questions.stamppages.RemoveAttachmentAnnotations.java

public static void createPdfWithAttachments() throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESOURCE));
    document.open();/*w ww. j  a  va 2s .c o m*/
    document.add(new Paragraph("page 1"));
    writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f),
            "This is some text", "some text".getBytes(), null, "some.txt"));
    writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(100f, 750f, 120f, 770f), "Help",
            "This Help annotation was made with 'createText'", false, "Help"));
    document.newPage();
    document.add(new Paragraph("page 2"));
    document.newPage();
    document.add(new Paragraph("page 3"));
    PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, TXT, "caesar.txt", null);
    writer.addAnnotation(
            PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "Caesar", fs1));
    PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, IMG, "1t3xt.gif", null);
    writer.addAnnotation(
            PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f), "1t3xt", fs2));
    document.close();
}