Getting java.lang.OutOfMemery Exception while used Pdf

Hi,

We have been using Aspose PDF to generate online reports through our web application. However, lately we are getting OutofMemory exception and as per IBM the culprit is Aspose PDF object.

Any help to optimize the code would be helpful

Here is the code snippet.

private Pdf getPdfFinnoneExportReport(FinnoneExportReportOut fout) {

Row header = null; 
Row row2 = null;
Row row22 = null;
Table table1 = null;
Table maintable=null;
Table casedesctable = null;
Pdf pdf1 =null;
Section sec1 =null; 

try
{			
	//Create PDF document
	pdf1 = new Pdf();
	pdf1.setIsLandscape(true);
	sec1 = pdf1.getSections().add();
	//Section and Table Margin 
	MarginInfo marginInfo = new MarginInfo();
	marginInfo.setTop(2);
	marginInfo.setBottom(0);
	marginInfo.setLeft(5);
	marginInfo.setRight(5);
	sec1.getPageInfo().setMargin(marginInfo);
	MarginInfo marginInfo1 = new MarginInfo();
	marginInfo1.setTop(2);
	marginInfo1.setBottom(0);
	marginInfo1.setLeft(0);
	marginInfo1.setRight(0);
	Text text = null;
	Text textBlanks = new Text(sec1, "");
	//===================================================================//
	//			Header Footer to show Page Number and Header Data
	//===================================================================//
	HeaderFooter footer = new HeaderFooter(sec1);
	HeaderFooter headers = new HeaderFooter(sec1);
	sec1.setOddFooter(footer);
	sec1.setEvenFooter(footer);
	sec1.setOddHeader(headers);
	sec1.setEvenHeader(headers);
	
	Text t1 = new Text(footer, "Page: $p of $P #$NL #$NP ");
	t1.getTextInfo().setIsTrueTypeFontBold(true);
	t1.getTextInfo().setFontName("Arial");
	t1.getTextInfo().setFontSize(10);
	t1.getTextInfo().setAlignment(AlignmentType.Center);
	casedesctable = new Table(sec1);
	casedesctable.setDefaultCellPadding(marginInfo);
	footer.getParagraphs().add(casedesctable);
	casedesctable.setColumnWidths("139 556 139");
	casedesctable.setBorder(new BorderInfo(BorderSide.Bottom.getValue(), 1F));
	casedesctable.setBorder(new BorderInfo(BorderSide.Top.getValue(), 1F));
	header = casedesctable.getRows().add();
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().add().getParagraphs().add(t1);
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().getCell(0).setAlignment(AlignmentType.Left);
	header.getCells().getCell(1).setAlignment(AlignmentType.Left);
	header.getCells().getCell(2).setAlignment(AlignmentType.Left);
	casedesctable.setBorder(new BorderInfo(BorderSide.Bottom.getValue(), 1F));
	casedesctable.setBorder(new BorderInfo(BorderSide.Top.getValue(), 1F));
	Text headerTest1 = new Text(headers, "XXX Application\n");
	headerTest1.getTextInfo().setIsTrueTypeFontBold(true);
	headerTest1.getTextInfo().setFontName("Arial");
	headerTest1.getTextInfo().setFontSize(14);
	// date on which report is generated --- right aligned
	DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
	Date date1 = new Date();
	String currDate1 = dateFormat1.format(date1);
	Text headerDate = new Text(headers, currDate1+"\n");
	headerDate.getTextInfo().setIsTrueTypeFontBold(false);
	headerDate.getTextInfo().setFontName("Arial");
	headerDate.getTextInfo().setFontSize(10);
	headerDate.getTextInfo().setAlignment(AlignmentType.Right);			
	//add table and add CUR Application header and date in a single row in header
	table1 = new Table(sec1);
	headers.getParagraphs().add(table1);
	table1.setDefaultCellPadding(marginInfo1);
	table1.setColumnWidths("140 80 200 200 70 140");
	table1.setDefaultCellBorder(new BorderInfo(BorderSide.All.getValue(), 0F));
	table1.setBorder(new BorderInfo(BorderSide.All.getValue(), 0F));
	
	header = table1.getRows().add();
	header.getCells().add().getParagraphs().add(headerTest1);
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().add().getParagraphs().add(textBlanks);
	header.getCells().add().getParagraphs().add(headerDate);
	header.getCells().getCell(0).setAlignment(AlignmentType.Right);
	header.getCells().getCell(1).setAlignment(AlignmentType.Left);
	header.getCells().getCell(2).setAlignment(AlignmentType.Left);
	header.getCells().getCell(3).setAlignment(AlignmentType.Left);
	header.getCells().getCell(4).setAlignment(AlignmentType.Left);
	header.getCells().getCell(5).setAlignment(AlignmentType.Right);
	
	headerTest1 = new Text(headers, "\nPending Case Details\n\n");
	headerTest1.getTextInfo().setIsTrueTypeFontBold(true);
	headerTest1.getTextInfo().setFontName("Arial");
	headerTest1.getTextInfo().setFontSize(14);
	table1 = new Table(sec1);
	headers.getParagraphs().add(table1);
	table1.setDefaultCellPadding(marginInfo1);
	table1.setColumnWidths("140 80 400 70 140");
	row2 = table1.getRows().add();	
	row2.getCells().add().getParagraphs().add(textBlanks);
	row2.getCells().add().getParagraphs().add(textBlanks);
	row2.getCells().add().getParagraphs().add(headerTest1);
	row2.getCells().add().getParagraphs().add(textBlanks);
	row2.getCells().add().getParagraphs().add(textBlanks);
	row2.getCells().getCell(0).setAlignment(AlignmentType.Left);
	row2.getCells().getCell(1).setAlignment(AlignmentType.Left);
	row2.getCells().getCell(2).setAlignment(AlignmentType.Center);
	row2.getCells().getCell(3).setAlignment(AlignmentType.Left);
	row2.getCells().getCell(4).setAlignment(AlignmentType.Left);
	table1.setBorder(new BorderInfo(BorderSide.Bottom.getValue(), 1F));
	table1.setBorder(new BorderInfo(BorderSide.Top.getValue(), 1F));
	//adding case data in report
	maintable = new Table(sec1);
	maintable.setTop(100F);
	maintable.setDefaultCellPadding(marginInfo);
	sec1.getParagraphs().add(maintable);
	maintable.setColumnWidths("93.55 93.55 93.55 93.55 93.55 93.55 93.55 93.55 93.55");
	String str = new String(fout.filecontent, "UTF-8");
	List<String> dataList = Arrays.asList(str.split(lineSep));
	int headValue=0;
	String headDesc = null;
	for(String s:dataList)
	{
			List<String> dataList1 = Arrays.asList(s.split(","));
			row2 = maintable.getRows().add();
			int i=0;
				if(headValue==0)
				{
					headDesc=s;
					for (String s1:dataList1)
					{
						text = new Text(sec1,"\n\n\n\n\n");	
						row2.getCells().add().getParagraphs().add(text);
						text.getTextInfo().setIsTrueTypeFontBold(true);
						text.getTextInfo().setFontName("Arial");
						text.getTextInfo().setFontSize(9);
						row2.getCells().getCell(i++).setAlignment(AlignmentType.Left);
					}
					headValue++;
				}
				else
				{
					for (String s1:dataList1)
					{
						text = new Text(sec1, s1+"\n");	
						row2.getCells().add().getParagraphs().add(text);
						text.getTextInfo().setIsTrueTypeFontBold(false);
						text.getTextInfo().setFontName("Arial");
						text.getTextInfo().setFontSize(9);
						row2.getCells().getCell(i++).setAlignment(AlignmentType.Center);
					}
				}
		}
			
	//adding End of Report at the end 
	casedesctable = new Table(sec1);
	casedesctable.setDefaultCellPadding(marginInfo);
	sec1.getParagraphs().add(casedesctable);
	casedesctable.setColumnWidths("421 421");
	casedesctable.setBorder(new BorderInfo(BorderSide.Bottom.getValue(), 1F));
	casedesctable.setBorder(new BorderInfo(BorderSide.Top.getValue(), 1F));
	Text textBlank = new Text(sec1, "\n");
	header = casedesctable.getRows().add();
	header.getCells().add().getParagraphs().add(textBlank);
	header.getCells().add().getParagraphs().add(textBlank);
	header.getCells().getCell(0).setAlignment(AlignmentType.Left);
	header.getCells().getCell(1).setAlignment(AlignmentType.Left);					
	text = new Text(sec1, "\n\nEnd Of Report\n\n");
	text.getTextInfo().setIsTrueTypeFontBold(true);
	text.getTextInfo().setFontName("Arial");
	text.getTextInfo().setFontSize(10);
	text.getTextInfo().setAlignment(AlignmentType.Center);
	sec1.getParagraphs().add(text);
				
	//adding headers of maintable in  pdf header 			
	List<String> dataList2 = Arrays.asList(headDesc.split(","));
	int j=0;
	Table maintables = new Table(sec1);
	maintables.setDefaultCellPadding(marginInfo);
	headers.getParagraphs().add(maintables);
	maintables.setColumnWidths("93.55 93.55 93.55 93.55 93.55 93.55 93.55 93.55 93.55");
	maintables.setBorder(new BorderInfo(BorderSide.Bottom.getValue(), 1F));
	maintables.setBorder(new BorderInfo(BorderSide.Top.getValue(), 1F));
	row22 = maintables.getRows().add();
	for (String s1:dataList2)
		{
			text = new Text(headers, s1+"\n");
			row22.getCells().add().getParagraphs().add(text);
			text.getTextInfo().setIsTrueTypeFontBold(true);
			text.getTextInfo().setFontName("Arial");
			text.getTextInfo().setFontSize(9);
			row22.getCells().getCell(j++).setAlignment(AlignmentType.Center);
		}
		System.out.println("PDF generation completed.");		
}
catch(Exception e)
{
	e.printStackTrace();
}

return pdf1;

}

