Hi everyone,

I am using iText Java API to merge around 1500 PDF files into one large one. However, it looks to me that iText keeps everything in memory until close() on the document is called which is causing my application to run out of memory. Here is how I merge the PDF files:
- doc = new Document()
- largePDF = PDFCopy(doc,output.pdf)
- for each of 1500 PDFs:
-----reader = new Pdfreader(filepath)
-----for each page in that PDF:
-------------largePDF.addPage(page)
-doc.close()

 

I read some posts on the list and found that people have had same memory problem with this code too:

               PdfCopyFields copy = new PdfCopyFields(new FileOutputStream(output));
               PdfReader reader = null;
         for (int i = 0; i < pages.size(); i++) {
   &n
 bsp;
           reader = new PdfReader(filePath + pages.get(i));
               copy.addDocument(reader);
         }
               copy.close();

 


is there another way to merge all these PDFs without keeping the whole largePDF object in memory?! I don’t have the option to increase JVM heap size, I really need to do this with ~200M of memory (each PDF is 100k and I have 1500 of them).

Thank you.
Ali-

 

Reply via email to