I have a situation where I need to generate a PDF (purchase order
document), but also attach another PDF document to the end of it. I can't generate this document via PDF, I just want to append it so that when you get the order, you get this page as well. Can FO-FTL handle this? -- James McGill Phoenix AZ |
Hi James,
It's unlikely because PDF is just an output format for FOP. You'd probably need to find a separate library that can modify the pdf once FOP is done with it. Try Apache PDFBox (http://pdfbox.apache.org/) the main page mentions a feature to merge PDF docs. Regards Scott HotWax Media http://www.hotwaxmedia.com On 9/12/2010, at 10:40 AM, James McGill wrote: > I have a situation where I need to generate a PDF (purchase order > document), but also attach another PDF document to the end of it. I > can't generate this document via PDF, I just want to append it so that > when you get the order, you get this page as well. > > Can FO-FTL handle this? > > -- > James McGill > Phoenix AZ smime.p7s (3K) Download Attachment |
In reply to this post by James McGill-5
James McGill schrieb:
> I have a situation where I need to generate a PDF (purchase order > document), but also attach another PDF document to the end of it. I > can't generate this document via PDF, I just want to append it so that > when you get the order, you get this page as well. > > Can FO-FTL handle this? This sounds like a job for the PDF Image Support Plug-In from Jeremias Märki (see http://www.jeremias-maerki.ch/development/fop/index.html) or you could try to convert the PDF into SVG and then include this with fo:external-graphic. Christian |
In reply to this post by Scott Gray-2
Yes, there are a few libraries that can combine PDFs (iText is another one), and there is another option too: combine the XSL:FO files before the FOP rendering to a single PDF file. To do that you'll have to create your own decorator that allows for multiple page sequences, and so on. I had the pleasure of doing this to get sales order and invoice into a single document and it worked fine, and is only a bit of a pain... ;) -David On Dec 8, 2010, at 10:44 PM, Scott Gray wrote: > Hi James, > > It's unlikely because PDF is just an output format for FOP. You'd probably need to find a separate library that can modify the pdf once FOP is done with it. > > Try Apache PDFBox (http://pdfbox.apache.org/) the main page mentions a feature to merge PDF docs. > > Regards > Scott > > HotWax Media > http://www.hotwaxmedia.com > > On 9/12/2010, at 10:40 AM, James McGill wrote: > >> I have a situation where I need to generate a PDF (purchase order >> document), but also attach another PDF document to the end of it. I >> can't generate this document via PDF, I just want to append it so that >> when you get the order, you get this page as well. >> >> Can FO-FTL handle this? >> >> -- >> James McGill >> Phoenix AZ > |
Hi James,
One Solution is that you can modify your PDF once FOP is done with it. First you need to convert the PDF's in Byte Array. Then this Utility Class to Merge Multiple PDF's will help you. Its takes the list of Byte Array & returns a Byte Array after Merging in a sequence passed by you. import java.io.ByteArrayOutputStream; import java.util.Iterator; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.lowagie.text.Document; import com.lowagie.text.pdf.PdfCopy; import com.lowagie.text.pdf.PdfImportedPage; import com.lowagie.text.pdf.PdfReader; @SuppressWarnings("unchecked") public class MergePDFs { private static Logger logger = LoggerFactory.getLogger(MergePDFs.class); private ByteArrayOutputStream outStream = new ByteArrayOutputStream(); private Document document = null; private PdfCopy writer = null; public byte[] mergePdfs(List pdfList) { byte[] array = null; try { if(logger.isDebugEnabled()) logger.debug("Inside mergePdfs method. Number of documents to merge : " + pdfList.size()); Iterator iteratorPDFs = pdfList.iterator(); while(iteratorPDFs.hasNext()){ byte[] byteArray = (byte[]) iteratorPDFs.next(); addToPDF(byteArray); } closeDocs(); array = getMergedPdfByteArray(); if(null != array) { if(logger.isDebugEnabled()) logger.debug("Got merged pdf. Length is " + array.length + " bytes."); } else { if(logger.isDebugEnabled()) logger.debug("Merge byte array is: " + array); } } catch (Exception e) { if(logger.isDebugEnabled()) logger.error("Exception occured while merging pdfs. Exception :" + e.toString()); } return array; } public byte[] getMergedPdfByteArray() { if (outStream != null) { if(logger.isDebugEnabled()) logger.debug("Inside getMergedPdfByteArray."); return this.getOutStream().toByteArray(); } else { return null; } } public void addToPDF(byte[] pdfByteArray) { try { PdfReader reader = new PdfReader(pdfByteArray); int numberOfPages = reader.getNumberOfPages(); if (document == null) { document = new Document(reader.getPageSizeWithRotation(1)); writer = new PdfCopy(document, outStream); document.open(); } PdfImportedPage page; for (int i = 0; i < numberOfPages;) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); } } catch (Exception e) { if(logger.isDebugEnabled()) logger.error("Exception occured while adding byte array to PDF. Exception :" + e.toString()); } } public void closeDocs() { try { if(logger.isDebugEnabled()) logger.debug("Close document & outStream"); document.close(); outStream.close(); } catch (Exception e) { if(logger.isDebugEnabled()) logger.error("Exception occured while closeDocs method. Exception :" + e.toString()); } } public ByteArrayOutputStream getOutStream() { return outStream; } } Another option as David has suggested, combine the XSL:FO files before the FOP rendering to a single PDF file. You can try if you have knowledge of XSL:FO. Hope this will help you. -- Thanks & Regards, Pankaj Savita Mob: +91 9890262476 Mail to: [hidden email] On Thu, Dec 9, 2010 at 2:36 PM, David E Jones <[hidden email]> wrote: > > Yes, there are a few libraries that can combine PDFs (iText is another > one), and there is another option too: combine the XSL:FO files before the > FOP rendering to a single PDF file. To do that you'll have to create your > own decorator that allows for multiple page sequences, and so on. I had the > pleasure of doing this to get sales order and invoice into a single document > and it worked fine, and is only a bit of a pain... ;) > > -David > > > On Dec 8, 2010, at 10:44 PM, Scott Gray wrote: > > > Hi James, > > > > It's unlikely because PDF is just an output format for FOP. You'd > probably need to find a separate library that can modify the pdf once FOP is > done with it. > > > > Try Apache PDFBox (http://pdfbox.apache.org/) the main page mentions a > feature to merge PDF docs. > > > > Regards > > Scott > > > > HotWax Media > > http://www.hotwaxmedia.com > > > > On 9/12/2010, at 10:40 AM, James McGill wrote: > > > >> I have a situation where I need to generate a PDF (purchase order > >> document), but also attach another PDF document to the end of it. I > >> can't generate this document via PDF, I just want to append it so that > >> when you get the order, you get this page as well. > >> > >> Can FO-FTL handle this? > >> > >> -- > >> James McGill > >> Phoenix AZ > > > > |
Free forum by Nabble | Edit this page |