I am trying to concatenate 50 pdf’s in a folder.Below is the code I am used to concatenate.The below programs throws out of memory error.Total PDF size in that folder is around 75 Mb only.Please help to resolve this and Please also let me know upto which file size the PDF concatenation will work fine?
public static void concatPDF(String destination,List convertedFileNames,Map<String,Integer> pdfInfo) throws Exception{
Integer pdfcount=new Integer(0);
PdfFileInfo pdffileinfo=null;
InputStream[] pdfStream=new InputStream[convertedFileNames.size()];
//List pdfStream=new ArrayList();
for(int i=0;i<convertedFileNames.size();i++){
pdfStream[i]=new FileInputStream(destination+convertedFileNames.get(i));
//pdfStream.add(new FileInputStream(destination+convertedFileNames.get(i)));
pdffileinfo=new PdfFileInfo(destination+convertedFileNames.get(i));
pdfInfo.put(convertedFileNames.get(i),pdfcount+1);
pdfcount=pdfcount+pdffileinfo.getNumberofPages();
System.out.println("— PDF Count —"+pdfcount);
}
String outFile=destination+ApplicationConstants.SINGLE_PDF+AppHelper.getFormattedTimeStamp()+ApplicationConstants.pdf;
try {
FileOutputStream outFos=new FileOutputStream(outFile);
PdfFileEditor editor = new PdfFileEditor();
editor.concatenate(pdfStream, outFos);
outFos.close();
//concatPDFs(pdfStream,outFos,true,pdfInfo,convertedFileNames);
bookMarkPDF(pdfInfo,outFile);
}
catch(Exception E){
E.printStackTrace();
}
}