I'm SURE that this has been addressed many times over so my apologies if I have 
missed it.  I am trying to append several PDF files together using the 
addDocument() method.  My code is below.  What results when I run this is that 
I get the correct NUMBER of documents but only the first document several times 
(if I sent an array of 3 filenames I get a final output file with three copies 
of the first file in the array).  What am I missing?

 

      public static void concatPDFs(String[] pdfFileNames, String 
outputfilename) {

            try {

                  ByteArrayOutputStream baos = new ByteArrayOutputStream();

                  PdfCopyFields copy = new PdfCopyFields(baos);

                  for (int i = 0; i < pdfFileNames.length; i++) {

                        copy.addDocument(new PdfReader(pdfFileNames[i]));

                  }

                  copy.close();

                  PdfReader reader = new PdfReader(baos.toByteArray());

                  PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream(outputfilename));

                  stamper.close();

            } catch (Exception e) {

                  e.printStackTrace();

            } finally {

            }

      }

 

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to