List of usage examples for com.lowagie.text.pdf PdfPCell setBorderColor
public void setBorderColor(Color borderColor)
From source file:com.krawler.spring.hrms.exportreport.exportAppraisalReportPDFDAOImpl.java
License:Open Source License
private ByteArrayOutputStream AppraisalDetail(HttpServletRequest request, Session session, boolean isEmm, String str, String goalstr, String quesansstr) throws JSONException, SessionExpiredException, DocumentException, ServiceException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); String[] colHeader = {//from w ww .j a v a 2 s . co m messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.cycle.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.start.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.end.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.total.appraisals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.Updates.NoofAppraisalsSubmitted", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.self.comments", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.appraiser.comments", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.competency.score", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competencies", null, RequestContextUtils.getLocale(request)) }; String[] colHeader1 = { messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.cycle.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.start.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.end.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.total.appraisals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.Updates.NoofAppraisalsSubmitted", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.appraiser.comments", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.competency.score", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competencies", null, RequestContextUtils.getLocale(request)) }; String[] colHeader2 = { messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.cycle.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.start.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraisal.end.date", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.total.appraisals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.Updates.NoofAppraisalsSubmitted", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.overall.competency.score", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competencies", null, RequestContextUtils.getLocale(request)) }; String[] dataIndex = { "empname", "appcylename", "appcylestdate", "appcylendate", "totalappraisal", "appraisalsubmitted", "empcomment", "mancom", "manavgwght", "" }; String[] dataIndex1 = { "empname", "appcylename", "appcylestdate", "appcylendate", "totalappraisal", "appraisalsubmitted", "mancom", "manavgwght", "" }; String[] dataIndex2 = { "empname", "appcylename", "appcylestdate", "appcylendate", "totalappraisal", "appraisalsubmitted", "manavgwght", "" }; String[] compHeader = { messageSource.getMessage("hrms.common.name", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.description", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.appraisal.score", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.appraisal.comment", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.competency.score", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comments", null, RequestContextUtils.getLocale(request)) }; String[] compDataIndex = { "comptename", "comptdesc", "selfcompscore", "selfcomment", "compmanwght" }; String[] compGoalHeader = { messageSource.getMessage("hrms.performance.goals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.assigned.by", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comment", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.comments", null, RequestContextUtils.getLocale(request)) }; String[] compGoalDataIndex = { "gname", "assignedby", "gmanrat", "mangoalcomment", "gemprat", "empgoalcomment" }; String[] quesAnsHeader1 = { messageSource.getMessage("hrms.performance.Questions", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.response", null, RequestContextUtils.getLocale(request)) }; String[] quesAnsHeader = { messageSource.getMessage("hrms.performance.Questions", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.response", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.response", null, RequestContextUtils.getLocale(request)) }; String[] quesAnsDataIndex = { hrmsAnonymousAppraisalConstants.question, hrmsAnonymousAppraisalConstants.answer, hrmsAnonymousAppraisalConstants.employeeanswer }; String[] quesAnsDataIndex1 = { hrmsAnonymousAppraisalConstants.question, hrmsAnonymousAppraisalConstants.answer }; String managerComments = ""; String scoreAvg = ""; String companyid = null; PdfWriter writer = null; try { String usID = request.getParameter("userid"); String self = request.getParameter("self"); Boolean removecolumn = false; if (!StringUtil.isNullOrEmpty(self) && self.equals("false")) { quesAnsHeader = quesAnsHeader1; quesAnsDataIndex = quesAnsDataIndex1; colHeader = colHeader1; dataIndex = dataIndex1; removecolumn = true; } if (StringUtil.isNullOrEmpty(usID)) { usID = sessionHandlerImplObj.getUserid(request); } if (StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) companyid = sessionHandlerImplObj.getCompanyid(request); else { User u = (User) hibernateTemplate.get(User.class, usID); companyid = u.getCompany().getCompanyID(); } HashMap<String, Object> requestParams = new HashMap<String, Object>(); // companyid = sessionHandlerImplObj.getCompanyid(request); requestParams.put("companyid", companyid); requestParams.put("checklink", "appraisal"); if (!hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { quesAnsHeader = quesAnsHeader1; quesAnsDataIndex = quesAnsDataIndex1; colHeader = colHeader1; removecolumn = true; } requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("checklink", "overallcomments"); if (!hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { colHeader = colHeader2; dataIndex = dataIndex2; } requestParams.clear(); Document document = new Document(PageSize.A4.rotate(), 25, 25, 25, 25); writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage()); document.open(); java.awt.Color tColor = new Color(9, 9, 9); //fontSmallBold.setColor(tColor); Paragraph p = new Paragraph(); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new float[] { 55, 75 }); PdfPTable mainTable = new PdfPTable(1); mainTable.setTotalWidth(90); mainTable.setWidthPercentage(100); mainTable.setSpacingBefore(20); PdfPCell headcell = null; headcell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.appraisal.details", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_HELVETICA, tColor))); headcell.setBackgroundColor(new Color(0xEEEEEE)); headcell.setPadding(5); mainTable.addCell(headcell); document.add(mainTable); // String str=hrmsManager.getAppraisalReport(session, request); JSONObject jobjTemplate = new JSONObject(str); com.krawler.utils.json.base.JSONArray jarr = jobjTemplate.getJSONArray("data"); com.krawler.utils.json.base.JSONArray jarr2 = jarr.getJSONObject(0).getJSONArray("data"); JSONObject jobjAppraisal = new JSONObject(jarr2.getString(0)); jarr = jobjAppraisal.getJSONArray("competencies"); int headlen = colHeader.length; if (jarr.length() < 1) { headlen = headlen - 2; } for (int i = 0; i < headlen; i++) { PdfPCell pcell = new PdfPCell( new Paragraph(fontFamilySelector.process(colHeader[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); if (i == 0) pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(pcell); if (!dataIndex[i].equals("mancom")) { pcell = new PdfPCell(new Paragraph(fontFamilySelector.process(!dataIndex[i].equals("") ? !jobjAppraisal.isNull(dataIndex[i]) ? jobjAppraisal.getString(dataIndex[i]) : "" : "", FontContext.SMALL_NORMAL_HELVETICA))); if (i == 0) pcell.setPaddingTop(10); pcell.setBorder(0); pcell.setPaddingLeft(10); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(pcell); } else { if (!jobjAppraisal.isNull(dataIndex[i])) { JSONArray spl = new JSONArray(jobjAppraisal.getString(dataIndex[i])); String strData = ""; for (int counter = 0; counter < spl.length(); counter++) { strData += spl.getString(counter) + "\n"; } pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(strData, FontContext.SMALL_NORMAL_HELVETICA))); if (i == 0) pcell.setPaddingTop(10); pcell.setBorder(0); pcell.setPaddingLeft(10); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(pcell); } } } document.add(table); PdfPTable quesansTable = new PdfPTable(quesAnsHeader.length); quesansTable.setWidthPercentage(100); if (removecolumn) { quesansTable.setWidths(new float[] { 40, 40 }); } else { quesansTable.setWidths(new float[] { 40, 40, 40 }); } quesansTable.setSpacingBefore(20); quesansTable.setHeaderRows(1); for (int i = 0; i < quesAnsHeader.length; i++) { PdfPCell pgcell = new PdfPCell(new Paragraph( fontFamilySelector.process(quesAnsHeader[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); quesansTable.addCell(pgcell); } JSONObject quesansjobj = new JSONObject(quesansstr); JSONArray quesansjarr = quesansjobj.getJSONArray("quesans"); JSONObject qajobj = new JSONObject(); for (int i = 0; i < quesansjarr.length(); i++) { qajobj = quesansjarr.getJSONObject(i); for (int k = 0; k < quesAnsHeader.length; k++) { String qatext = !qajobj.isNull(quesAnsDataIndex[k]) ? qajobj.getString(quesAnsDataIndex[k]) : ""; qatext = qatext.replaceAll("~", "\n\n"); qatext = qatext.replaceAll("\n", "<br/>"); StyleSheet st = new StyleSheet(); st.loadTagStyle("body", "face", "HELVETICA"); st.loadTagStyle("body", "size", "1"); st.loadTagStyle("body", "leading", "8,0"); StringReader stringReader = new StringReader(qatext); PdfPCell pcell = new PdfPCell(); ArrayList listStr = HTMLWorker.parseToList(stringReader, st); pcell.setPadding(4); for (int htmlCount = 0; htmlCount < listStr.size(); ++htmlCount) { if (!listStr.get(htmlCount).toString().equals("[]")) pcell.addElement((Element) listStr.get(htmlCount)); } pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_CENTER); quesansTable.addCell(pcell); } } document.add(quesansTable); PdfPTable compTable = new PdfPTable(6); compTable.setWidthPercentage(100); compTable.setWidths(new float[] { 50, 60, 30, 50, 42, 70 }); compTable.setSpacingBefore(20); compTable.setHeaderRows(1); for (int i = 0; i < compHeader.length; i++) { PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(compHeader[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setBorder(PdfPCell.BOX); pcell.setPadding(4); pcell.setBorderColor(Color.GRAY); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); compTable.addCell(pcell); } for (int i = 0; i < jarr.length(); i++) { jobjAppraisal = jarr.getJSONObject(i); for (int k = 0; k < compHeader.length; k++) { if (k != compHeader.length - 1) { scoreAvg = ""; if (!jobjAppraisal.isNull(compDataIndex[k]) && compDataIndex[k].equals("compmanwght")) { scoreAvg = jobjAppraisal.getString("nominalRat"); Chunk chunk1 = fontFamilySelector.processChunk( jobjAppraisal.getString(compDataIndex[k]) + "\n\n", FontContext.SMALL_NORMAL_HELVETICA); Chunk chunk2 = null; requestParams.clear(); if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) { // User user=(User)session.get(User.class,request.getParameter("userid")); // companyid=user.getCompany().getCompanyID(); requestParams.put("companyid", companyid); requestParams.put("checklink", "modaverage"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { chunk2 = fontFamilySelector.processChunk("[" + messageSource.getMessage("hrms.performance.mod.avg", null, RequestContextUtils.getLocale(request)) + ": " + scoreAvg + " ]", FontContext.SMALL_NORMAL_HELVETICA); } else { chunk2 = fontFamilySelector.processChunk("[" + messageSource.getMessage("hrms.performance.avg", null, RequestContextUtils.getLocale(request)) + ": " + scoreAvg + " ]", FontContext.SMALL_NORMAL_HELVETICA); } } else { requestParams.put("companyid", companyid); requestParams.put("checklink", "modaverage"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { chunk2 = fontFamilySelector.processChunk("[" + messageSource.getMessage("hrms.performance.mod.avg", null, RequestContextUtils.getLocale(request)) + ": " + scoreAvg + " ]", FontContext.SMALL_NORMAL_HELVETICA); } else { chunk2 = fontFamilySelector.processChunk("[" + messageSource.getMessage("hrms.performance.avg", null, RequestContextUtils.getLocale(request)) + ": " + scoreAvg + " ]", FontContext.SMALL_NORMAL_HELVETICA); } } Phrase phrase1 = new Phrase(); phrase1.add(chunk1); phrase1.add(chunk2); p = new Paragraph(); p.add(phrase1); } PdfPCell pcell = new PdfPCell(); if (!scoreAvg.equals("")) { pcell = new PdfPCell(new Paragraph(p)); pcell.setPadding(0); pcell.setPaddingTop(2); pcell.setPaddingBottom(4); } else { if (!jobjAppraisal.isNull(compDataIndex[k])) { String htmlStr = jobjAppraisal.getString(compDataIndex[k]); htmlStr = htmlStr.replaceAll("\n", "<br>"); StyleSheet st = new StyleSheet(); st.loadTagStyle("body", "face", "HELVETICA"); st.loadTagStyle("body", "size", "1"); st.loadTagStyle("body", "leading", "8,0"); HTMLWorker worker = new HTMLWorker(document); StringReader stringReader = new StringReader(htmlStr); ArrayList<Element> listStr = HTMLWorker.parseToList(stringReader, st); pcell.setPadding(4); for (int htmlCount = 0; htmlCount < listStr.size(); ++htmlCount) { if (!listStr.get(htmlCount).getChunks().isEmpty()) { pcell.addElement(fontFamilySelector.processElement( listStr.get(htmlCount).getChunks(), FontContext.SMALL_NORMAL_HELVETICA)); } } } else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( !jobjAppraisal.isNull(compDataIndex[k]) ? StringUtil .serverHTMLStripper(jobjAppraisal.getString(compDataIndex[k])) : "", FontContext.SMALL_NORMAL_HELVETICA))); } pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setHorizontalAlignment( compDataIndex[k].equals("comptename") || compDataIndex[k].equals("comptdesc") || compDataIndex[k].equals("selfcomment") ? Element.ALIGN_LEFT : Element.ALIGN_CENTER); pcell.setVerticalAlignment( compDataIndex[k].equals("comptdesc") || compDataIndex[k].equals("comptdesc") || compDataIndex[k].equals("selfcomment") ? Element.ALIGN_LEFT : Element.ALIGN_CENTER); compTable.addCell(pcell); } else { jarr2 = jobjAppraisal.getJSONArray("comments"); managerComments = ""; int commentCount = 1; for (int j = jarr2.length() - 1; j >= 0; j--) { jobjTemplate = jarr2.getJSONObject(j); managerComments += commentCount + ") " + jobjTemplate.getString("managercomment") + "\n\n"; commentCount++; } PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(managerComments, FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setPadding(4); pcell.setBorderColor(Color.GRAY); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); compTable.addCell(pcell); } } } document.add(compTable); PdfPCell pcell; if (jarr.length() > 0) { PdfPTable helpTable = new PdfPTable(1); helpTable.setTotalWidth(90); helpTable.setWidthPercentage(100); helpTable.setSpacingBefore(20); pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.mod.avg", null, RequestContextUtils.getLocale(request)) + ". : " + messageSource.getMessage("hrms.performance.mode.average.ratings", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); helpTable.addCell(pcell); requestParams.clear(); requestParams.put("companyid", companyid); requestParams.put("checklink", "modaverage"); if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) { if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { document.add(helpTable); } } else { if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { document.add(helpTable); } } } PdfPTable compgTable = new PdfPTable(6); compgTable.setWidthPercentage(100); compgTable.setWidths(new float[] { 50, 60, 30, 50, 42, 70 }); compgTable.setSpacingBefore(20); compgTable.setHeaderRows(1); for (int i = 0; i < compGoalHeader.length; i++) { PdfPCell pgcell = new PdfPCell(new Paragraph( fontFamilySelector.process(compGoalHeader[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); compgTable.addCell(pgcell); } JSONObject jobjTemplates = new JSONObject(goalstr); com.krawler.utils.json.base.JSONArray jarr11 = jobjTemplates.getJSONArray("data"); JSONObject jobjl = new JSONObject(); for (int i = 0; i < jarr11.length(); i++) { jobjl = jarr11.getJSONObject(i); for (int k = 0; k < compHeader.length; k++) { pcell = new PdfPCell( new Paragraph( fontFamilySelector.process( !jobjl.isNull(compGoalDataIndex[k]) ? StringUtil .serverHTMLStripper(jobjl.getString(compGoalDataIndex[k])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); compgTable.addCell(pcell); } } document.add(compgTable); document.newPage(); document.close(); } catch (DocumentException ex) { ex.printStackTrace(); throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", ex); } catch (JSONException e) { e.printStackTrace(); throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", e); } catch (Exception ex) { ex.printStackTrace(); throw ServiceException.FAILURE(ex.getMessage(), ex); } finally { writer.close(); } return baos; }
From source file:com.krawler.spring.hrms.printreport.PrintAppraisalReportDAOImp.java
License:Open Source License
public void createPDFPriview(HttpServletRequest request, HttpServletResponse response, JSONArray obj, Map<String, String> personalData) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4.rotate(), 25, 25, 25, 25); PdfWriter writer = null;/*from w ww . j a va 2s.com*/ try { HashMap<String, Object> requestParams = new HashMap<String, Object>(); boolean isQuestion = request.getParameter("question").equals("true") ? true : false; boolean promotion = request.getParameter("promotion").equals("false") ? false : true; Boolean isMyAppraisal = Boolean.parseBoolean(personalData.get("isMyAppraisal")); CompanyPreferences companyPreferences = (CompanyPreferences) hibernateTemplate .get(CompanyPreferences.class, sessionHandlerImplObj.getCompanyid(request)); writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage()); document.open(); java.awt.Color tColor = new Color(9, 9, 9); //fontSmallBold.setColor(tColor); //heading PdfPTable headTable = new PdfPTable(1); headTable.setTotalWidth(90); headTable.setWidthPercentage(100); headTable.setSpacingBefore(20); PdfPCell headcell = new PdfPCell( new Paragraph(fontFamilySelector.process(messageSource.getMessage("hrms.common.AppraisalForm", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_HELVETICA))); headcell.setBackgroundColor(new Color(0xEEEEEE)); headcell.setPadding(5); headTable.addCell(headcell); document.add(headTable); //heading //Details int flag = 0; String appDetailsParam[] = { messageSource.getMessage("hrms.performance.appraisal.cycle.name", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.appraisal.cycle.period", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.Masters.Designation", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.performance.rating", null, RequestContextUtils.getLocale(request)) + "*: " }; String appDetailsValue[] = { personalData.get("appcycname"), personalData.get("empname"), messageSource.getMessage("hrms.common.form", null, RequestContextUtils.getLocale(request)) + ": " + personalData.get("startdate") + " " + messageSource.getMessage("hrms.common.to", null, RequestContextUtils.getLocale(request)) + ": " + personalData.get("enddate"), personalData.get("desgname"), personalData.get("performance") }; requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "promotion"); if (!hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { flag = 1; } PdfPTable appDetailsTable = new PdfPTable(2); appDetailsTable.setWidthPercentage(100); appDetailsTable.setWidths(new float[] { 55, 75 }); if (isMyAppraisal) { flag = 1; } for (int i = 0; i < (appDetailsParam.length - flag); i++) { PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(appDetailsParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph( fontFamilySelector.process(appDetailsValue[i], FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "overallcomments"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( (isMyAppraisal ? messageSource.getMessage("hrms.performance.self.overall.comment", null, RequestContextUtils.getLocale(request)) + ": " : messageSource.getMessage("hrms.performance.overall.appraiser.comments", null, RequestContextUtils.getLocale(request)) + ": "), FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( (isMyAppraisal ? personalData.get("selfcomment") : personalData.get("empcomment")), FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "promotion"); if (!isMyAppraisal && hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.promotion.recommendation", null, RequestContextUtils.getLocale(request)) + ": ", FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( (promotion ? messageSource.getMessage("hrms.MasterData.Yes", null, RequestContextUtils.getLocale(request)) : messageSource.getMessage("hrms.MasterData.No", null, RequestContextUtils.getLocale(request))), FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } if (promotion && !isMyAppraisal && hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { String[] appDetaisPromotionParam = { messageSource.getMessage("hrms.performance.new.department", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.new.designation", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.salary.increment", null, RequestContextUtils.getLocale(request)) + "(%): " }; String[] appDetaisPromotionValue = { personalData.get("newDept") != null ? personalData.get("newDept") : "", personalData.get("newDesig") != null ? personalData.get("newDesig") : "", personalData.get("salInc") != null ? personalData.get("salInc") : "" }; for (int i = 0; i < appDetaisPromotionParam.length; i++) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector .process(appDetaisPromotionParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process(appDetaisPromotionValue[i], FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } } document.add(appDetailsTable); //Details //Comp requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "competency"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { try { if (!isQuestion) { JSONArray jsonComp = obj.getJSONArray(0); if (!isMyAppraisal) { String[] compParam = { messageSource.getMessage("hrms.performance.competency", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competency.description", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comment", null, RequestContextUtils.getLocale(request)) }; String[] colParam = { "cmptname", "cmptdesc", "cmptwt", "manrat", "mancompcomment" }; PdfPTable questionTable = null; if (companyPreferences.isWeightage()) { questionTable = new PdfPTable(5); questionTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { questionTable = new PdfPTable(4); questionTable.setWidths(new float[] { 50, 60, 30, 42 }); } questionTable.setWidthPercentage(100); questionTable.setSpacingBefore(20); questionTable.setHeaderRows(1); for (int i = 0; i < compParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(compParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pgcell); } } for (int i = 0; i < jsonComp.length(); i++) { for (int j = 0; j < colParam.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell = null; if (j != 3) pcell = new PdfPCell( new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? jsonComp .getJSONObject(i).getString(colParam[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else { pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? (jsonComp.getJSONObject(i).getString(colParam[j]) .equals("0") ? "" : jsonComp.getJSONObject(i) .getString(colParam[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); } pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pcell); } } } document.add(questionTable); } else { String[] compParam = { messageSource.getMessage("hrms.performance.competency", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competency.description", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.comments", null, RequestContextUtils.getLocale(request)) }; String[] colParam = { "cmptname", "cmptdesc", "cmptwt", "emprat", "empcompcomment" }; PdfPTable questionTable = null; if (companyPreferences.isWeightage()) { questionTable = new PdfPTable(5); questionTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { questionTable = new PdfPTable(4); questionTable.setWidths(new float[] { 50, 60, 30, 42 }); } questionTable.setWidthPercentage(100); questionTable.setSpacingBefore(20); questionTable.setHeaderRows(1); for (int i = 0; i < compParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(compParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pgcell); } } for (int i = 0; i < jsonComp.length(); i++) { for (int j = 0; j < colParam.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? jsonComp .getJSONObject(i).getString(colParam[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? (jsonComp.getJSONObject(i).getString(colParam[j]) .equals("0") ? "" : jsonComp.getJSONObject(i) .getString(colParam[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pcell); } } } document.add(questionTable); } } else {//Questions try { JSONArray jsonQues = obj.getJSONArray(1); JSONArray jsonAnsTemp = obj.getJSONArray(2); JSONArray jsonAns = new JSONArray(); PdfPTable quesMainTable = new PdfPTable(1); quesMainTable.setTotalWidth(90); quesMainTable.setWidthPercentage(100); quesMainTable.setSpacingBefore(20); quesMainTable.setSkipFirstHeader(true); PdfPCell quesHeadcell = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.qualitative.appraisal", null, RequestContextUtils.getLocale(request)), FontContext.MEDIUM_BOLD_HELVETICA))); quesHeadcell.setPadding(5); quesMainTable.addCell(quesHeadcell); document.add(quesMainTable); PdfPTable[] quesTable = new PdfPTable[jsonQues.length()]; try { for (int i = 0; i < jsonQues.length(); i++) { String qid = (String) jsonQues.getJSONObject(i).get("qdescription"); for (int j = 0; j < jsonAnsTemp.length(); j++) { try { if (qid.equals((String) jsonAnsTemp.getJSONObject(j).get("question"))) { jsonAns.put(jsonAnsTemp.getJSONObject(j)); break; } } catch (JSONException e) { jsonAns.put(""); } } } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < jsonQues.length(); i++) { quesTable[i] = new PdfPTable(2); quesTable[i].setWidthPercentage(90); quesTable[i].setWidths(new float[] { 10, 80 }); quesTable[i].setSpacingBefore(20); quesTable[i].setHeaderRows(1); PdfPCell pgcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.que", null, RequestContextUtils.getLocale(request)) + ".", FontContext.SMALL_NORMAL_HELVETICA))); pgcell1.setBorder(0); pgcell1.setBorder(PdfPCell.BOX); pgcell1.setPadding(4); pgcell1.setHorizontalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pgcell1); PdfPCell pgcell2 = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonQues.getJSONObject(i).has("qdesc") ? jsonQues .getJSONObject(i).getString("qdesc") : "", FontContext.SMALL_NORMAL_HELVETICA))); pgcell2.setBorder(0); pgcell2.setBorder(PdfPCell.BOX); pgcell2.setPadding(4); pgcell2.setHorizontalAlignment(Element.ALIGN_LEFT); quesTable[i].addCell(pgcell2); int cnt = 0; try { cnt = jsonQues.getJSONObject(i).has("qans") ? Integer.parseInt(jsonQues.getJSONObject(i).getString("qans")) : 0; } catch (NumberFormatException e) { e.printStackTrace(); } if (jsonAns.length() > 0) { JSONArray arr = jsonAns.getJSONObject(i).getJSONArray("answer"); for (int j = 0; j < arr.length(); j++) { PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process((j + 1) + "", FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell1.setBorderColor(Color.GRAY); pcell1.setPadding(4); pcell1.setHorizontalAlignment(Element.ALIGN_CENTER); pcell1.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell1); PdfPCell pcell2 = new PdfPCell(new Paragraph(fontFamilySelector.process( arr.getJSONObject(j).getString("" + j + ""), FontContext.SMALL_NORMAL_HELVETICA))); pcell2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell2.setBorderColor(Color.GRAY); pcell2.setPadding(4); pcell2.setHorizontalAlignment(Element.ALIGN_LEFT); pcell2.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell2); } } else { for (int j = 0; j < cnt; j++) { PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process((j + 1) + "", FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell1.setBorderColor(Color.GRAY); pcell1.setPadding(4); pcell1.setHorizontalAlignment(Element.ALIGN_CENTER); pcell1.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell1); PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell); } } PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); //questionTable.addCell(pcell); document.add(quesTable[i]); } //document.add(questionTable); } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } } //Comp //Goals requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "goal"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { try { JSONArray jsonGoals = obj.getJSONArray(3); if (!isMyAppraisal) { String goalParam[] = { messageSource.getMessage("hrms.performance.goals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.percent.completed", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.goal.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comment", null, RequestContextUtils.getLocale(request)) }; String colHeader[] = { "gname", "gcomplete", "gwth", "gmanrat", "mangoalcomment" }; PdfPTable goalTable = null; if (companyPreferences.isWeightage()) { goalTable = new PdfPTable(5); goalTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { goalTable = new PdfPTable(4); goalTable.setWidths(new float[] { 50, 60, 30, 42 }); } goalTable.setWidthPercentage(100); goalTable.setSpacingBefore(20); goalTable.setHeaderRows(1); for (int i = 0; i < goalParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(goalParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pgcell); } } for (int i = 0; i < jsonGoals.length(); i++) { for (int j = 0; j < colHeader.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? jsonGoals.getJSONObject(i) .getString(colHeader[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? (jsonGoals.getJSONObject(i).getString(colHeader[j]) .equals("0") ? "" : jsonGoals.getJSONObject(i) .getString(colHeader[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pcell); } } } document.add(goalTable); } else { String goalParam[] = { messageSource.getMessage("hrms.performance.goals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.percent.completed", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.goal.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.comments", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.assigned.by", null, RequestContextUtils.getLocale(request)) }; String colHeader[] = { "gname", "gcomplete", "gwth", "gemprat", "empgoalcomment", "assignedby" }; PdfPTable goalTable = null; if (companyPreferences.isWeightage()) { goalTable = new PdfPTable(6); goalTable.setWidths(new float[] { 50, 60, 30, 50, 42, 60 }); } else { goalTable = new PdfPTable(5); goalTable.setWidths(new float[] { 50, 60, 50, 42, 60 }); } goalTable.setWidthPercentage(100); goalTable.setSpacingBefore(20); goalTable.setHeaderRows(1); for (int i = 0; i < goalParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(goalParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pgcell); } } for (int i = 0; i < jsonGoals.length(); i++) { for (int j = 0; j < colHeader.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? jsonGoals.getJSONObject(i) .getString(colHeader[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? (jsonGoals.getJSONObject(i).getString(colHeader[j]) .equals("0") ? "" : jsonGoals.getJSONObject(i) .getString(colHeader[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pcell); } } } document.add(goalTable); } } catch (JSONException e) { e.printStackTrace(); } } //Goals document.newPage(); document.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "App_Form" + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { writer.close(); } }
From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {/* w ww . j a v a 2 s .c om*/ DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.DELIVERED_QUANTITY) && columnsName.indexOf(DeliveredProductFields.DELIVERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell(new Phrase( numberService.format(deliveryPricesAndQuantities.getDeliveredCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.TOTAL_PRICE) && columnsName.indexOf(DeliveredProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getDeliveredTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {/*from w w w . j a v a 2 s .co m*/ DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(OrderedProductFields.TOTAL_PRICE) && columnsName.indexOf(OrderedProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Performs the appropriate action necessary when starting a new page. In * this case, we will write the SLAMD header to the top of the page. * * @param writer The writer used to write the PDF document. * @param document The PDF document being written. *//* w w w. ja va 2 s.com*/ public void onStartPage(PdfWriter writer, Document document) { try { PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); PdfPCell blueCell = new PdfPCell(new Phrase(" \n ")); blueCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); blueCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); blueCell.setBackgroundColor(new Color(0x59, 0x4F, 0xBF)); blueCell.setBorderWidth(inchesToPoints(1.0 / 16)); blueCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); blueCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(blueCell); Phrase titlePhrase = new Phrase("SLAMD Generated Report", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0x59, 0x4F, 0xBF))); PdfPCell yellowCell = new PdfPCell(titlePhrase); yellowCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); yellowCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); yellowCell.setBackgroundColor(new Color(0xFB, 0xE2, 0x49)); yellowCell.setBorderWidth(inchesToPoints(1.0 / 16)); yellowCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); yellowCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(yellowCell); Phrase versionPhrase = new Phrase("Version " + DynamicConstants.SLAMD_VERSION, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0xFF, 0xFF, 0xFF))); PdfPCell redCell = new PdfPCell(versionPhrase); redCell.setHorizontalAlignment(Cell.ALIGN_RIGHT); redCell.setVerticalAlignment(Cell.ALIGN_MIDDLE); redCell.setBackgroundColor(new Color(0xD1, 0x21, 0x24)); redCell.setBorderWidth(inchesToPoints(1.0 / 16)); redCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); redCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(redCell); document.add(table); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java
License:Open Source License
private void formatZelle(final int zeile, final int spalte, final PdfPCell cell) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorderColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.blue")))); if (isEvenBlockIndex(zeile, spalte)) { cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.blue")))); } else {//from w w w. ja va 2 s. c o m cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.blue")))); } cell.setBorderWidth(PdfConstants.RAHMEN_DUENN); if (BoxUtils.isFirstRowInBlock(zeile, getSudokuSize())) { cell.setBorderWidthTop(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthTop(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastColumnInRow(spalte, getSudokuSize())) { cell.setBorderWidthRight(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthRight(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastRowInColumn(zeile, getSudokuSize())) { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isFirstColumnInBlock(spalte, getSudokuSize())) { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DUENN); } cell.setFixedHeight(27f); }
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException { boolean result = false; UnitTrayLabel label = new UnitTrayLabel(); LabelEncoder encoder = new LabelEncoder(label); Image image = encoder.getImage(); int counter = 0; try {/*from w w w . ja v a 2 s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("labels.pdf")); document.setPageSize(PageSize.LETTER); document.open(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f); //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); float[] cellWidths = { 30f, 20f, 30f, 20f }; table.setWidths(cellWidths); UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle(); if (taxa == null) { taxa = uls.findAll(); } Iterator<UnitTrayLabel> i = taxa.iterator(); PdfPCell cell = null; PdfPCell cell_barcode = null; // Create two lists of 12 cells, the first 6 of each representing // the left hand column of 6 labels, the second 6 of each // representing the right hand column. // cells holds the text for each label, cells_barcode the barcode. ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12); ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12); for (int x = 0; x < 12; x++) { cells.add(null); cells_barcode.add(null); } int cellCounter = 0; while (i.hasNext()) { // Loop through all of the taxa (unit tray labels) found to print label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each taxon, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page log.debug("Label " + toPrint + " of " + label.getNumberToPrint()); cell = new PdfPCell(); cell.setBorderColor(Color.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); String higherNames = ""; if (label.getTribe().trim().length() > 0) { higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe(); } else { higherNames = label.getFamily() + ": " + label.getSubfamily(); } Paragraph higher = new Paragraph(); higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); higher.add(new Chunk(higherNames)); cell.addElement(higher); Paragraph name = new Paragraph(); Chunk genus = new Chunk(label.getGenus().trim() + " "); genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); Chunk species = new Chunk(label.getSpecificEpithet().trim()); Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>) if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) { if (label.getSpecificEpithet().startsWith("nr. ")) { normal = new Chunk("nr. "); normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); species = new Chunk(label.getSpecificEpithet().trim().substring(4)); species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } String s = ""; if (label.getSubspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim()); if (label.getSubspecificEpithet().contains(".") || label.getSubspecificEpithet().contains("[")) { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } else { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } if (label.getInfraspecificRank().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim()); infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); if (label.getInfraspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim()); infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); if (label.getUnNamedForm().trim().length() > 0) { s = " "; } else { s = ""; } Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim()); unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); name.add(genus); if (normal != null) { name.add(normal); } name.add(species); name.add(subspecies); name.add(infraRank); name.add(infra); name.add(unNamed); cell.addElement(name); Paragraph authorship = new Paragraph(); authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); if (label.getAuthorship() != null && label.getAuthorship().length() > 0) { Chunk c_authorship = new Chunk(label.getAuthorship()); authorship.add(c_authorship); } cell.addElement(authorship); //cell.addElement(new Paragraph(" ")); if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) { Paragraph drawerNumber = new Paragraph(); drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_drawerNumber = new Chunk(label.getDrawerNumber()); drawerNumber.add(c_drawerNumber); cell.addElement(drawerNumber); } else { if (label.getCollection() != null && label.getCollection().length() > 0) { Paragraph collection = new Paragraph(); collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_collection = new Chunk(label.getCollection()); collection.add(c_collection); cell.addElement(collection); } } cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(Color.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); cell_barcode.addElement(image); cells.add(cellCounter, cell); cells_barcode.add(cellCounter, cell_barcode); cellCounter++; // If we have hit a full set of 12 labels, add them to the document // in two columns, filling left column first, then right if (cellCounter == 12) { // add a page of 12 cells in columns of two. for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // Reset to begin next page cellCounter = 0; document.add(table); table = new PdfPTable(4); table.setWidthPercentage(100f); table.setWidths(cellWidths); for (int x = 0; x < 12; x++) { cells.set(x, null); cells_barcode.set(x, null); } } } // end loop through toPrint (for a taxon) counter++; } // end while results has next (for all taxa requested) // get any remaining cells in pairs for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // add any remaining cells document.add(table); try { document.close(); } catch (Exception e) { throw new PrintFailedException("No labels to print." + e.getMessage()); } // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; // Increment number printed. i = taxa.iterator(); while (i.hasNext()) { label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { label.setPrinted(label.getPrinted() + 1); } label.setNumberToPrint(0); try { uls.attachDirty(label); } catch (SaveFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("File not found."); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("Error buiding PDF document."); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } return result; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StyleUtils.java
License:Open Source License
public static void applyStyles(StyleBorder border, PdfPCell cell) { if (border == null) { return;/*from ww w .jav a2 s.com*/ } switch (border.getBorderType()) { case ALL: // border if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.TOP); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); // border-color Color color = border.getColor(); if (color != null) { cell.setBorderColor(color); } // border-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidth(width); } } break; case BOTTOM: // border-bottom if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.BOTTOM); } else { cell.enableBorderSide(PdfPCell.BOTTOM); // border-bottom-color Color color = border.getColor(); if (color != null) { cell.setBorderColorBottom(color); } // border-bottom-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthBottom(width); } } break; case LEFT: // border-left if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.LEFT); // border-left-color Color color = border.getColor(); if (color != null) { cell.setBorderColorLeft(color); } // border-left-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthLeft(width); } } break; case RIGHT: // border-right if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.RIGHT); } else { cell.enableBorderSide(PdfPCell.RIGHT); // border-right-color Color color = border.getColor(); if (color != null) { cell.setBorderColorRight(color); } // border-right-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthRight(width); } } break; case TOP: // border-top if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); } else { cell.enableBorderSide(PdfPCell.TOP); // border-top-color Color color = border.getColor(); if (color != null) { cell.setBorderColorTop(color); } // border-top-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthTop(width); } } break; } }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds the table for the crosstab/* w w w . j a v a 2s . com*/ * @param json the JSON representation of the crosstab * @param pdfDocument the pdf document that should contains the crosstab * @param numberFormat the formatter for the numbers * @throws JSONException * @throws BadElementException * @throws DocumentException */ public void export(JSONObject json, Document pdfDocument, DecimalFormat numberFormat) throws SerializationException, JSONException, BadElementException, DocumentException { logger.debug("IN: exporting the crosstab"); //prepare the crosstab for the export CrosstabExporterUtility.calculateDescendants(json); JSONObject columnsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_COLUMNS_HEADERS); JSONArray columnsRootChilds = columnsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONObject rowsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_ROWS_HEADERS); JSONArray rowsRootChilds = rowsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONArray rowHeadersDescription = json.getJSONArray(CrossTab.CROSSTAB_JSON_ROWS_HEADER_TITLE); JSONArray data = (JSONArray) json.get(CrossTab.CROSSTAB_JSON_DATA); measureMetadata = new MeasureFormatter(json, numberFormat, "##,##0.00"); this.numberFormat = numberFormat; //build the matrix for the content dataMatrix = new Vector<List<PdfPCell>>(); buildDataMatrix(data); //number of headers lavels int rowsDepth = CrosstabExporterUtility.getDepth(rowsRoot); int columnsDepth = CrosstabExporterUtility.getDepth(columnsRoot); //build the table PdfPTable table = new PdfPTable(rowsDepth + dataMatrix.get(0).size()); //build the empty cell on the top left PdfPCell topLeftCell = new PdfPCell(new Phrase("")); topLeftCell.setRowspan(columnsDepth - 1);//-1 because of the title of the rows header topLeftCell.setColspan(rowsDepth); topLeftCell.setBorderColor(Color.WHITE); table.addCell(topLeftCell); List<PdfPCell> cells = new ArrayList<PdfPCell>(); //builds the headers int dataColumnNumber = ((JSONArray) data.get(0)).length(); cells.addAll(buildColumnsHeader(columnsRootChilds, rowHeadersDescription, dataColumnNumber)); cells.addAll(buildRowsHeaders(rowsRootChilds)); logger.debug("Addign the content"); //adds the headers for (int i = 0; i < cells.size(); i++) { table.addCell(cells.get(i)); } table.setWidthPercentage(100); pdfDocument.add(table); logger.debug("IN: exported the crosstab"); }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Build the matrix for the content of the crosstab * @param data/*from ww w . ja v a 2 s.c o m*/ * @throws JSONException */ private void buildDataMatrix(JSONArray data) throws JSONException { logger.debug("IN: building the crosstab content"); PdfPCell cell; for (int i = 0; i < data.length(); i++) { JSONArray array = (JSONArray) data.get(i); List<PdfPCell> dataRow = new ArrayList<PdfPCell>(); for (int j = 0; j < array.length(); j++) { String text = (String) array.get(j); //Check if a cell is a sum if (text.length() > 5 && text.substring(0, 5).equals("[sum]")) { text = text.substring(5); cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont)); cell.setBackgroundColor(sumBackgroundColor); } else { cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont)); } cell.setBorderColor(cellsBorderColor); dataRow.add(cell); } dataMatrix.add(dataRow); } logger.debug("OUT: built the crosstab content"); }