List of usage examples for com.itextpdf.text.pdf PdfStamper addFileAttachment
public void addFileAttachment(final String description, final byte fileStore[], final String file, final String fileDisplay) throws IOException
From source file:cz.hobrasoft.pdfmu.operation.OperationAttach.java
License:Open Source License
private static void execute(PdfStamper stp, String description, String file, String fileDisplay) throws OperationException { {//w ww.j a v a2 s . c o m assert stp != null; assert file != null; assert fileDisplay != null; // We use the attachment file name by default logger.info(String.format("Attached file: %s", file)); logger.info(String.format("Description: %s", (description != null ? description : "<none>"))); logger.info(String.format("Display name: %s", fileDisplay)); { Matcher m = filenameWithExtension.matcher(fileDisplay); if (!m.matches()) { logger.warning( "Display name does not contain a file extension. Adobe Reader XI does not allow opening or saving such attachment."); } } } try { stp.addFileAttachment(description, null, file, fileDisplay); } catch (IOException ex) { throw new OperationException(ATTACH_FAIL, ex, PdfmuUtils.sortedMap(new String[] { "file" }, new Object[] { file })); } logger.info(String.format("The file \"%s\" has been attached.", file)); }
From source file:gov.nih.nci.firebird.service.pdf.PdfServiceBean.java
License:Open Source License
@Override public void attachFileToPdf(InputStream srcPdf, OutputStream destPdf, final InputStream attachment, final String attachmentFileName) throws IOException { PdfProcessor processor = new PdfProcessor(srcPdf, destPdf) { @Override// w ww. jav a 2s .c o m void handleProcessing(PdfReader reader, PdfStamper stamper) throws IOException, DocumentException { stamper.addFileAttachment(attachmentFileName, IOUtils.toByteArray(attachment), attachmentFileName, attachmentFileName); } }; processor.process(); }