PDF导出错误

时间:2015-06-10 10:14:56

标签: java pdf itext

这是我的代码段 -

getResponse().setContentType(NAPSConstants.PDF_CONTENT_TYPE);
getResponse().setHeader(NAPSConstants.PDF_CONTENT_DISP, NAPSConstants.PDF_ATTACHMENT_FILE+getText("rcmid.details")+NAPSConstants.PDF_EXTN);
//Set the Page Size
Document document = new Document(PageSize.A3, 40, 40, 40, 40);

    PdfPTable table = new PdfPTable(rcmDetailsCols.length); 
    for(RCMIDPartsDetailsDTO part : rcmidDTO.getPartsDetailsDTO()){
            table.addCell(part.getPartStatus().equals(NAPSConstants.Active) ? 
                    PDFHelper.dataCell( part.getPlantName(), PDFHelper.FONT_DATA) : 
PDFHelper.coloredDataCell( part.getPlantName(), PDFHelper.FONT_DATA));
table.addCell(part.getPartStatus().equals(NAPSConstants.Active) ?
                            PDFHelper.dataCell( part.getOemSupplierId(), PDFHelper.FONT_DATA):PDFHelper.coloredDataCell( part.getOemSupplierId(), PDFHelper.FONT_DATA));
table.addCell(PDFHelper.dataCellWithRowSpan( rcmidDTO.getPackSupplierId(), PDFHelper.FONT_DATA, rcmidDTO.getActiveRowSpan()+rcmidDTO.getPartsList.size()));

                }
                document.add(table);

    document.close();

//助手方法

public static PdfPCell dataCell(String cellText, Integer fontSize)
    {
        PdfPCell cell = new PdfPCell();
        if(cellText==null || cellText.compareTo("null")==0 || NAPSConstants.EMPTY_STRING.equals(cellText) || 
                cellText.equals(NAPSConstants.MINUS_ONE)){
            //cellText = NAPSConstants.TEXT_NA;
            cellText = NAPSConstants.EMPTY_STRING;
        }
        cell.setPhrase(new Phrase(cellText, new Font(Font.NORMAL, fontSize)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        return cell;
    }
public static PdfPCell coloredDataCell(String cellText, Integer fontSize)
    {
        PdfPCell cell = new PdfPCell();
        if(cellText==null || cellText.compareTo("null")==0 || NAPSConstants.EMPTY_STRING.equals(cellText) || 
                cellText.equals(NAPSConstants.MINUS_ONE)){
            //cellText = NAPSConstants.TEXT_NA;
            cellText = NAPSConstants.EMPTY_STRING;
        }

        cell.setPhrase(new Phrase(cellText, new Font(Font.NORMAL, fontSize,0, new Color(255,0,0))));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell.setBackgroundColor(new Color(200, 200, 200));
        return cell;
    }

 public static PdfPCell dataCellWithRowSpan(String cellText, Integer fontSize, int rowspan)
    {
        PdfPCell cell = new PdfPCell();
        cell.setRowspan(rowspan);   
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        if(cellText==null || cellText.compareTo("null")==0){
            //cellText = NAPSConstants.TEXT_NA;
            cellText = NAPSConstants.EMPTY_STRING;
        }

        cell.setPhrase(new Phrase(cellText, new Font(Font.NORMAL, fontSize)));
        return cell;
    }

我无法理解实际问题是什么。 我有两种数据'活动'/'非活动',因此我添加了三元运算符来更改非活动数据的背景颜色。 pdf导出对于活动数据非常好。但对于非活动数据,以下是例外情况。

ThreadMonitor W   WSVR0605W: Thread "WebContainer : 3" (0000001c) has been active for 754832 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.
    at com.lowagie.text.pdf.BidiLine.createArrayOfPdfChunks(Unknown Source)
    at com.lowagie.text.pdf.BidiLine.createArrayOfPdfChunks(Unknown Source)
    at com.lowagie.text.pdf.BidiLine.processLine(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.PdfPCell.getMaxHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.calculateHeights(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.setTotalWidth(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.goComposite(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.PdfDocument.addPTable(Unknown Source)
    at com.lowagie.text.pdf.PdfDocument.add(Unknown Source)
    at com.lowagie.text.Document.add(Unknown Source)
    at com.honda.naps.action.rcmid.RCMIDDetailsAction.rcmDetailsExportTOPDF(RCMIDDetailsAction.java:490)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:600)

此外,java进程占用CPU使用率的95%。服务器变得非常慢。我必须手动停止java进程并重启服务器。

1 个答案:

答案 0 :(得分:0)

问题解决了 -

由于现有架构的依赖性,我无法更新jar。

但真正的问题是使用rowspan。 有效/无效部分的行距不同。 改变逻辑之后问题就解决了。