使用jira-javamelody-1.57.1​​.jar生成PDF时出现堆栈溢出错误

时间:2018-01-12 10:17:18

标签: java itext

class ProductRequestPage2 extends PdfPageEventHelper

public void onEndPage(PdfWriter writer, Document document) {}

Table table = new Table(1);table.setWidth(100);
table.setTableFitsPage(true);
table.setBorderWidth(0);
table.setBorder(0);
table.getDefaultCell().setBorder(0);
table.setOffset(5);
Cell secondCell = new Cell(new Phrase("", new Font(bf2, 9)));
table.addCell(secondCell);
secondCell = new Cell(new Phrase("Global Export Control ", new Font(bf2,  9)));
secondCell.setBackgroundColor(new Color(0xC1, 0xC0, 0xC0));
secondCell.setHorizontalAlignment(Element.ALIGN_LEFT);
secondCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
secondCell.setLeading(9);
table.addCell(secondCell);//Line no 1675

堆栈追踪:

Caused by: java.lang.StackOverflowError
    at com.lowagie.text.pdf.events.PdfPageEventForwarder.onEndPage(Unknown Source) ~[itext-2.1.7.jar:?]
    at com.lowagie.text.pdf.PdfDocument.newPage(Unknown Source) ~[itext-2.1.7.jar:?]
    at com.lowagie.text.pdf.PdfDocument.carriageReturn(Unknown Source) ~[itext-2.1.7.jar:?]
    at com.lowagie.text.pdf.PdfDocument.add(Unknown Source) ~[itext-2.1.7.jar:?]
    at com.ocr.pcs.action.ProductRequestPdf$ProductRequestPage2.onEndPage(ProductRequestPdf.java:1675) ~[?:?]
    at com.lowagie.text.pdf.events.PdfPageEventForwarder.onEndPage(Unknown Source) ~[itext-2.1.7.jar:?]
    at com.lowagie.text.pdf.PdfDocument.newPage(Unknown Source) ~[itext-2.1.7.jar:?]

1 个答案:

答案 0 :(得分:0)

您是否使用此代码创建了新页面?您的表适合页面并具有偏移量,尝试使其略小于页面

  • onEndPage:创建新页面
  • 处理新页面:没有
  • 新页面onEndPage:创建新页面
  • 处理新页面:没有
  • 新页面onEndPage:创建新页面
  • 处理新页面:没有
  • 新页面onEndPage:创建新页面
  • 等等,StackOverflowError