We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose PDF - Infinite Loop

Hi,


We use aspose PDF to generate our reports on PDF. Reports are fairly simple with a table containing rows and columns.

We have trouble where if a data within a cell is a big enough to not fit on the single page. Aspose tends to go on to some kind of infinite loop or something. And brings application server down.

Below is the stack form the thread ,

This is very urgent and is causing huge unrest to us. Can you help ?


BlockedCount:6 BlockedTime:-1 LockName:null LockOwnerID:-1 LockOwnerName:null
WaitedCount:5 WaitedTime:-1 InNative:false IsSuspended:false at com.aspose.pdf.internal.p550.z9.m6(null:-1)
at com.aspose.pdf.internal.p550.z9.m12(null:-1)
at com.aspose.pdf.internal.p550.z9.m22(null:-1)
at com.aspose.pdf.internal.p583.z8.m1(null:-1)
at com.aspose.pdf.internal.p583.z8.m1(null:-1)
at com.aspose.pdf.internal.p583.z8.m1(null:-1)
at com.aspose.pdf.internal.ms.System.z89.m1(null:-1)
at com.aspose.pdf.internal.p45.z2.m2(null:-1)
at com.aspose.pdf.internal.p46.z1.m2(null:-1)
at com.aspose.pdf.internal.p46.z7.m1(null:-1)
at com.aspose.pdf.internal.p46.z1.m1(null:-1)
at com.aspose.pdf.internal.p57.z35.m2(null:-1)
at com.aspose.pdf.internal.p57.z35.m8(null:-1)
at com.aspose.pdf.internal.p51.z6.m1(null:-1)
at com.aspose.pdf.internal.p51.z1.m4(null:-1)
at com.aspose.pdf.internal.p51.z6.m2(null:-1)
at com.aspose.pdf.internal.p51.z1.m1(null:-1)
at com.aspose.pdf.TextSegment.setText(null:-1)
at com.aspose.pdf.TextSegment.m1(null:-1)
at com.aspose.pdf.TextBuilder.m1(null:-1)
at com.aspose.pdf.TextBuilder.appendParagraph(null:-1)
at com.aspose.pdf.TextBuilder.appendParagraph(null:-1)
at com.aspose.pdf.z63.m1(null:-1)
at com.aspose.pdf.z63.m6(null:-1)
at com.aspose.pdf.Cell.m1(null:-1)
at com.aspose.pdf.Row.m1(null:-1)
at com.aspose.pdf.Table.m1(null:-1)
at com.aspose.pdf.z63.m6(null:-1)
at com.aspose.pdf.Page.m2(null:-1)
at com.aspose.pdf.Page.processParagraphs(null:-1)
at com.aspose.pdf.ADocument.processParagraphs(null:-1)
at com.aspose.pdf.Document.processParagraphs(null:-1)
at com.aspose.pdf.ADocument.saveInternal(null:-1)
at com.aspose.pdf.Document.saveInternal(null:-1)
at com.aspose.pdf.ADocument$1.m1(null:-1)
at com.aspose.pdf.internal.p718.z2.m2(null:-1)
at com.aspose.pdf.internal.p718.z3.m1(null:-1)
at com.aspose.pdf.ADocument.save(null:-1)

Hi Ritesh,


Thanks for your inquriy. We will appreciate it if you please share a sample code to replicate the issue at our end, so we will look into it and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Please find sample code that brings down my JVM



com.aspose.pdf.Document ndoc = new com.aspose.pdf.Document();
com.aspose.pdf.Page npage = ndoc.getPages().add();
com.aspose.pdf.MarginInfo pagemargins = new com.aspose.pdf.MarginInfo();
pagemargins.setLeft(50f);
pagemargins.setRight(50f);
pagemargins.setTop(50f);
pagemargins.setBottom(80f);

PageInfo npageInfo = new PageInfo();
npageInfo.setMargin(pagemargins);

npage.setPageInfo(npageInfo);


// set page size
//todo > Set landscape vs Portraite for all options below
PageInfo pageInfo = npage.getPageInfo();
pageInfo.setHeight(com.aspose.pdf.PageSize.getA4().getHeight());
pageInfo.setWidth(com.aspose.pdf.PageSize.getA4().getWidth());


//Instantiate HeaderFooter object and pass the Section reference in which
com.aspose.pdf.HeaderFooter nheader = new com.aspose.pdf.HeaderFooter();
com.aspose.pdf.MarginInfo headermarginInfo = new com.aspose.pdf.MarginInfo();
headermarginInfo.setTop(50);
nheader.setMargin(headermarginInfo);

com.aspose.pdf.HeaderFooter nfooter = new com.aspose.pdf.HeaderFooter();
com.aspose.pdf.MarginInfo footermarginInfo = new com.aspose.pdf.MarginInfo();
footermarginInfo.setBottom(50);
footermarginInfo.setLeft(50);
footermarginInfo.setRight(50);
nfooter.setMargin(footermarginInfo);
npage.setFooter(nfooter);


