Example usage for com.lowagie.text.pdf PdfFileSpecification fileEmbedded

List of usage examples for com.lowagie.text.pdf PdfFileSpecification fileEmbedded

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfFileSpecification fileEmbedded.

Prototype

public static PdfFileSpecification fileEmbedded(PdfWriter writer, String filePath, String fileDisplay,
        byte fileStore[], boolean compress) throws IOException 

Source Link

Document

Creates a file specification with the file embedded.

Usage

From source file:questions.compression.CompressionLevelsEmbeddedFiles.java

public static void createPdf(int compressionLevel) {
    try {//from   w ww.ja  v a2s .co 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());
    }
}