Example usage for com.lowagie.text.pdf PdfStamper addFileAttachment

List of usage examples for com.lowagie.text.pdf PdfStamper addFileAttachment

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfStamper addFileAttachment.

Prototype

public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException 

Source Link

Document

Adds a file attachment at the document level.

Usage

From source file:dev.ztgnrw.htmlconverter.HtmlConverter.java

/**
 * Method for attachment. Adds a File to a PDF as attachment
 * /*from ww  w  .  j a  v  a2  s. c o m*/
 * @param reader
 * @param output
 * @param attachment_uri
 * @throws IOException
 * @throws DocumentException 
 */
private static void addFile(PdfReader reader, String output, String attachment_uri)
        throws IOException, DocumentException {

    File attachment = new File(attachment_uri);

    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(output + ".pdf"));
    // PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(
    //        stamper.getWriter(), null, "test.txt", "Some test".getBytes());

    PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(stamper.getWriter(), null, attachment.getName(),
            Files.readAllBytes(attachment.toPath()));

    stamper.addFileAttachment("Attachment File", fs);
    stamper.close();
}