int rowslenght = 10;
int rowslenght1 = 100;
String[] headers = new String[rowslenght];
for (int a = 0; a < headers.length; a++) {
headers[a] = “Header_” + a;

}


String reportHeader = “Report Header”;
com.aspose.pdf.TextFragment reportheaderData;
if (!StringUtil.isEmpty(reportHeader)) {
reportheaderData = new com.aspose.pdf.TextFragment(reportHeader);
npage.getParagraphs().add(reportheaderData);
}
com.aspose.pdf.TextFragment textFragment;
textFragment = new com.aspose.pdf.TextFragment(“Report Title”);

textFragment.getTextState().setFontSize(14.0f);
nheader.getParagraphs().add(textFragment);

com.aspose.pdf.MarginInfo headerMargine = new com.aspose.pdf.MarginInfo();
headerMargine.setLeft(50f);
headerMargine.setRight(50f);
headerMargine.setTop(50f);
nheader.setMargin(headerMargine);
com.aspose.pdf.MarginInfo defaultTablePadding = new com.aspose.pdf.MarginInfo();
defaultTablePadding.setTop(4.0f);
defaultTablePadding.setBottom(4.0f);
defaultTablePadding.setLeft(4.0f);
defaultTablePadding.setRight(4.0f);


com.aspose.pdf.drawing.Line nline = new com.aspose.pdf.drawing.Line();
TextFragment ftext = new TextFragment(“Page $p of $P”);
ftext.getTextState().setHorizontalAlignment(HorizontalAlignment.Right);


Login runAsLogin = null;
com.aspose.pdf.TextFragment footerData = new com.aspose.pdf.TextFragment(“Data of”);
footerData.getTextState().setHorizontalAlignment(HorizontalAlignment.Left);

com.aspose.pdf.Table footerTable = new com.aspose.pdf.Table();
footerTable.setDefaultCellPadding(defaultTablePadding);

double fwidth = (((npageInfo.isLandscape() ? npageInfo.getHeight() : npageInfo.getWidth()) - (npage.getPageInfo().getMargin().getLeft() + npage.getPageInfo().getMargin().getRight())) / 4.00);
footerTable.setColumnWidths((fwidth * 3) + " " + fwidth);

com.aspose.pdf.Row footerRow = footerTable.getRows().add();
com.aspose.pdf.BorderInfo footerBorder = new com.aspose.pdf.BorderInfo();
com.aspose.pdf.GraphInfo footerGraphInfo = new com.aspose.pdf.GraphInfo();
footerGraphInfo.setLineWidth(1f);
footerBorder.setTop(footerGraphInfo);
footerRow.setBorder(footerBorder);
com.aspose.pdf.Cell footerLeftCell = footerRow.getCells().add();
footerLeftCell.getParagraphs().add(footerData);
com.aspose.pdf.Cell footerRightCell = footerRow.getCells().add();
footerRightCell.getParagraphs().add(ftext);
nfooter.getParagraphs().add(footerTable);
npage.setFooter(nfooter);
com.aspose.pdf.Table ntable = new com.aspose.pdf.Table();
ntable.setDefaultCellPadding(defaultTablePadding);
ntable.setAlignment(AlignmentType.Left);

// Repeat header
ntable.setRepeatingRowsCount(2);
// Add row
com.aspose.pdf.Row row = ntable.getRows().add();
com.aspose.pdf.Cell ncell = row.getCells().add();
ncell.setColSpan(headers.length);
ncell.getParagraphs().add(textFragment);
row = ntable.getRows().add();

com.aspose.pdf.BorderInfo headerBorders = new com.aspose.pdf.BorderInfo();
com.aspose.pdf.GraphInfo graphInfo = new com.aspose.pdf.GraphInfo();
graphInfo.setLineWidth(1f);
headerBorders.setBottom(graphInfo);
headerBorders.setTop(graphInfo);
row.setBorder(headerBorders);

String columnWidths = “”;

// start loops there
float totalwidth = (float) ((npageInfo.isLandscape() ? npageInfo.getHeight() : npageInfo.getWidth()) - (npage.getPageInfo().getMargin().getLeft() + npage.getPageInfo().getMargin().getRight()));
float remainingWidth = totalwidth;
for (int x = 0; x < headers.length; x++) {
columnWidths += "100 ";
}

ntable.setColumnWidths(columnWidths);

for (String head : headers) {
com.aspose.pdf.Cell cell = row.getCells().add(head);
}

com.aspose.pdf.BorderInfo totalBorder = new com.aspose.pdf.BorderInfo();
totalBorder.setBottom(graphInfo);
com.aspose.pdf.Cell c;
com.aspose.pdf.TextFragment t;

