Example usage for com.lowagie.text.pdf PdfAnnotation createFileAttachment

List of usage examples for com.lowagie.text.pdf PdfAnnotation createFileAttachment

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAnnotation createFileAttachment.

Prototype

public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents,
        PdfFileSpecification fs) throws IOException 

Source Link

Document

Creates a file attachment annotation

Usage

From source file:questions.compression.CompressionLevelsEmbeddedFiles.java

public static void createPdf(int compressionLevel) {
    try {//  ww w  . j a v a2s .  c o m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1]));
        document.open();
        document.add(new Paragraph("Hello World"));
        PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, null, "some.txt",
                "some text".getBytes(), compressionLevel);
        writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f),
                "This is some text", fs1));
        PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, RESOURCE, "caesar.txt", null,
                compressionLevel);
        writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f),
                "Caesar", fs2));
        document.close();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
}