I am trying to combine 1000 pdf files through iText. I am not sure where the memory leak occurs. The following is sample code. Please note that I delete the child-pdf file as soon as I merge with the parent file. Please indicate the error in the code below or is there a better way to do this without the concept of memory. This process runs through a servlet (not a standalone program)
FileInputStream local_fis = null; BufferedInputStream local_bis = null; File localFileObj = null; for(int taIdx=0;taIdx<totalSize;taIdx++){ frObj = (Form3AReportObject)reportRows.get(taIdx); localfilename = companyId + "_" + frObj.empNumber + ".pdf"; local_fis = new FileInputStream(localfilename); local_bis = new BufferedInputStream(local_fis); pdfReader = new PdfReader(local_bis); cb = pdfWriter.getDirectContent(); document.newPage(); page = pdfWriter.getImportedPage(pdfReader, 1); cb.addTemplate(page, 0, 0); local_bis.close(); local_fis.close(); localFileObj = new File(localfilename); localFileObj.delete(); } document.close();
Niger source share