Here is my code snippet-
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();
//Helper methods
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;
}
I am not able to understand what the actual problem is. I have two kinds of data 'Active'/'Inactive', therefore i have added ternary operator to change background color for inactive data. The pdf export work perfectly fine for active data. But for inactive data the following is the exception.
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)
Also the java process takes upto 95% of CPU usage. The server becomes very slow. I have to stop the java process manually and restart server.
Problem solved-
I was not able to update the jar because of dependencies of existing architecture.
But the real problem was with rowspan. The rowspan was different for active/inactive parts. After changing that logic the problem was solved.