@shridharkamat11

Thanks for contacting support.

I have checked the code snippet which you have shared and I am afraid that you are using an obsoleted Aspose.Pdf.Generator approach and we are not providing any support or fixes against this approach. However it is strongly recommended to use Aspose.Pdf DOM (Document Object Model) approach with latest version of the API.

By looking at your code, it seems that you are generating a PDF by adding Text, Table and Header/Footer inside it. In order to generated similar PDF by Aspose.Pdf DOM, please check following useful articles in our API documentation.

Please download Aspose.Pdf for Java 17.9 and try using DOM approach by following instructions, given over shared documentation links. In case you experience any issue, please share your sample PDF document, so that we can test the scenario in our environment and address it accordingly.

Dear Asad,

As per your suggestion, post upgrading the aspose pdf jar to 17.9 we are still facing same issue. Please find the code snippet and the error logs for your reference and provide resolution for the same.

Code Snippet:

      Document oDoc = new Document(); 
      Page oPage = oDoc.getPages().add(); 
      MarginInfo oMarginInfo = new MarginInfo();
      oMarginInfo.setBottom(2);
      oMarginInfo.setLeft(2);
      oMarginInfo.setTop(2);
      oMarginInfo.setRight(2);
      oPage.setPageSize( 842.4,597.6);
      Paragraphs oPara = oPage.getParagraphs(); 
      
      BorderInfo oBorder = new BorderInfo(); 
      GraphInfo oTop = new GraphInfo(); 
      oBorder.setTop(oTop); 
      GraphInfo oBottom = new GraphInfo();  
      oBorder.setBottom(oBottom); 
      
      GraphInfo oLeft = new GraphInfo(); 
      oBorder.setLeft(oLeft); 
      GraphInfo oRight = new GraphInfo(); 
      oBorder.setRight(oRight); 
      
      Table oTable = new Table(); 
      oTable.setDefaultCellBorder(oBorder); 
      oTable.setRepeatingRowsCount(1); 

      Row oRow = oTable.getRows().add(); 
      oRow.getCells().add("Last Name"); 
      oRow.getCells().add("Age"); 
      oRow.setDefaultCellPadding(oMarginInfo);

      String str = null;
	try {
		str = new String(fout.filecontent, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
      List<String> dataList = Arrays.asList(str.split(lineSep));
		int headValue=0;
		String headDesc = null;
		for(String s:dataList)
		{
				List<String> dataList1 = Arrays.asList(s.split(","));
				oRow.setDefaultCellPadding(oMarginInfo);
				oRow = oTable.getRows().add();
				
				int i=0;
					if(headValue==0)
					{
						headDesc=s;
						for (String s1:dataList1)
						{
							
							oRow.getCells().add(s1+"\n\n");
													
						}
						headValue++;
					}
					else
					{
						for (String s1:dataList1)
						{   if(dataList1.size()> 7)
							break;
							
							oRow.getCells().add(s1+"\n\n");
																	
						}
					}
			}
     
      
      oPara.add(oTable); 
     
	  
      oDoc.freeMemory(); 
	  return oDoc;

Error logs:
Exception in thread ““http-bio-8082”-exec-10” java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.resize(Unknown Source)
at java.util.HashMap.addEntry(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.jar.Manifest.read(Unknown Source)
at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
at sun.security.util.SignatureFileVerifier.process(Unknown Source)
at java.util.jar.JarVerifier.processEntry(Unknown Source)
at java.util.jar.JarVerifier.update(Unknown Source)
at java.util.jar.JarFile.initializeVerifier(Unknown Source)
at java.util.jar.JarFile.getInputStream(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2981)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2753)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1148)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at sis.tm.client.apps.hdfcb.cur.web.openentriesreport.OpenEntriesReport.addform(OpenEntriesReport.java:137)
at sis.tm.client.apps.hdfcb.cur.web.openentriesreport.OpenEntriesReport.onSecurityCheck(OpenEntriesReport.java:105)
at net.sf.click.ClickServlet.processPage(ClickServlet.java:496)
at net.sf.click.ClickServlet.handleRequest(ClickServlet.java:357)
at net.sf.click.ClickServlet.doGet(ClickServlet.java:280)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
Exception in thread ““http-bio-8082”-exec-11” java.lang.OutOfMemoryError: Java heap space
at java.lang.StringCoding$StringDecoder.decode(Unknown Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.String.(Unknown Source)
at java.util.jar.Attributes.read(Unknown Source)
at java.util.jar.Manifest.read(Unknown Source)
at java.util.jar.Manifest.(Unknown Source)
at java.util.jar.JarFile.getManifestFromReference(Unknown Source)
at java.util.jar.JarFile.getManifest(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2980)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2753)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1148)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at sis.tm.client.apps.hdfcb.cur.web.openentriesreport.OpenEntriesReport.addform(OpenEntriesReport.java:137)
at sis.tm.client.apps.hdfcb.cur.web.openentriesreport.OpenEntriesReport.onSecurityCheck(OpenEntriesReport.java:105)
at net.sf.click.ClickServlet.processPage(ClickServlet.java:496)
at net.sf.click.ClickServlet.handleRequest(ClickServlet.java:357)
at net.sf.click.ClickServlet.doGet(ClickServlet.java:280)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)

