2015-06-10 29 views
0

这里是我的代码snippet-错误在PDF导出

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进程并重新启动服务器。

+0

我在你的错误信息中看到我的名字。这意味着您使用的是6年前的iText版本。该版本不再受支持。当前版本是5.5.6。请升级。 –

+0

是的应用程序已超过6年。通过更新到最新版本将解决这个问题? – Waqar

+0

你是说你有一个6年的应用程序,并且你一直在等待报告问题?表功能已被完全重写,所以问题很可能会消失。 –

回答

0

问题solved-

我无法更新,因为现有的架构的依赖关系的罐子。

但真正的问题是与rowspan。 活动/非活动部件的行距不同。 更改该逻辑后,问题得以解决。