List of usage examples for com.lowagie.text.pdf PdfStamper addFileAttachment
public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException
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(); }