@suveena.almeida

Thanks for sharing code snippet.

Would you please share the definition of FinnoneExportReportOut fout object with sample input file, so that we can test the scenario in our environment and address it accordingly.

Please find FinnoneExportReportOut defintion

public class FinnoneExportReportOut extends Out{
	
	private static final long serialVersionUID = 1L;//Added by Videet for CUR JDK on 13-08-2015
  //public byte filecontent[];
  //Modified by TARUN for CUR JDK ENH on 20 Aug 2015
  public byte[] filecontent;
  public String filename = null;
  public String caseNo;
  public String message;
  public String pendingRecords;


public FinnoneExportReportOut()
{
  filecontent=new byte[50];
}

public FinnoneExportReportOut(byte[] filecontent)
{
  this.filecontent=filecontent;
}
}

PLease not that any sample files has more than 10000 records for report genration .

@suveena.almeida

Thanks for sharing the requested details.

We are testing the scenario in our environment and will share our findings shortly.

@suveena.almeida

Thanks for your patience.

I have tried to execute your earlier shared code snippet by adding FinnoneExportReportOut class definition into the program but could not manage to run it correctly. As per my understandings, you are reading content of some file and passing that content into your method for PDF generation.

Would you please share the input file, which content you are using to add in PDF and share other missing details to run the scenario correctly? It will really be appreciated if you can share a sample console application along with input file(s). This will really help us in testing the scenario accordingly.

