So I'm doing a project that generates a PDF of information that was previously filled out in a form. Along with this information, documents were attached to support the information in the form.
I generate the PDF with the normal info from my DB, but I also want to convert their uploaded files (if .doc or .docx) to PDF format and stick in the same PDF. (So it is all in one place.)
I know how to convert to PDF, problem is how do you att开发者_如何学Goach those newly generated PDFs to the current one with the other information on it?
you have 2 options:
merge all PDFs into one using
<cfpdf action="merge"...>
really attach files in your main pdf but as CFPDF does not support it (yet?) you have to use iText:
<cfscript> try { // Source of THE main PDF and destination file inputFile = ExpandPath("myDoc.pdf"); outputFile = ExpandPath("myDocPlusAttachments.pdf"); // the file to attach (can be of any type) attach1 = ExpandPath("myAttachment.doc"); // prepare everything reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( inputFile ); outStream = createObject("java", "java.io.FileOutputStream").init( outputFile ); stamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init( reader, outStream ); // attachment the file stamper.addFileAttachment("My Attached File", javacast("null", ""), attach1, "myAttachment.doc"); // display the attachment pane when the pdf opens (Since 1.6) writer = stamper.getWriter(); writer.setPdfVersion( writer.VERSION_1_6 ); } finally { // always cleanup objects if (IsDefined("stamper")) { stamper.close(); } if (IsDefined("outStream")) { outStream.close(); } } </cfscript>
Just found where I got that piece of code: ColdFusion 9: Adding Document Level Attachments to a PDF with iText
You need to use the CFPDF tag, and use the merge
action.
精彩评论