Ah!
 
While you could save the PDF to a file rather than a BAOS, the big
savings will be in calling copy.freeReader(reader) when you're done with
each reader in turn:
 
for (int x = 0; x < PdfReaderArray.length; x++) {
    reader = PdfReaderArray[x];
 
    for (int page = 0; page < reader.getNumberOfPages(); ) {
      copy.addPage(copy.getImportedPage(reader, ++page);
    }
    copy.freeReader(reader);
 
}
 
Otherwise you're keeping everything from each reader in memory until you
"copy.close()".
 
--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 


________________________________

        From: McGee, Ed F, CTR, OSD-CAPE
[mailto:edwin.mcgee....@osd.mil] 
        Sent: Tuesday, November 09, 2010 2:55 PM
        To: 'itext-questions@lists.sourceforge.net'
        Subject: [iText-questions] Out Of Memory Error Concatenating
Multiple PDFFiles
        
        
        
        Is there a size limitation to a PdfCopy object and/or
PdfSmartCopy object?  I have tried both, as suggested in iText in
Action, second edition, but get the same error.
         
        I am concatenating multiple PDF files and I am now encountering
an Out-Of-Memory error as I import pages using code similar to the
following:
         
        I have an input of PdfReader[] which contains 16 PdfReader
objects with approximately 457 pages when combined.
         
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfCopy copy = new PdfCopy(document, baos);
        document.open();
         
        PdfReader reader = null;
         
        for (int x = 0; x < PdfReaderArray.length; x++) {
            reader = PdfReaderArray[x];
         
            for (int page = 0; page < reader.getNumberOfPages(); ) {
              copy.addPage(copy.getImportedPage(reader, ++page);
            }
         
        }
         
        Any assistance is appreciated.
         
         

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to