Please find file attached which is value of String object str.
str = new String(fout.filecontent, “UTF-8”);

This is value of str from there we separate comma separated values into datalist used to write into PDF

Value of str:

Collection Account No,Transaction Date,Cheque Number,Value Date,Dr-Cr Code,Txn Amount,Bal Available,Authorisation Code
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
 , , , , , , , 
123456789,2014-03-08 13:30:00.0,,2014-03-08 00:00:00.0,C,4332211,4332211,D1036249
123456789,2014-03-08 13:30:00.0,,2014-03-08 00:00:00.0,C,1122334,1122334,D1036249
123456789,2011-02-13 13:30:00.0,121ABC017,2011-02-13 00:00:00.0,D,1326582,2000,D1036249
123456789,2011-02-13 13:30:00.0,0,2011-02-13 00:00:00.0,C,10000,2000,D1036249
123456789,2013-03-15 13:30:00.0,0,2013-03-15 00:00:00.0,C,45,45,D1036249
123456789,2013-03-15 13:30:00.0,,2013-10-20 00:00:00.0,C,58741,58741,D1036249
123456789,2014-03-08 13:30:00.0,,2014-03-08 00:00:00.0,C,4332211,4332211,D1036249
123456789,2014-03-15 13:30:00.0,740430302A1,2014-03-15 00:00:00.0,C,300,300000,000
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,41050,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,43300,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,20830,3194712,SYSTEM
123456789,2014-07-19 10:07:00.0,,2014-07-19 00:00:00.0,C,12600,3194712,SYSTEM
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,5500,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,1960,3194712,SYSTEM
123456789,2014-07-19 16:07:00.0,CUR141990457,2014-07-19 00:00:00.0,D,1082537,3194712,S11243
123456789,2014-07-19 16:07:00.0,CUR142000038,2014-07-19 00:00:00.0,D,897730,3194712,S11243
123456789,2014-07-19 16:07:00.0,CUR142000064,2014-07-19 00:00:00.0,D,968680,3194712,S11243
123456789,2014-07-19 16:07:00.0,CUR142000095,2014-07-19 00:00:00.0,D,25000,3194712,S11243
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,4652,3194712,SYSTEM
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,22740,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,37419,3194712,SYSTEM
123456789,2014-07-19 15:07:00.0,000000000078,2014-07-19 00:00:00.0,D,56100,3194712,
123456789,2014-07-19 10:07:00.0,,2014-07-19 00:00:00.0,C,1800,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,3053,3194712,SYSTEM
123456789,2014-07-19 14:07:00.0,,2014-07-19 00:00:00.0,C,13935,3194712,SYSTEM
123456789,2014-07-19 14:07:00.0,,2014-07-19 00:00:00.0,C,123252,3194712,N2405
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,22819,3194712,SYSTEM
123456789,2014-07-19 10:07:00.0,,2014-07-19 00:00:00.0,C,2000,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,21430,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,41450,3194712,SYSTEM
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,460888,3194712,S12638
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,25650,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,31974,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,58072,3194712,Z0044
123456789,2014-07-19 13:07:00.0,000000459049,2014-07-21 00:00:00.0,C,22600,3194712,B2157
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,2616,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,12025,3194712,SYSTEM
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,64461,3194712,G0456
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,54160,3194712,D4617
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,11310,3194712,SYSTEM
123456789,2014-07-19 10:07:00.0,000000577066,2014-07-21 00:00:00.0,C,33534,3194712,N2405
123456789,2014-07-19 10:07:00.0,,2014-07-19 00:00:00.0,C,54840,3194712,S12638
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2011-10-11 00:00:00.0,,2011-10-11 00:00:00.0,C,1234,1234,D1036249
123456789,2014-07-21 14:07:00.0,,2014-07-21 00:00:00.0,C,12750,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,473,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,15400,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,74100,3168763,A6177
123456789,2014-07-21 20:07:00.0,,2014-07-21 00:00:00.0,D,50000,8675892,S133269951
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,46510,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,150984,3168763,P7401
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,41000,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,7300,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,17000,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,80310,3168763,A6177
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,40500,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,6235,3168763,SYSTEM
123456789,2014-07-21 20:07:00.0,CUR142000224,2014-07-21 00:00:00.0,D,1115657,3168763,S133269951
123456789,2014-07-21 20:07:00.0,CUR142020344,2014-07-21 00:00:00.0,D,1045516,3168763,S133269951
123456789,2014-07-21 20:07:00.0,CUR142020399,2014-07-21 00:00:00.0,D,160862,3168763,S133269951
123456789,2014-07-21 20:07:00.0,,2014-07-21 00:00:00.0,D,21300,9370129,S133269951
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,16124,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,12201,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,37270,3168763,SYSTEM
123456789,2014-07-21 16:07:00.0,000000471619,2014-07-22 00:00:00.0,C,17581,3168763,S9457
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,28080,3168763,SYSTEM
123456789,2014-07-21 16:07:00.0,,2014-07-21 00:00:00.0,C,2000,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,16841,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,543564,3168763,S8822
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,9760,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,140155,3168763,A6177
123456789,2014-07-21 16:07:00.0,,2014-07-21 00:00:00.0,C,38915,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,210735,3168763,S12638
123456789,2014-07-21 16:07:00.0,000000087816,2014-07-22 00:00:00.0,C,77000,3168763,S9457
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,25650,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,31974,3194712,SYSTEM
123456789,2014-07-19 14:07:00.0,,2014-07-19 00:00:00.0,C,9390,3194712,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,6000,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,58072,3194712,Z0044
123456789,2014-07-19 13:07:00.0,000000459049,2014-07-21 00:00:00.0,C,22600,3194712,B2157
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,2616,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,30000,3194712,SYSTEM
123456789,2014-07-19 12:07:00.0,,2014-07-19 00:00:00.0,C,12025,3194712,SYSTEM
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,64461,3194712,G0456
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,54160,3194712,D4617
123456789,2014-07-19 13:07:00.0,,2014-07-19 00:00:00.0,C,11310,3194712,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,27895,3168763,SYSTEM
123456789,2014-07-21 15:07:00.0,,2014-07-21 00:00:00.0,C,28662,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,12220,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,18100,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,11240,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,320167,3168763,S12638
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,8120,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,3000,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,26000,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,13000,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,2693,3168763,SYSTEM
123456789,2014-07-21 14:07:00.0,000000021019,2014-07-22 00:00:00.0,C,2875,3168763,S9457
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,13665,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,453,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,43400,3168763,SYSTEM
123456789,2014-07-21 13:07:00.0,,2014-07-21 00:00:00.0,C,43458,3168763,SYSTEM
123456789,2014-07-21 14:07:00.0,000000425561,2014-07-22 00:00:00.0,C,18598,3168763,S9457
123456789,2014-07-21 10:07:00.0,,2014-07-21 00:00:00.0,C,44910,3168763,SYSTEM
123456789,2014-07-21 10:07:00.0,,2014-07-21 00:00:00.0,C,15000,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,10500,3168763,SYSTEM
123456789,2014-07-21 11:07:00.0,,2014-07-21 00:00:00.0,C,40000,3168763,SYSTEM
123456789,2014-07-21 12:07:00.0,,2014-07-21 00:00:00.0,C,9262,3168763,SYSTEM
123456789,2014-07-19 11:07:00.0,,2014-07-19 00:00:00.0,C,1700,7509853,SYSTEM
123456789,2014-07-19 10:07:00.0,000000577066,2014-07-21 00:00:00.0,C,3...

