/* * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * * https://creativecommons.org/licenses/by/4.0/ * * Unless required by applicable law or agreed to in writing, documentation * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ============LICENSE_END============================================ * * */ /* =========================================================================================== * This class is part of RAPTOR (Rapid Application Programming Tool for OLAP Reporting) * Raptor : This tool is used to generate different kinds of reports with lot of utilities * =========================================================================================== * * ------------------------------------------------------------------------------------------- * PdfReportHandler.java - This class is used to generate reports in PDF using iText * ------------------------------------------------------------------------------------------- * * * Changes * ------- * 14-Jul-2009 : Version 8.4 (Sundar); * */ package org.onap.portalsdk.analytics.model.pdf; import com.lowagie.text.BadElementException; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.ElementTags; import com.lowagie.text.Font; import com.lowagie.text.FontFactory; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; import com.lowagie.text.html.simpleparser.HTMLWorker; import com.lowagie.text.html.simpleparser.StyleSheet; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfWriter; import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.StringReader; import java.net.MalformedURLException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TimeZone; import java.util.TreeMap; import java.util.Vector; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.error.ReportSQLException; import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; import org.onap.portalsdk.analytics.util.HtmlStripper; import org.onap.portalsdk.analytics.util.Utils; import org.onap.portalsdk.analytics.view.ColumnHeader; import org.onap.portalsdk.analytics.view.ColumnHeaderRow; import org.onap.portalsdk.analytics.view.DataRow; import org.onap.portalsdk.analytics.view.DataValue; import org.onap.portalsdk.analytics.view.HtmlFormatter; import org.onap.portalsdk.analytics.view.ReportData; import org.onap.portalsdk.analytics.view.RowHeader; import org.onap.portalsdk.analytics.view.RowHeaderCol; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; /** * @author mwliu and sundar * */ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PdfReportHandler.class); private PdfBean pb; private HtmlStripper strip = new HtmlStripper(); private static final int RetryCreateNewImage = 3; private int retryCreateNewImageCount=0; private String FONT_FAMILY = "Arial"; private int FONT_SIZE = 9; public PdfReportHandler() { } public void createPdfFileContent(HttpServletRequest request, HttpServletResponse response, int type) throws IOException, RaptorException { Document document = new Document(); ReportHandler rh = new ReportHandler(); String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date()); String pdfFName = ""; String user_id = AppUtils.getUserID(request); response.reset(); response.setContentType("application/pdf"); OutputStream outStream = response.getOutputStream(); String formattedReportName = ""; PdfWriter writer = null; ReportRuntime firstReportRuntimeObj = null; int returnValue = 0; ReportRuntime rr = null; if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); boolean isDashboard = false; if ((request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)!=null) && ( ((String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).equals(rr.getReportID())) ) { isDashboard = true; } if(isDashboard) { try { String reportID = (String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID); ReportRuntime rrDash = rh.loadReportRuntime(request, reportID, true, 1); pb = preparePdfBean(request,rrDash); // Setting pb Values document.setPageSize(PageSize.getRectangle(pb.getPagesize())); if(!pb.isPortrait()) // get this from properties file document.setPageSize(document.getPageSize().rotate()); // writer = PdfWriter.getInstance(document, response.getOutputStream()); writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark document.open(); formattedReportName = new HtmlStripper().stripSpecialCharacters(rrDash.getReportName()); if(pb.isAttachmentOfEmail()) response.setHeader("Content-disposition", "inline"); else response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf"); pdfFName = "dashboard"+formattedReportName+formattedDate+user_id+".pdf"; Map reportRuntimeMap = null; Map reportDataMap = null; Map reportDisplayTypeMap = null; reportRuntimeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP); reportDataMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP); reportDisplayTypeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP); if(reportRuntimeMap!=null) { Set setReportRuntime = reportRuntimeMap.entrySet(); Set setReportDataMap = reportDataMap.entrySet(); Set setReportDisplayTypeMap = reportDisplayTypeMap.entrySet(); Iterator iter2 = setReportDataMap.iterator(); Iterator iter3 = setReportDisplayTypeMap.iterator(); int count = 0; for(Iterator iter = setReportRuntime.iterator(); iter.hasNext(); ) { count++; Map.Entry entryData = (Entry) iter2.next(); Map.Entry entry = (Entry) iter.next(); Map.Entry entryCheckChart = (Entry) iter3.next(); ReportRuntime rrDashRep = (ReportRuntime) entry.getValue(); if(count == 1) { firstReportRuntimeObj = (ReportRuntime) entry.getValue(); if(pb.isCoverPageIncluded()) { document = paintDashboardCoverPage(document, rrDash, firstReportRuntimeObj, request); } } ReportData rdDashRep = (ReportData) entryData.getValue(); int col = 0; if( ((rrDashRep.getChartType()).trim().length()>0 && rrDashRep.getDisplayChart()) && entryCheckChart.getValue().toString().equals("c")) { document.newPage(); pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName()); paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rrDashRep.getReportID()+".png", rrDashRep); } else { document.newPage(); pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName()); paintPdfData(request, document,rdDashRep,rrDashRep, ""); } } } } catch (DocumentException dex) { logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", dex); } catch (RaptorException rex) { logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in createPdfFileContent", rex); } } else { rr = null; ReportData rd = null; String parent = ""; int parentFlag = 0; if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), ""); if(parent.startsWith("parent_")) parentFlag = 1; if(parentFlag == 1) { rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr"); rd = (ReportData) request.getSession().getAttribute(parent+"_rd"); } if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); if(rd==null) rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA); pb = preparePdfBean(request,rr); FONT_FAMILY = rr.getPDFFont(); FONT_SIZE = rr.getPDFFontSize(); formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName()); response.setContentType("application/pdf"); if(pb.isAttachmentOfEmail()) response.setHeader("Content-disposition", "inline"); else response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf"); document.setPageSize(PageSize.getRectangle(pb.getPagesize())); if(!pb.isPortrait()) // get this from properties file document.setPageSize(document.getPageSize().rotate()); try { writer = PdfWriter.getInstance(document, outStream); writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark document.open(); if(pb.isCoverPageIncluded()) { document = paintCoverPage(document, rr, request); } if(pb.isDisplayChart()) { paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+".png", rr); } document.newPage(); if(type == 3 && rr.getSemaphoreList()==null && !(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) ) { //type = 3 is whole String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE); returnValue = paintPdfData(request, document, rd, rr, sql_whole); } else if(type == 2) { returnValue = paintPdfData(request, document, rd, rr, ""); } else { int downloadLimit = (rr.getMaxRowsInExcelDownload()>0)?rr.getMaxRowsInExcelDownload():Globals.getDownloadLimit(); String action = request.getParameter(AppConstants.RI_ACTION); if(!(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) && !action.endsWith("session")) rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, false /*download*/); if(rr.getSemaphoreList()!=null) { rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, true); returnValue = paintPdfData(request, document, rd, rr, ""); } else { returnValue = paintPdfData(request, document, rd, rr, rr.getWholeSQL()); } } } catch (DocumentException de) { logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", de); } } document.close(); int mb = 1024*1024; Runtime runtime = Runtime.getRuntime(); logger.debug(EELFLoggerDelegate.debugLogger, ("##### Heap utilization statistics [MB] #####")); logger.debug(EELFLoggerDelegate.debugLogger, ("Used Memory:" + (runtime.maxMemory() - runtime.freeMemory()) / mb)); logger.debug(EELFLoggerDelegate.debugLogger, ("Free Memory:" + runtime.freeMemory() / mb)); logger.debug(EELFLoggerDelegate.debugLogger, ("Total Memory:" + runtime.totalMemory() / mb)); logger.debug(EELFLoggerDelegate.debugLogger, ("Max Memory:" + runtime.maxMemory() / mb)); } private Document paintCoverPage(Document doc, ReportRuntime rr, HttpServletRequest request) throws IOException, DocumentException { if(nvl(rr.getPdfImg()).length()>0) { Image image1 = Image.getInstance(AppUtils.getExcelTemplatePath()+"../../"+AppUtils.getImgFolderURL()+rr.getPdfImg()); image1.scalePercent(20f, 20f); doc.add(image1); } float firstColumnSize = Globals.getCoverPageFirstColumnSize(); float[] relativeWidths = {firstColumnSize,1f-firstColumnSize}; PdfPTable table = new PdfPTable(relativeWidths); table.getDefaultCell().setBorderWidth(0); addEmptyRows(table,6); HTMLWorker worker = new HTMLWorker(doc); StyleSheet style = new StyleSheet(); style.loadTagStyle("body", "leading", "16,0"); StringBuffer reportDescrBuf = new StringBuffer(""); ArrayList descr = HTMLWorker.parseToList(new StringReader(nvl(rr.getReportDescr())), style); ArrayList paraList = null; if(nvl(rr.getReportTitle()).length()>0) { add2Cells(table,"Report Title : ",nvl(rr.getReportTitle())); if(nvl(rr.getReportSubTitle()).length()>0) { add2Cells(table,"Report Sub-Title : ",nvl(rr.getReportSubTitle())); System.out.println("Adding the report sub-title "); } } else { add2Cells(table,"Report Name : ",nvl(rr.getReportName())); } if((descr!=null && descr.size()>0)) { paraList = (com.lowagie.text.Paragraph)descr.get(0); for (int i=0 ; i0) { String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(","); String name=nameValue[0]; String value=nameValue[1]; add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value)))); } if(Globals.isCreatedOwnerInfoNeeded()) { add2Cells(table,"Created By : ",nvl(AppUtils.getUserName(rr.getCreateID()))); add2Cells(table,"Owner : ",nvl(AppUtils.getUserName(rr.getOwnerID()))); } if(Globals.displayLoginIdForDownloadedBy()) add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserBackdoorLoginId(request))); else add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserName(AppUtils.getUserID(request)))); addEmptyRows(table,1); boolean isFirstRow = true; ArrayList al = rr.getParamNameValuePairsforPDFExcel(request, 1); if(al.size()<=0) { al = (ArrayList) request.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO); } Iterator it = al.iterator(); addEmptyRows(table,1); if(rr.getFormFieldComments(request).length()<=0) { while(it.hasNext()) { if(isFirstRow) { add2Cells(table, "Run-time Criteria : ", " "); isFirstRow = false; } IdNameValue value = (IdNameValue)it.next(); if(!value.getId().trim().equals("BLANK")) add2Cells(table, value.getId()+" : ",value.getName().replaceAll("~",",")); } addEmptyRows(table,1); doc.add(table); } else { it = al.iterator(); if(it.hasNext()) { addEmptyRows(table,1); doc.add(table); ArrayList p = HTMLWorker.parseToList(new StringReader(rr.getFormFieldComments(request).replaceAll("~",",")), style); for (int k = 0; k < p.size(); ++k){ doc.add((com.lowagie.text.Element)p.get(k)); } } } return doc; } private Document paintDashboardCoverPage(Document doc, ReportRuntime rrDashRep, ReportRuntime firstReportRuntimeObj, HttpServletRequest request) throws IOException, DocumentException { float firstColumnSize = Globals.getCoverPageFirstColumnSize(); float[] relativeWidths = {firstColumnSize,1f-firstColumnSize}; PdfPTable table = new PdfPTable(relativeWidths); table.getDefaultCell().setBorderWidth(0); addEmptyRows(table,6); add2Cells(table,"Report Name : ",rrDashRep.getReportName()); add2Cells(table,"Description : ",rrDashRep.getReportDescr()); if(Globals.getSessionInfoForTheCoverPage().length()>0) { String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(","); String name=nameValue[0]; String value=nameValue[1]; add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value)))); } if(Globals.isCreatedOwnerInfoNeeded()) { add2Cells(table,"Created By : ",AppUtils.getUserName(rrDashRep.getCreateID())); add2Cells(table,"Owner : ",AppUtils.getUserName(rrDashRep.getOwnerID())); } if(Globals.displayLoginIdForDownloadedBy()) add2Cells(table,"Downloaded by : ",AppUtils.getUserBackdoorLoginId(request)); else add2Cells(table,"Downloaded by : ",AppUtils.getUserName(request)); addEmptyRows(table,1); boolean isFirstRow = true; ArrayList al = firstReportRuntimeObj.getParamNameValuePairsforPDFExcel(request, 2); Iterator it = al.iterator(); addEmptyRows(table,1); if(firstReportRuntimeObj.getFormFieldComments(request).length()<=0) { while(it.hasNext()) { if(isFirstRow) { add2Cells(table, "Run-time Criteria : ", " "); isFirstRow = false; } IdNameValue value = (IdNameValue)it.next(); if(!value.getId().trim().equals("BLANK")) add2Cells(table, value.getId()+" : ",value.getName()); } addEmptyRows(table,1); doc.add(table); } else { it = al.iterator(); if(it.hasNext()) { addEmptyRows(table,1); doc.add(table); HTMLWorker worker = new HTMLWorker(doc); StyleSheet style = new StyleSheet(); style.loadTagStyle("body", "leading", "16,0"); ArrayList p = HTMLWorker.parseToList(new StringReader(firstReportRuntimeObj.getFormFieldComments(request)), style); for (int k = 0; k < p.size(); ++k){ doc.add((com.lowagie.text.Element)p.get(k)); } } } return doc; } public static void addEmptyRows(PdfPTable table, int rows) throws DocumentException { for (int i=0; i0?AppUtils.getRequestNvlValue(request, "multiplePieOrder").equals("row"):rr.isMultiplePieOrderByRow())) ); additionalChartOptionsMap.put("multiplePieLabelDisplay", AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay").length()>0? AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay"):rr.getMultiplePieLabelDisplay()); additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D())); } else if (chartType.equals(AppConstants.GT_BAR_3D)) { additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) ); additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer()); additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D())); additionalChartOptionsMap.put("lastSeriesALineChart", new Boolean(rr.isLastSeriesALineChart())); } else if (chartType.equals(AppConstants.GT_LINE)) { additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) ); additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D())); additionalChartOptionsMap.put("lastSeriesABarChart", new Boolean(rr.isLastSeriesABarChart())); } else if (chartType.equals(AppConstants.GT_TIME_DIFFERENCE_CHART)) { additionalChartOptionsMap.put("intervalFromDate",AppUtils.getRequestNvlValue(request, "intervalFromDate").length()>0?AppUtils.getRequestNvlValue(request, "intervalFromDate"):rr.getIntervalFromdate()); additionalChartOptionsMap.put("intervalToDate", AppUtils.getRequestNvlValue(request, "intervalToDate").length()>0? AppUtils.getRequestNvlValue(request, "intervalToDate"):rr.getIntervalTodate()); additionalChartOptionsMap.put("intervalLabel", AppUtils.getRequestNvlValue(request, "intervalLabel").length()>0? AppUtils.getRequestNvlValue(request, "intervalLabel"):rr.getIntervalLabel()); } else if (chartType.equals(AppConstants.GT_REGRESSION)) { additionalChartOptionsMap.put("regressionType",AppUtils.getRequestNvlValue(request, "regressionType").length()>0?AppUtils.getRequestNvlValue(request, "regressionType"):rr.getLinearRegression()); additionalChartOptionsMap.put("linearRegressionColor",nvl(rr.getLinearRegressionColor())); additionalChartOptionsMap.put("expRegressionColor",nvl(rr.getExponentialRegressionColor())); additionalChartOptionsMap.put("maxRegression",nvl(rr.getCustomizedRegressionPoint())); } else if (chartType.equals(AppConstants.GT_STACK_BAR) ||chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR) || chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR_LINES) || chartType.equals(AppConstants.GT_STACKED_VERT_BAR) || chartType.equals(AppConstants.GT_STACKED_VERT_BAR_LINES) ) { additionalChartOptionsMap.put("overlayItemValue",new Boolean(nvl(rr.getOverlayItemValueOnStackBar()).equals("Y"))); } additionalChartOptionsMap.put("legendPosition", nvl(rr.getLegendPosition())); additionalChartOptionsMap.put("hideToolTips", new Boolean(rr.hideChartToolTips())); additionalChartOptionsMap.put("hideLegend", new Boolean(AppUtils.getRequestNvlValue(request, "hideLegend").length()>0? AppUtils.getRequestNvlValue(request, "hideLegend").equals("Y"):rr.hideChartLegend())); additionalChartOptionsMap.put("labelAngle", nvl(rr.getLegendLabelAngle())); additionalChartOptionsMap.put("maxLabelsInDomainAxis", nvl(rr.getMaxLabelsInDomainAxis())); additionalChartOptionsMap.put("rangeAxisLowerLimit", nvl(rr.getRangeAxisLowerLimit())); additionalChartOptionsMap.put("rangeAxisUpperLimit", nvl(rr.getRangeAxisUpperLimit())); boolean totalOnChart = false; totalOnChart = AppUtils.getRequestNvlValue(request, "totalOnChart").equals("Y"); String filename = null; ArrayList graphURL = new ArrayList(); ArrayList chartNames = new ArrayList(); ArrayList fileNames = new ArrayList(); List l = rr.getAllColumns(); List lGroups = rr.getAllChartGroups(); HashMap mapYAxis = rr.getAllChartYAxis(rr.getReportParamValues()); String chartLeftAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartLeftAxisLabel())); String chartRightAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartRightAxisLabel())); int displayTotalOnChart = 0; HashMap formValues = Globals.getRequestParamtersMap(request, false); for (Iterator iterC = l.iterator(); iterC.hasNext();) { DataColumnType dc = (DataColumnType) iterC.next(); if(nvl(dc.getColName()).equals(AppConstants.RI_CHART_TOTAL_COL)) { displayTotalOnChart = 1; } } String legendColumnName = (rr.getChartLegendColumn()!=null)?rr.getChartLegendColumn().getDisplayName():"Legend Column"; if(ds!=null) { if(rr.hasSeriesColumn() && chartType.equals(AppConstants.GT_TIME_SERIES) && (lGroups==null || lGroups.size() <= 0)) { /** Check whether Report has only category columns if so then all the columns will open in seperate chart - sundar**/ for (int i=0; i0) tempChartGroupCurrent = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|")); if(i>0) tempChartGroupPrev = ((String) lGroups.get(i-1)).substring(0,((String) lGroups.get(i-1)).lastIndexOf("|")); if(tempChartGroupCurrent.equals(tempChartGroupPrev)) continue; String chartGroup = chartGroupOrg; downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png"; String chartTitle = (Globals.getDisplayChartTitle()? (chartGroup!=null && chartGroup.indexOf("|") > 0 ?chartGroup.substring(0,chartGroup.lastIndexOf("|")):rr.getReportName()):""); chartTitle = rr.getFormFieldFilled(chartTitle); String leftAxisLabel = ""; if(!rr.isMultiSeries()) { leftAxisLabel = ((chartYAxis!=null && chartYAxis.indexOf("|") > 0) ? chartYAxis.substring(0,chartYAxis.lastIndexOf("|")): chartLeftAxisLabel ); } else { leftAxisLabel = chartLeftAxisLabel; } filename = null; try { Image image = Image.getInstance(downloadFileName); images.add(image); } catch (MalformedURLException e) { logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG, e); } catch (BadElementException e) { logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG, e); } catch (FileNotFoundException e) { logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG, e); } catch (IOException e) { logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); } } if(!chartType.equals(AppConstants.GT_PIE_MULTIPLE)) { for (int i=0; i 0))) { if(/*chartType.equals(AppConstants.GT_TIME_SERIES) && */rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues)!=null && rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues).size()>0) { downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_All.png"; String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():""; chartTitle = rr.getFormFieldFilled(chartTitle); filename = null; try { Image image = Image.getInstance(downloadFileName); images.add(image); } catch (MalformedURLException e) { logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG, e); } catch (BadElementException e) { logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG, e); } catch (FileNotFoundException e) { logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG, e); } catch (IOException e) { logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); } } } // Stacked Chart Check } // else no Series Column } // if(ds!=null) } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "Exception in generateNewImage", e); } return images.size()>0?images:null; } private final int DEFAULT_PDF_DISPLAY_WIDTH = 10; private int paintPdfData(final HttpServletRequest request, final Document document, final ReportData rd, final ReportRuntime rr, final String sql_whole) throws DocumentException, RaptorException, IOException { final int mb = 1024 * 1024; final Runtime runtime = Runtime.getRuntime(); int returnValue = 0; final float f[] = getRelativeWidths(rd, AppConstants.RT_CROSSTAB.equals(rr.getReportType())); PdfPTable table = new PdfPTable(f); table.setWidthPercentage(100f); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM); final ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID()); final List allColumns = rdef.getAllColumns(); final float[] repotWidths = new float[rdef.getVisibleColumnCount()]; int columnIdx = 0; float pdfDisplayWidth = 0; for (final Iterator iter = allColumns.iterator(); iter.hasNext(); ) { final DataColumnType dct = (DataColumnType) iter.next(); if (dct.isVisible()) { if (dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().isEmpty() || dct .getPdfDisplayWidthInPxls().startsWith("null")) { pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH; } else { pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls()); } repotWidths[columnIdx++] = pdfDisplayWidth; } } table.setWidths(repotWidths); //TODO: check title and subtitle final HttpSession session = request.getSession(); final String drilldown_index = (String) session.getAttribute("drilldown_index"); int index = 0; try { index = Integer.parseInt(drilldown_index); } catch (NumberFormatException ex) { index = 0; } final String titleRep = (String) session.getAttribute("TITLE_" + index); final String subtitle = (String) session.getAttribute("SUBTITLE_" + index); if (nvl(titleRep).length() > 0 && nvl(subtitle).length() > 0) { table.setHeaderRows(3); } else if (nvl(titleRep).length() > 0) { table.setHeaderRows(2); } else { table.setHeaderRows(1); } table = paintPdfReportHeader(request, document, table, rr, f); paintPdfTableHeader(document, rd, table); int idx = 0; final int fragmentsize = 30; //for memory management rd.reportDataRows.resetNext(); DataRow dr = rd.reportDataRows.getNext(); if (nvl(sql_whole).length() > 0 && AppConstants.RT_LINEAR.equals(rr.getReportType())) { try (final Connection conn = ConnectionUtils.getConnection(rr.getDbInfo()); final Statement st = conn.createStatement(); final ResultSet rs = st.executeQuery(sql_whole);) { logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************")); logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole)); logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************")); final ResultSetMetaData rsmd = rs.getMetaData(); final int numberOfColumns = rsmd.getColumnCount(); dr = null; int rowCount = 0; while (rs.next()) { rowCount++; final Map colHash = new HashMap(); for (int i = 1; i <= numberOfColumns; i++) { colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i)); } rd.reportDataRows.resetNext(); dr = rd.reportDataRows.getNext(); for (dr.resetNext(); dr.hasNext(); ) { final DataValue dv = dr.getNext(); final String value = nvl((String) colHash.get(dv.getColId().toUpperCase())); if (dv.isVisible()) { final HtmlFormatter cfmt = dv.getCellFormatter(); final HtmlFormatter rfmt = dv.getRowFormatter(); final Font cellFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if (cfmt != null) { cellFormatterFont(cfmt, cellFont); } else if (rfmt != null) { cellFormatterFont(rfmt, cellFont); } else { if (dv.isBold()) { cellFont.setStyle(Font.BOLD); } } final String cellValue = strip.stripHtml(value.trim()); final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont)); //row background color can be overwritten by cell background color cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); if (nvl(dv.getAlignment()).trim().length() > 0) { cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); } else { cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); } if (cfmt != null) { formatterCell(cfmt, cell); } else if (rfmt != null) { formatterCell(rfmt, cell); } table.addCell(cell); }//if isVisible() } } if (rd.reportDataTotalRow != null) { for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) { dr = rd.reportDataTotalRow.getNext(); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); final Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize(FONT_SIZE + 1f); table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); table.addCell(new Paragraph("Total", rowHeaderFont)); addTotalRowColumns(table, dr, idx); if (idx % fragmentsize == fragmentsize - 1) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } } } } catch (final SQLException | ReportSQLException ex) { throw new RaptorException(ex); } catch (final Exception ex) { if (!(ex.getCause() instanceof java.net.SocketException)) { throw new RaptorException(ex); } } //document.add(table); } else { if (rr.getReportType().equals(AppConstants.RT_LINEAR)) { for (rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); idx++) { if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold() / 100)) { returnValue = 1; } dr = rd.reportDataRows.getNext(); addRowHeader(table, dr, idx, rd); addRowColumns(table, dr, idx); if (idx % fragmentsize == fragmentsize - 1) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } } if (rd.reportDataTotalRow != null) { for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) { dr = rd.reportDataTotalRow.getNext(); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize(FONT_SIZE + 1f); table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); table.addCell(new Paragraph("Total", rowHeaderFont)); addTotalRowColumns(table, dr, idx); if (idx % fragmentsize == fragmentsize - 1) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } } } } else if (AppConstants.RT_CROSSTAB.equals(rr.getReportType())) { int rowCount = 0; final List l = rd.getReportDataList(); boolean first = true; for (int dataRow = 0; dataRow < l.size(); dataRow++) { first = true; rowCount++; dr = (DataRow) l.get(dataRow); final Vector rowNames = dr.getRowValues(); for (dr.resetNext(); dr.hasNext(); ) { if (first) { HtmlFormatter rfmt = dr.getRowFormatter(); Font cellFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if (rfmt != null) { cellFormatterFont(rfmt, cellFont); } if (rowNames != null) { for (int i = 0; i < rowNames.size(); i++) { final DataValue dv = rowNames.get(i); rfmt = dr.getRowFormatter(); cellFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if (rfmt != null) { cellFormatterFont(rfmt, cellFont); } String cellValue = dv.getDisplayValue(); if (cellValue.indexOf("|#") != -1) { cellValue = cellValue.substring(0, cellValue.indexOf("|")); } final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont)); //row background color can be overwritten by cell background color cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); if (rfmt != null) { formatterCell(rfmt, cell); } table.addCell(cell); } } } first = false; if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold() / 100)) { returnValue = 1; } //addRowHeader(table,dr,idx,rd); addRowColumns(table, dr, idx); if (idx % fragmentsize == fragmentsize - 1) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } } } } //document.add(table); } document.add(table); paintPdfReportFooter(request, document, rr, f); return returnValue; } private void addRowHeader(PdfPTable table, DataRow dr, int idx, ReportData rd) { table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) { RowHeaderCol rhc = rd.reportRowHeaderCols.getNext(); if(idx==0) rhc.resetNext(); RowHeader rh = rhc.getNext(); //System.out.println(" =============== RowHeader\n "+rh); Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if(rh.isBold()) { rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize(FONT_SIZE+1f); } if(rh.getColSpan()>0) { table.getDefaultCell().setColspan(rh.getColSpan()); table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); table.addCell(new Paragraph(strip.stripHtml(rh.getRowTitle()),rowHeaderFont)); } } } private void addRowColumns(PdfPTable table, DataRow dr, int idx) { table.getDefaultCell().setColspan(1); for(dr.resetNext();dr.hasNext();) { DataValue dv = dr.getNext(); //System.out.println(columnCount +" --> "+dv); if(dv.isVisible()) { HtmlFormatter cfmt = dv.getCellFormatter(); HtmlFormatter rfmt = dv.getRowFormatter(); Font cellFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if(cfmt!= null) { cellFormatterFont(cfmt,cellFont); } else if(rfmt != null) { cellFormatterFont(rfmt,cellFont); } else { if(dv.isBold()) { cellFont.setStyle(Font.BOLD); } } String cellValue = strip.stripHtml(dv.getDisplayValue().trim()); PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); //row background color can be overwritten by cell background color cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); if(nvl(dv.getAlignment()).trim().length()>0) cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); else cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); if(cfmt!= null) { formatterCell(cfmt,cell); } else if(rfmt != null) { formatterCell(rfmt,cell); } table.addCell(cell); }//if isVisible() } } private void addTotalRowColumns(PdfPTable table, DataRow dr, int idx) { table.getDefaultCell().setColspan(1); dr.resetNext(); dr.getNext(); for(;dr.hasNext();) { DataValue dv = dr.getNext(); //System.out.println(columnCount +" --> "+dv); if(dv.isVisible()) { HtmlFormatter cfmt = dv.getCellFormatter(); HtmlFormatter rfmt = dv.getRowFormatter(); Font cellFont = FontFactory.getFont(FONT_FAMILY, FONT_SIZE, Font.NORMAL, Color.BLACK); if(cfmt!= null) { cellFormatterFont(cfmt,cellFont); } else if(rfmt != null) { cellFormatterFont(rfmt,cellFont); } else { if(dv.isBold()) { cellFont.setStyle(Font.BOLD); } } String cellValue = strip.stripHtml(dv.getDisplayValue().trim()); PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); //row background color can be overwritten by cell background color cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); if(nvl(dv.getAlignment()).trim().length()>0) cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); else cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); if(cfmt!= null) { formatterCell(cfmt,cell); } else if(rfmt != null) { formatterCell(rfmt,cell); } table.addCell(cell); }//if isVisible() } } private void formatterCell(HtmlFormatter fmt, PdfPCell cell) { if(nvl(fmt.getBgColor()).trim().length()>0) cell.setBackgroundColor(Color.decode(fmt.getBgColor())); if(nvl(fmt.getAlignment()).trim().length()>0) cell.setHorizontalAlignment(ElementTags.alignmentValue(fmt.getAlignment())); } private void cellFormatterFont(HtmlFormatter fmt, Font font) { if(fmt.isBold()) font.setStyle(Font.BOLD); if(fmt.isItalic()) font.setStyle(Font.ITALIC); if(fmt.isUnderline()) font.setStyle(Font.UNDERLINE); if(fmt.getFontColor().trim().length()>0) font.setColor(Color.decode(fmt.getFontColor())); if(fmt.getFontSize().trim().length()>0) font.setSize(Float.parseFloat(fmt.getFontSize())-Globals.getDataFontSizeOffset()); // if(fmt.getFontFace().trim().length()>0) // cellFont.setFamily() } private Color getRowBackgroundColor(DataRow dr, int idx) { Color color = Color.decode(Globals.getDataDefaultBackgroundHexCode()); HtmlFormatter rhf = dr.getRowFormatter(); if(rhf!=null && nvl(rhf.getBgColor()).trim().length()>0) color = Color.decode(rhf.getBgColor()); else if(pb.isAlternateColor() && idx%2==0) color = Color.decode(Globals.getDataBackgroundAlternateHexCode()); return color; } private int getTotalVisbleColumns(ReportData rd) { int totalVisbleColumn = rd.getTotalColumnCount(); for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();) { DataRow dr = rd.reportDataRows.getNext(); for(dr.resetNext();dr.hasNext();) { DataValue dv = dr.getNext(); if(!dv.isVisible()) totalVisbleColumn--; } break; } return totalVisbleColumn; } /* private int getFirstRowIndex(ReportRuntime rr) { return (pb.getCurrentPage()>0)?pb.getCurrentPage()*rr.getPageSize()+1 : 1; } */ private float[] getRelativeWidths(ReportData rd, boolean crosstab){ int totalColumns = getTotalVisbleColumns(rd); /*if(rd.reportTotalRowHeaderCols!=null) { totalColumns += 1; }*/ if(crosstab) { totalColumns += 1; } if(totalColumns == 0 ) totalColumns=1; float[] relativeWidths = new float[totalColumns]; //initial widths are even for(int i=0; i0) { //PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM); Font font = FontFactory.getFont(FONT_FAMILY, FONT_SIZE-2f, Font.BOLD, Color.BLACK); //addEmptyRows(table,1); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor())); title = Utils.replaceInString(title, "
", " "); title = Utils.replaceInString(title, "
", " "); title = Utils.replaceInString(title, "
", " "); title = strip.stripHtml(nvl(title).trim()); //subtitle = Utils.replaceInString(subtitle, "
", " "); //subtitle = Utils.replaceInString(subtitle, "
", " "); //subtitle = Utils.replaceInString(subtitle, "
", " "); //subtitle = strip.stripHtml(nvl(subtitle).trim()); StyleSheet styles = new StyleSheet(); HTMLWorker htmlWorker = new HTMLWorker(document); ArrayList cc = new ArrayList(); cc = htmlWorker.parseToList(new StringReader(subtitle), styles); Phrase p1 = new Phrase(); for (int i = 0; i < cc.size(); i++){ Element elem = (Element)cc.get(i); ArrayList al = elem.getChunks(); for (int j = 0; j < al.size(); j++) { Chunk chunk = (Chunk) al.get(j); chunk.font().setSize(6.0f); } p1.add(elem); } //cell = new PdfPCell(p1); StyleSheet style = new StyleSheet(); style.loadTagStyle("font", "font-size", "3"); style.loadTagStyle("font", "size", "3"); styles.loadStyle("pdfFont1", "size", "11px"); styles.loadStyle("pdfFont1", "font-size", "11px"); /*ArrayList p = HTMLWorker.parseToList(new StringReader(nvl(title)), style); for (int k = 0; k < p.size(); ++k){ document.add((com.lowagie.text.Element)p.get(k)); }*/ //p1.font().setSize(3.0f); PdfPCell titleCell = new PdfPCell(new Phrase(title, font)); titleCell.setColspan(rr.getVisibleColumnCount()); PdfPCell subtitleCell = new PdfPCell(p1); subtitleCell.setColspan(rr.getVisibleColumnCount()); titleCell.setHorizontalAlignment(1); subtitleCell.setHorizontalAlignment(1); table.addCell(titleCell); table.addCell(subtitleCell); //document.add(table); } return table; } private void paintPdfReportFooter(HttpServletRequest request, Document document, ReportRuntime rr, float[] f) throws DocumentException, IOException { HttpSession session = request.getSession(); String drilldown_index = (String) session.getAttribute("drilldown_index"); int index = 0; try { index = Integer.parseInt(drilldown_index); } catch (NumberFormatException ex) { index = 0; } String title = (String) session.getAttribute("FOOTER_"+index); if(nvl(title).length()>0) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM); Font font = FontFactory.getFont(FONT_FAMILY, FONT_SIZE-3f, Font.BOLD, Color.BLACK); //addEmptyRows(table,1); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor())); /*title = Utils.replaceInString(title, "
", " "); title = Utils.replaceInString(title, "
", " "); title = Utils.replaceInString(title, "
", " "); title = strip.stripHtml(nvl(title).trim());*/ StyleSheet style = new StyleSheet(); HTMLWorker htmlWorker = new HTMLWorker(document); ArrayList cc = new ArrayList(); cc = htmlWorker.parseToList(new StringReader(title), style); Phrase p1 = new Phrase(); for (int i = 0; i < cc.size(); i++){ Element elem = (Element)cc.get(i); ArrayList al = elem.getChunks(); for (int j = 0; j < al.size(); j++) { Chunk chunk = (Chunk) al.get(j); chunk.font().setSize(6.0f); } p1.add(elem); } /* HTMLWorker.parseToList(new StringReader(nvl(title)), style);*/ PdfPCell titleCell = new PdfPCell(p1); titleCell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(titleCell); //table. document.add(table); } //return table; } private void paintPdfTableHeader(Document document, ReportData rd, PdfPTable table) throws DocumentException { Font font = FontFactory.getFont(FONT_FAMILY, FONT_SIZE+1f, Font.BOLD, Color.decode(Globals.getDataTableHeaderFontColor())); //table.setHeaderRows(1); table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor())); String title = ""; boolean firstPass = true; /*if(rd.reportTotalRowHeaderCols!=null) { if(firstPass) { table.addCell(new Paragraph("No.", font)); firstPass = false; } }*/ for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();) { if(firstPass) { for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) { /*if(firstPass) { table.addCell(new Paragraph("No.", font)); firstPass = false; } else {*/ RowHeaderCol rhc = rd.reportRowHeaderCols.getNext(); title = rhc.getColumnTitle(); title = Utils.replaceInString(title,"_nl_", " \n"); table.addCell(new Paragraph(title,font)); //} } } ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext(); for (chr.resetNext(); chr.hasNext();) { ColumnHeader ch = chr.getNext(); //System.out.println(ch); if(ch.isVisible()) { title = ch.getColumnTitle(); title = Utils.replaceInString(title,"_nl_", " \n"); table.addCell(new Paragraph(title,font)); } } } } public static String currentTime(String pattern) { try { SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss"); Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime()); SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern()); return dtimestamp.format(sysdate)+" "+Globals.getTimeZone(); //paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone())); } catch(Exception ex) {} SimpleDateFormat s = new SimpleDateFormat(pattern); s.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone())); //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + Calendar.getInstance().getTime()); //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + s.format(Calendar.getInstance().getTime())); return s.format(Calendar.getInstance().getTime()); } private PdfBean preparePdfBean(HttpServletRequest request,ReportRuntime rr) { PdfBean pb = new PdfBean(); pb.setUserId(AppUtils.getUserID(request)); pb.setWhereToShowPageNumber(Globals.getPageNumberPosition()); pb.setAlternateColor(Globals.isDataAlternateColor()); pb.setTimestampPattern(Globals.getDatePattern()); int temp = -1; try { temp = Integer.parseInt(request.getParameter(AppConstants.RI_NEXT_PAGE)); } catch (NumberFormatException e) {} pb.setCurrentPage(temp); //pb.setPortrait( trueORfalse(request.getParameter("isPortrait"),true)); pb.setPortrait(trueORfalse(rr.getPDFOrientation() == "portait"?"true":"false", true)); //pb.setCoverPageIncluded( trueORfalse(request.getParameter("isCoverPageIncluded"), true)); //if(Globals.isCoverPageNeeded()) { pb.setCoverPageIncluded(Globals.isCoverPageNeeded()?rr.isPDFCoverPage():false); //} pb.setTitle(nvl(request.getParameter("title"))); pb.setPagesize(nvls(request.getParameter("pagesize"),"LETTER")); pb.setLogo1Url(rr.getPDFLogo1()); pb.setLogo2Url(rr.getPDFLogo2()); pb.setLogo1Size(rr.getPDFLogo1Size()); pb.setLogo2Size(rr.getPDFLogo2Size()); pb.setFullWebContextPath(request.getSession().getServletContext().getRealPath(File.separator)); pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart()); String id = nvl(request.getParameter("pdfAttachmentKey")).trim(); String log_id = nvl(request.getParameter("log_id")).trim(); if(id.length()>0 && log_id.length()>0) pb.setAttachmentOfEmail(true); return pb; } private boolean trueORfalse(String str) { return (str != null) && (str.equalsIgnoreCase("true")); } private boolean trueORfalse(String str,boolean b_default) { return str==null ? b_default : (str.equalsIgnoreCase("true")); } }