for (int i1 = 0; i1 < rowslenght1; i1++) {

row = ntable.getRows().add();


for (int i2 = 0; i2 < headers.length; i2++) {
Object object = “Normal Text”;
if (i1 == 5 && i2 == 1) {
StringBuilder sb = new StringBuilder();
// iterate 100 times and this will bring the JVM down, iterate 110 times and it will be just fine , iterate 90 times is also just fine
for (int b = 0; b < 100; b++)
sb.append("String Long ");
object = sb;
}
t = new TextFragment(object == null ? “” : object.toString());
t.getTextState().setFontStyle(FontStyles.Bold);
c = row.getCells().add();
c.getParagraphs().add(t);
}
}
npage.getParagraphs().add(ntable);

String reportFooter = “Footer Data”;
com.aspose.pdf.TextFragment reportfooterData;
if (!StringUtil.isEmpty(reportFooter)) {
reportfooterData = new com.aspose.pdf.TextFragment(reportFooter);
com.aspose.pdf.MarginInfo footerPadding = new com.aspose.pdf.MarginInfo();
footerPadding.setTop(8.0f);
reportfooterData.setMargin(footerPadding);
npage.getParagraphs().add(reportfooterData);
}
ndoc.save(“c:\dev\file” + Math.abs(Math.random()) + “.pdf”);
ndoc.freeMemory();
ndoc.dispose();

Hi Ritesh,


Thanks for sharing your sample source code. I have tested your code with a long text(210 iterations of appending sample text) with Aspose.Pdf for Java 11.4.0 and unable to notice the reported issue. We will appreciate it if you please use latest version of Aspose.Pdf for Java, it will resolve the issue.

…<o:p></o:p>

....

// iterate 100 times and this will bring the JVM down, iterate 110 times and it will be just fine , iterate 90 times is also just fine

for (int b = 0; b < 210; b++)

sb.append("String Long ");

....

....


Best Regards,

Hi


Thanks for that, I did upgrade to new version and it solves problem but not completely. Now for some other instance I am getting same issue. It’s not possible for me to send you sample code to help you reproduce issue on your side this time. There are a lot many combinations around it.

Here is the stack trace with CPU load details and memory details. I am sure you guys have some some clue on what is going on.

If it does not generate PDF that’s fine but it should not hold my CPU and Memory endlessly. Is there a way aspose can exit gracefully and move on with next execution if such a thing happens.

Also this only happens easily if I have data with reasonable huge text in it. like 1000 or 1500 up to 2000 chars long text.

“http-apr-8080-exec-1” : 2040 : RUNNABLE : cpu=306375000000 : cpuLoad= 95.7988
BlockedCount:0 BlockedTime:-1 LockName:null LockOwnerID:-1 LockOwnerName:null
WaitedCount:14 WaitedTime:-1 InNative:false IsSuspended:false at com.aspose.pdf.internal.p567.z6.m1(null:-1)
at com.aspose.pdf.internal.p567.z6.m1(null:-1)
at com.aspose.pdf.internal.ms.System.z133.m8(null:-1)
at com.aspose.pdf.internal.p55.z1.m1(null:-1)
at com.aspose.pdf.internal.p56.z6.m1(null:-1)
at com.aspose.pdf.internal.p56.z1.m1(null:-1)
at com.aspose.pdf.TextSegment.setText(null:-1)
at com.aspose.pdf.TextSegment.m1(null:-1)
at com.aspose.pdf.TextBuilder.m1(null:-1)
at com.aspose.pdf.TextBuilder.appendParagraph(null:-1)
at com.aspose.pdf.TextBuilder.appendParagraph(null:-1)
at com.aspose.pdf.z65.m1(null:-1)
at com.aspose.pdf.z65.m8(null:-1)
at com.aspose.pdf.Cell.m1(null:-1)
at com.aspose.pdf.Row.m1(null:-1)
at com.aspose.pdf.Table.m1(null:-1)
at com.aspose.pdf.z65.m8(null:-1)
at com.aspose.pdf.Page.m2(null:-1)
at com.aspose.pdf.Page.m8(null:-1)
at com.aspose.pdf.ADocument.processParagraphs(null:-1)
at com.aspose.pdf.Document.processParagraphs(null:-1)
at com.aspose.pdf.ADocument.saveInternal(null:-1)
at com.aspose.pdf.Document.saveInternal(null:-1)
at com.aspose.pdf.ADocument$2.m1(null:-1)
at com.aspose.pdf.internal.p735.z2.m2(null:-1)
at com.aspose.pdf.internal.p735.z3.m1(null:-1)
at com.aspose.pdf.ADocument.save(null:-1)
at com.aspose.pdf.Document.save(null:-1)

Hi Ritesh,


Thanks for your feedback. It is good to know that your initial reported issue is resolved with latest release. However in reference to new issue, I am afraid it is quite difficult to suggest you any thing without replicating issue as out end. Please try to break the table in which you have huge text as following and share the results. However if the issue persist then please share your sample code here, we will look into it and will guide you accordingly.

…<o:p></o:p>

....

com.aspose.pdf.Table table = new com.aspose.pdf.Table();

table.setBroken(TableBroken.Vertical);

....

....


We are sorry for the inconvenience caused.

Best Regards,