@suveena.almeida

Thanks for your cooperation.

I have tested the scenario while using Aspose.Pdf for Java 17.9 in a Java Web Application (IBM WAS, JDK 1.8) and was unable to notice the exception which you have mentioned. The code executed fine and generated output with 11523 records, without throwing any exception. For your reference, I have attached an output as well.

generatedPDF.pdf (1.5 MB)

Would you please share your environment details (i.e OS version, JDK Version, etc.), so that we can test the scenario in specified environment and address it accordingly.

Hii Asad

Please let us know your configuration details (Heap memory allocated to WAS,) Our OS version is AIX 6.5 JDK version 1.6. As we are frequently getting out of memory exception during high concurrency on production server.

Also find IBM’s revert attached with this reply
image.png (13.7 KB)

Hi Asad,

Looks like the product API uses a lot of memory for generating the PDF. I tried running the following standalone code snippet from within eclipse and it could not run for more than 25 rows (args[0]=25). Also, the same was using up over 315 MB of memory as checked in Task manager for generating the file. Kindly let us know if there is something we are missing

public static void main(String[] args) {
	// Instantiate Document object
	//System.out.println("Args:"+args.length);
	//System.out.println("Total Memeory Before Generation:"+Runtime.getRuntime().totalMemory());
	Document doc = new Document();
	// Add a page to pages collection of PDF file
	Page page = doc.getPages().add();
	// Instantiate HtmlFragment with HTML contents
	StringBuffer sb = new StringBuffer();
	sb.append("<table border=1 cellpadding=0 cellspacing=1 width=90%>");
	sb.append("<tr bgcolor=cyan>");
	sb.append("<td>");
	sb.append("First Name");
	sb.append("</td>");
	sb.append("<td>");
	sb.append("Last Name");
	sb.append("</td>");
	sb.append("<td>");
	sb.append("Age");
	sb.append("</td>");
	sb.append("</tr>");
	for(int i=0;i<Integer.valueOf(args[0]).intValue();i++)
	{
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("Shridhar");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("Kamat");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("48");
		sb.append("</td>");
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("Shridhar");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("Kamat");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("48");
		sb.append("</td>");
		sb.append("</tr>");
	}
	sb.append("</table>");
	HtmlFragment titel = new HtmlFragment(sb.toString());
	// set MarginInfo for margin details
	MarginInfo Margin = new MarginInfo();
	Margin.setBottom(10);
	Margin.setTop(200);
	// Set margin information
	titel.setMargin(Margin);
	// Add HTML Fragment to paragraphs collection of page
	page.getParagraphs().add(titel);
	//System.out.println("Total Memeory After Generation:"+Runtime.getRuntime().totalMemory());
	// Save PDF file
	doc.save("C:\\Temp\\output.pdf");
}

Following error is thrown while executing the save method of Document object

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.zip.InflaterInputStream.(Unknown Source)
at java.util.zip.ZipFile$ZipFileInflaterInputStream.(Unknown Source)
at java.util.zip.ZipFile.getInputStream(Unknown Source)
at java.util.jar.JarFile.getManifestFromReference(Unknown Source)
at java.util.jar.JarFile.getManifest(Unknown Source)
at sun.misc.URLClassPath$JarLoader$2.getManifest(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.aspose.pdf.Heading.m1(Unknown Source)
at com.aspose.pdf.ADocument.processParagraphs(Unknown Source)
at com.aspose.pdf.Document.processParagraphs(Unknown Source)
at com.aspose.pdf.ADocument.saveInternal(Unknown Source)
at com.aspose.pdf.Document.saveInternal(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at sis.tm.client.apps.hdfcb.cur.web.FileGeneration.FILEGENERATIONCONSTS.main(FILEGENERATIONCONSTS.java:488)

@suveena.almeida

Thanks for writing back.

Please notice the Heap Size Parameters at my side for the Eclipse, whereas OS is Win10 EN x64 and JDK 1.8:

Xms256m
Xmx1024m

We have tested the scenario and were unable to notice the OOM Exception in our environment. For your reference, a PDF, generated in our environment, is also attached.

Temp_output.pdf (40.1 KB)

Furthermore, we did observe the memory consumption of ~500MB while PDF generation and when we tried to generate PDF with 150 rows, the code ended up giving Out of Memory Exception and memory consumption reached upto ~1GB. For the sake of detailed investigation, we have logged a quality issue as PDFJAVA-37198 in our issue tracking system.

We have provided details of both scenarios and environments along with the logged issue. Product team will further investigate the issue and as soon as we receive some news regarding investigation progress, we will inform you. Please be patient and spare us little time.

However, it is advisable to upgrade JDK to latest version as it also allows your program/application to access more memory. Moreover, latest JDKs have better memory management and improvements. So upgrading JDK to latest version will definitely helps you get better performance and results.

We are sorry for the inconvenience caused.

Hi,

Kindly update if you have any findings on the OOM issue since we cannot use the product if it occupies about 1 GB of Heap memory to generate report having about 150 rows. In our production environment the report may consist of over 20000 rows and also may be generated by multiple concurrent users.

As per your suggestion, we also tried to use Java 1.8 under standalone environment and could generate the PDF for 10000 rows.

Kindly expedite resolution as we are having lot of client escalations.

@suveena.almeida

Thanks for your inquiry.

As we recently have logged the investigation ticket in our issue tracking system, so I am afraid it is still pending for review. The product team will start an investigation against logged ticket, as per their development schedule. We have recorded your recent concerns and shared them with respective team as well. As soon as we get some definite feedback from their side, we will certainly let you know. Please spare us little time.

We are sorry for the inconvenience.

Still awaiting reply for the logged issue.

@suveena.almeida

Thanks for your inquiry.

I am afraid that earlier logged issue has not been yet investigated, due to others pending issues in the queue, reported prior to this issue. However, respective team will surely plan an investigation as per their development schedule and as soon as we receive some news on resolution progress, we will let you know. Please spare us little time.

We are sorry for the inconvenience.