List of usage examples for com.lowagie.text.pdf PdfPCell setVerticalAlignment
public void setVerticalAlignment(int verticalAlignment)
From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java
public String createPdf() throws IOException, DocumentException { EtiquetaConf conf = etiquetaConfDAO.getEtiquetaConfDefault(); if (hayParaImprimir() && conf != null) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); float ancho = Utilities.millimetersToPoints(conf.getAnchoHoja().floatValue()); System.out.println("Ancho: " + ancho); float largo = Utilities.millimetersToPoints(conf.getLargoHoja().floatValue()); System.out.println("Alto: " + largo); // step 1 Document document = new Document(new Rectangle(ancho, largo)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();//w ww .jav a 2s .c o m // step 4 PdfContentByte cb = writer.getDirectContent(); for (Producto p : getLista()) { if (p.getCantidadEtiquetas() > 0) { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(96); Font fontbold = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); Chunk productTitle = new Chunk("HC", fontbold); Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_LEFT); pTitile.setLeading(6, 0); PdfPCell cellTitle = new PdfPCell(); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_TOP); cellTitle.setBorder(Rectangle.NO_BORDER); cellTitle.addElement(pTitile); Font font2 = FontFactory.getFont("Times-Roman", conf.getTamDescripcion().floatValue(), Font.NORMAL); Chunk productName = new Chunk(p.getNombre(), font2); Paragraph pName = new Paragraph(productName); pName.setAlignment(Element.ALIGN_CENTER); //pTitile.setLeading(0, 1); cellTitle.addElement(pName); table.addCell(cellTitle); Barcode39 code39 = new Barcode39(); code39.setCode(p.getCodigo()); //code39.setCodeType(Barcode.EAN13); code39.setBarHeight(conf.getAltoCodBarra().floatValue()); //codeEan.setX(0.7f); code39.setSize(conf.getTamDescripcion().floatValue()); //code39.setAltText("HC - " + p.getNombre()); PdfPCell cellBarcode = new PdfPCell(); cellBarcode.setHorizontalAlignment(Element.ALIGN_CENTER); cellBarcode.setBorder(Rectangle.NO_BORDER); cellBarcode.addElement(code39.createImageWithBarcode(cb, null, Color.BLACK)); table.addCell(cellBarcode); for (int i = 0; i < p.getCantidadEtiquetas(); i++) { document.add(table); document.newPage(); } } } // step 5 document.close(); response.getOutputStream().flush(); response.getOutputStream().close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", "")); } return null; }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf footer./*from w w w . ja va2s .com*/ * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; font = getFont(); final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font)); footerCell.setHorizontalAlignment(Element.ALIGN_CENTER); footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); footerCell.setColspan(headerWidth); footerCell.setBorder(0); footerCell.setUseDescender(true); pdfPTable.addCell(footerCell); pdfPTable.setFooterRows(1); }
From source file:com.krawler.esp.servlets.AppraisalDetails.java
License:Open Source License
private ByteArrayOutputStream AppraisalDetail(HttpServletRequest request, Session session, boolean isEmm) throws JSONException, SessionExpiredException, DocumentException, ServiceException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); String[] colHeader = { "Employee Name", "Appraisal Cycle Name", "Appraisal Cycle Start Date", "Appraisal Cycle End Date", "Total No. of Appraisals", "No. of Appraisals submitted", "Overall Self Comment", "Overall Appraiser Comments", "Overall Competency Score", "Competencies" }; String[] dataIndex = { "empname", "appcylename", "appcylestdate", "appcylendate", "totalappraisal", "appraisalsubmitted", "empcomment", "mancom", "manavgwght", "" }; String[] compHeader = { "Name", "Description", "Self Appraisal Score", "Self Appraisal Comment", "Appraiser Competency Score", "Appraiser Comments" }; String[] compDataIndex = { "comptename", "comptdesc", "selfcompscore", "selfcomment", "compmanwght" }; String[] compGoalHeader = { "Goals", "Assigned By", "Appraiser Rating", "Appraiser Comment", "Self Rating", "Self Comments" }; String[] compGoalDataIndex = { "gname", "assignedby", "gmanrat", "mangoalcomment", "gemprat", "empgoalcomment" }; String managerComments = ""; String scoreAvg = ""; String companyid = null;/*from w w w. jav a2s. c o m*/ Transaction tx = null; PdfWriter writer = null; try { 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("Appraisal Details", fontHeadingMediumBold)); 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"); String goalstr = ""; User user = (User) session.get(User.class, request.getParameter("userid")); companyid = user.getCompany().getCompanyID(); if (hrmsManager.checkModule("goal", session, request, companyid)) goalstr = hrmsManager.getAppraisalReportGoalsforGrid(session, request); 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 - 1; } for (int i = 0; i < headlen; i++) { PdfPCell pcell = new PdfPCell(new Paragraph(colHeader[i], fontMediumBold)); 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(!dataIndex[i].equals("") ? !jobjAppraisal.isNull(dataIndex[i]) ? jobjAppraisal.getString(dataIndex[i]) : "" : "", fontSmallRegular)); 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])) { String[] spl = jobjAppraisal.getString(dataIndex[i]).split(","); String strData = ""; for (int counter = 0; counter < spl.length; counter++) { strData += spl[counter] + " \n"; } pcell = new PdfPCell(new Paragraph(strData, fontSmallRegular)); 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 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(compHeader[i], fontMediumBold)); 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"); Font font = new Font(Font.HELVETICA, 8, Font.BOLD, Color.BLACK); Chunk chunk1 = new Chunk(jobjAppraisal.getString(compDataIndex[k]) + "\n\n", fontSmallRegular); Chunk chunk2 = null; if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) { // user=(User)session.get(User.class,request.getParameter("userid")); // companyid=user.getCompany().getCompanyID(); if (hrmsManager.checkModule("modaverage", session, request, companyid)) { chunk2 = new Chunk("[Mod Avg: " + scoreAvg + " ]", font); } else { chunk2 = new Chunk("[Avg: " + scoreAvg + " ]", font); } } else { if (hrmsManager.checkModule("modaverage", session, request)) { chunk2 = new Chunk("[Mod Avg: " + scoreAvg + " ]", font); } else { chunk2 = new Chunk("[Avg: " + scoreAvg + " ]", font); } } 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 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)); } } else pcell = new PdfPCell(new Paragraph( !jobjAppraisal.isNull(compDataIndex[k]) ? hrmsManager.serverHTMLStripper( jobjAppraisal.getString(compDataIndex[k])) : "", fontSmallRegular)); } 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(managerComments, fontSmallRegular)); 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); } } } PdfPTable helpTable = new PdfPTable(1); helpTable.setTotalWidth(90); helpTable.setWidthPercentage(100); helpTable.setSpacingBefore(20); PdfPCell pcell = new PdfPCell(new Paragraph( "Mod Avg. : Average of ratings after excluding a minimum and a maximum rating. For e.g, mod average of 2, 3, 2, 4, 5, 3 is (2+3+4+3)/4", helpFont)); pcell.setBorder(0); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); helpTable.addCell(pcell); document.add(compTable); if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) { if (hrmsManager.checkModule("modaverage", session, request, companyid)) { document.add(helpTable); } } else { if (hrmsManager.checkModule("modaverage", session, request)) { document.add(helpTable); } } if (!StringUtil.isNullOrEmpty(goalstr)) { 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(compGoalHeader[i], fontMediumBold)); 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 < compGoalHeader.length; k++) { pcell = new PdfPCell( new Paragraph( !jobjl.isNull(compGoalDataIndex[k]) ? StringUtil .serverHTMLStripper(jobjl.getString(compGoalDataIndex[k])) : "", fontSmallRegular)); 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(); } if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) { String ipaddr = ""; if (StringUtil.isNullOrEmpty(request.getHeader("x-real-ip"))) { ipaddr = request.getRemoteAddr(); } else { ipaddr = request.getHeader("x-real-ip"); } User u = (User) session.get(User.class, request.getParameter("d")); User u1 = (User) session.get(User.class, request.getParameter("userid")); Appraisalcycle appcy = (Appraisalcycle) session.get(Appraisalcycle.class, request.getParameter("appraisalcycid")); //AuditAction action = (AuditAction) session.load(AuditAction.class, AuditAction.Appraisal_Report_Download); String details = ""; if (StringUtil.equal(request.getParameter("d"), request.getParameter("userid"))) { details = "User " + u.getFirstName() + " " + u.getLastName() + " has downloaded self" + " appraisal report for appraisal cycle " + appcy.getCyclename() + " through email link"; } else { details = "Reviewer " + u.getFirstName() + " " + u.getLastName() + " has downloaded " + u1.getFirstName() + " " + u1.getLastName() + "'s" + " appraisal report for appraisal cycle " + appcy.getCyclename() + " through email link"; } tx = session.beginTransaction(); //@@ProfileHandler.insertAuditLog(session, action, details, ipaddr, u); tx.commit(); } else { String details = ""; User u = null; String appCycleID = request.getParameter("appraisalcycid"); Appraisalcycle appcy = (Appraisalcycle) session.get(Appraisalcycle.class, appCycleID); String userID = request.getParameter("userid"); if (StringUtil.isNullOrEmpty(userID)) { userID = AuthHandler.getUserid(request); u = (User) session.get(User.class, userID); details = "User " + AuthHandler.getFullName(u) + " has downloaded self" + " appraisal report for appraisal cycle " + appcy.getCyclename() + " through Deskera HRMS"; } else { u = (User) session.get(User.class, userID); details = "Reviewer " + AuthHandler .getFullName((User) session.get(User.class, AuthHandler.getUserid(request))) + " has downloaded " + AuthHandler.getFullName(u) + "'s" + " appraisal report for appraisal cycle " + appcy.getCyclename() + " through Deskera HRMS"; } tx = session.beginTransaction(); //@@ProfileHandler.insertAuditLog(session, AuditAction.Appraisal_Report_Download,details,request); tx.commit(); } } catch (DocumentException ex) { throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", ex); } catch (JSONException e) { throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", e); } catch (Exception ex) { if (tx != null) { tx.rollback(); } throw ServiceException.FAILURE(ex.getMessage(), ex); } finally { writer.close(); } return baos; }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, Document document) throws JSONException, DocumentException { java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); fontSmallBold.setColor(tColor);/*from w w w . j a v a 2s . co m*/ com.krawler.utils.json.base.JSONObject colWidth = config.getJSONObject("colWidth"); JSONArray widths = colWidth.getJSONArray("data"); ArrayList arr = new ArrayList(); PdfPTable table; float[] f = new float[widths.length() + 1];//[(stpcol - stcol) + 1]; float[] tcol = new float[(stpcol - stcol) + 1]; if (widths.length() == 0) { f[0] = 10; for (int k = 1; k < f.length; k++) { f[k] = 20; } tcol[0] = 10; } else { for (int i = 0; i < widths.length(); i++) { JSONObject temp = widths.getJSONObject(i); arr.add(temp.getInt("width")); } f[0] = 30; for (int k = 1; k < f.length; k++) { if (!config.getBoolean("landscape") && (Integer) arr.get(k - 1) > 550) { f[k] = 550; } else { f[k] = (Integer) arr.get(k - 1); } } // table = new PdfPTable(f); // table.setTotalWidth(90); // table.setWidthPercentage(f,document.getPageSize()); tcol[0] = 30; } int i = 1; for (int k = stcol; k < stpcol; k++) { tcol[i] = f[k + 1]; i++; } table = new PdfPTable(tcol); table.setTotalWidth(90); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor); PdfPCell h2 = new PdfPCell(new Paragraph("No.", fontSmallBold)); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); int stpcol1 = 0; for (int hcol = stcol; hcol < stpcol; hcol++) { PdfPCell h1 = new PdfPCell(new Paragraph(colHeader[hcol], fontSmallBold)); h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell(new Paragraph(String.valueOf(row + 1), f1)); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); for (int col = stcol; col < stpcol; col++) { Paragraph para = null; if (store.getJSONObject(row).has(colwidth2[col])) para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1); else para = new Paragraph("", f1); // Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1); PdfPCell h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h1); } } document.add(table); document.newPage(); /* add instance of OnStartPage*/ if (widths.length() != 0) { if (stpcol != colwidth2.length) { float twidth = 0; stpcol1 = stpcol; int docwidth; if (config.getBoolean("landscape")) docwidth = 800; else docwidth = 600; while (twidth < docwidth && stpcol1 < f.length) { twidth += f[stpcol1]; stpcol1++; } stpcol1--; addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document); } } else { if (stpcol != colwidth2.length) { if ((colwidth2.length - stpcol) > showColumns) { // column limit stpcol1 = stpcol + 5; } else { stpcol1 = (colwidth2.length - stpcol) + stpcol; } addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document); } } return stpcol; }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private int addTableTimeLine(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, int maxlevel, Document document) throws JSONException, DocumentException { float[] f = new float[(stpcol - stcol) + 1]; for (int k = 0; k < f.length; k++) { f[k] = 20;//from ww w. ja v a 2 s . c om } f[0] = f[0] + 10 * maxlevel; PdfPTable table = new PdfPTable(f); java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, tColor); Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor); Font f1; table.setWidthPercentage(90); PdfPCell h2 = new PdfPCell(new Paragraph("Name", font)); // new if (config.getBoolean("gridBorder")) h2.setBorder(PdfPCell.BOX); else h2.setBorder(0); h2.setPadding(2); // h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED); // Paragraph(colwidth2[hcol],font); table.addCell(h2); int stpcol1 = 0; for (int hcol = stcol; hcol < stpcol; hcol++) { PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new h1.setHorizontalAlignment(Element.ALIGN_RIGHT); if (config.getBoolean("gridBorder")) h1.setBorder(PdfPCell.BOX); else h1.setBorder(0); h1.setPadding(2); // Paragraph(colwidth2[hcol],font); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { if (row % 62 == 61) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } if (store.getJSONObject(row).getBoolean("flag")) f1 = font; else f1 = font1; if (store.getJSONObject(row).getString("info").compareTo("") != 0) { h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1)); // h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5); } else { h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1)); // h2.setPaddingTop(9); // h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5); } // h2.setBorder(0); // h2.setPadding(1); // Color bColor = Color.decode("DDDDDD"); if (config.getBoolean("gridBorder")) { if (store.getJSONObject(row).getBoolean("flag")) { h2.setBackgroundColor(new Color(0xEEEEEE)); h2.setBorder(PdfPCell.LEFT | PdfPCell.BOTTOM); } else h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(2); h2.setBorderColor(Color.GRAY); if (store.getJSONObject(row).getBoolean("flag")) h2.setHorizontalAlignment(Element.ALIGN_LEFT); else h2.setHorizontalAlignment(Element.ALIGN_RIGHT); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); for (int col = stcol; col < stpcol; col++) { Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1); PdfPCell h1 = new PdfPCell(para); // h1.setBorder(0); // h1.setPadding(1); h1.setMinimumHeight(15); h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { if (store.getJSONObject(row).getBoolean("flag")) { h1.setBorder(PdfPCell.BOTTOM); h1.setBackgroundColor(new Color(0xEEEEEE)); if (col == stpcol - 1) h1.setBorder(PdfPCell.BOTTOM | PdfPCell.RIGHT); } else h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setPadding(2); h1.setBorderColor(Color.GRAY); table.addCell(h1); // table.addCell(new Paragraph(store.getJSONObject(row) // .getString(colwidth2[col]), f1)); } } document.add(table); document.newPage(); if (stpcol != colwidth2.length) { if ((colwidth2.length - stpcol) > 5) // column limit stpcol1 = stpcol + 5; else stpcol1 = (colwidth2.length - stpcol) + stpcol; addTableTimeLine(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document); } return stpcol; }
From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java
License:Open Source License
private void addTable(JSONArray store, String[] res, String[] colIndex, String[] colHeader, String[] mainHeader, String[] val, Document document) throws JSONException, DocumentException { java.awt.Color tColor = new Color(0, 0, 0); fontSmallBold.setColor(tColor);//ww w. j a va 2 s . com Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor); float[] colw = new float[4]; for (int x = 0; x < 4; x++) { colw[x] = 150; } int col = 0; for (int x = 0; x < mainHeader.length; x++) { //table start PdfPTable table = new PdfPTable(colw); table.setTotalWidth(88); table.setWidthPercentage(colw, document.getPageSize()); //table.setSpacingBefore(10); PdfPTable mainTable = new PdfPTable(1); mainTable.setTotalWidth(90); mainTable.setWidthPercentage(100); mainTable.setSpacingBefore(20); //header cell for mainTable PdfPCell headcell = null; headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold)); headcell.setBackgroundColor(new Color(0xEEEEEE)); headcell.setPadding(padding); mainTable.addCell(headcell); document.add(mainTable); //header cell added to mainTable int row = 3; if (x == 0 || x == 4) { row = 4; } else if (x == 5) { row = 0; } for (; row > 0; row--) { for (int y = 1; y < colw.length + 1; y++) {// for each column add the colHeader and value cell if (col != colHeader.length) { if (y % 2 != 0) { Paragraph p = new Paragraph(colHeader[col], f1); if (colHeader[col].contains("Variance")) { p = new Paragraph(colHeader[col], fontSmallBold); } PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); } else { Paragraph p; p = new Paragraph(val[col], f1); if (colHeader[col].contains("Start Variance") || colHeader[col].contains("End Variance")) { p = new Paragraph(val[col] + " days", fontSmallBold); } else if (colHeader[col].contains("Duration")) { if (colHeader[col].contains("Duration Variance")) p = new Paragraph(val[col] + " days", fontSmallBold); else p = new Paragraph(val[col] + " days", f1); } else if (colHeader[col].contains("Work")) { if (colHeader[col].contains("Work Variance")) p = new Paragraph(val[col] + " hrs", fontSmallBold); else p = new Paragraph(val[col] + " hrs", f1); } else if (colHeader[col].contains("Cost")) { if (colHeader[col].contains("Cost Variance")) p = new Paragraph(currSymbol + " " + val[col], fontSmallBold); else p = new Paragraph(currSymbol + " " + val[col], f1); } else if (colHeader[col].contains("Percent Complete")) { p = new Paragraph(val[col] + " %", f1); } PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); col++; } } } } if (x == 5) { int y = 0; row = res.length / 4; for (; row > 0; row--) { for (int c = 0; c < 2; c++) { Paragraph p = new Paragraph(res[y], f1); PdfPCell pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); p = new Paragraph(res[y + 1], f1); pcell = new PdfPCell(p); if (gridBorder) { pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP); } else { pcell.setBorder(0); } pcell.setPadding(padding); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(pcell); y += 2; } } } document.add(table); } }
From source file:com.krawler.esp.servlets.ExportReportServlet.java
License:Open Source License
private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, int maxlevel, Document document) { float[] f = new float[(stpcol - stcol) + 1]; for (int k = 0; k < f.length; k++) { f[k] = 20;//from w w w.j a va2 s.c o m } f[0] = f[0] + 10 * maxlevel; PdfPTable table = new PdfPTable(f); Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK); Font f1; PdfPCell h2 = new PdfPCell(new Paragraph("", font)); // new h2.setBorder(0); h2.setPadding(1); // h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED); // Paragraph(colwidth2[hcol],font); table.addCell(h2); int stpcol1 = 0; for (int hcol = stcol; hcol < stpcol; hcol++) { PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setBorder(0); h1.setPadding(1); // Paragraph(colwidth2[hcol],font); table.addCell(h1); } table.setHeaderRows(1); try { for (int row = strow; row < stprow; row++) { if (row % 62 == 61) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } if (store.getJSONObject(row).getBoolean("flag")) f1 = font; else f1 = font1; if (store.getJSONObject(row).getString("info").compareTo("") != 0) { h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1)); h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5); } else { h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1)); h2.setPaddingTop(9); h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5); } h2.setBorder(0); h2.setPadding(1); if (store.getJSONObject(row).getBoolean("flag")) h2.setHorizontalAlignment(Element.ALIGN_LEFT); else h2.setHorizontalAlignment(Element.ALIGN_RIGHT); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); for (int col = stcol; col < stpcol; col++) { Paragraph para = null; if (store.getJSONObject(row).has(colwidth2[col])) para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1); else para = new Paragraph("", f1); // Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1); PdfPCell h1 = new PdfPCell(para); h1.setBorder(0); h1.setPadding(1); h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h1); // table.addCell(new Paragraph(store.getJSONObject(row) // .getString(colwidth2[col]), f1)); } } document.add(table); document.newPage(); if (stpcol != colwidth2.length) { if ((colwidth2.length - stpcol) > 5) // column limit stpcol1 = stpcol + 5; else stpcol1 = (colwidth2.length - stpcol) + stpcol; addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document); } } catch (com.krawler.utils.json.base.JSONException j) { KrawlerLog.op.warn("Problem During Creating JSON Object :" + j.toString()); } catch (com.lowagie.text.DocumentException de) { KrawlerLog.op.warn("Problem While Creating PDF :" + de.toString()); } return stpcol; }
From source file:com.krawler.esp.servlets.ExportServlet.java
License:Open Source License
private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request, Session session) throws JSONException, DocumentException, SessionExpiredException { java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); fontSmallBold.setColor(tColor);//w w w .j a v a 2 s.co m PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor); PdfPCell h2 = new PdfPCell(new Paragraph("No.", fontSmallBold)); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { if (align[hcol].equals("right") && !colHeader[hcol].equals("")) { String currency = currencyRender("", session, request); h1 = new PdfPCell(new Paragraph(colHeader[hcol] + "(" + currency + ")", fontSmallBold)); } else h1 = new PdfPCell(new Paragraph(colHeader[hcol], fontSmallBold)); h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell(new Paragraph(String.valueOf(row + 1), f1)); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); for (int col = 0; col < colwidth2.length; col++) { Paragraph para = null; if (align[col].equals("right") && !temp.getString(colwidth2[col]).equals("")) { String currency = currencyRender(temp.getString(colwidth2[col]), session, request); para = new Paragraph(currency, f1); } else { if (colwidth2[col].equals("invoiceno")) { para = new Paragraph(temp.getString("no").toString(), f1); } else if (colwidth2[col].equals("invoicedate")) { para = new Paragraph(temp.getString("date").toString(), f1); } else if ((temp.isNull(colwidth2[col])) && !(colwidth2[col].equals("invoiceno")) && !(colwidth2[col].equals("invoicedate"))) { para = new Paragraph("", fontMediumRegular); } else { para = new Paragraph(temp.getString(colwidth2[col]).toString(), f1); } } h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (!align[col].equals("right") && !align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else if (align[col].equals("right")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } document.add(table); document.newPage(); return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, String[] xtype, Document document) throws ServiceException { try {//from ww w . jav a 2 s . c om java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell( new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { h1 = new PdfPCell(new Paragraph( fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor))); h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell(new Paragraph( fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); for (int col = 0; col < colwidth2.length; col++) { String str = temp.optString((colwidth2[col]), ""); try { if (xtype.length > 0) { str = formatValue(temp.optString((colwidth2[col]), ""), xtype[col]); } } catch (Exception e) { } Paragraph para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA, tColor)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (!align[col].equals("right") && !align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else if (align[col].equals("right")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java
License:Open Source License
public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request) throws ServiceException { try {/*w w w . j a v a2 s . c om*/ DateFormat formatter = authHandlerDAOObj.getUserDateFormatter( sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request), true); DateFormat frmt = authHandler.getDateFormatter(request); String currencyid = sessionHandlerImpl.getCurrencyID(request); int mode = Integer.parseInt(request.getParameter("get")); double totalCre = 0; double totalDeb = 0; java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); // fontSmallRegular.setColor(tColor); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell(new Paragraph( (new Phrase(fontFamilySelector.process("No.", FontContext.FOOTER_NOTE, tColor))))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { String headerStr = StringUtil.serverHTMLStripper(colHeader[hcol]); if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) { String currency = currencyRender("", currencyid); h1 = new PdfPCell(new Paragraph((new Phrase(fontFamilySelector .process(headerStr + "(" + currency + ")", FontContext.FOOTER_NOTE, tColor))))); } else { h1 = new PdfPCell(new Paragraph( (new Phrase(fontFamilySelector.process(headerStr, FontContext.FOOTER_NOTE, tColor))))); } h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell( new Paragraph(fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); if (mode == 116 || mode == 117) { totalCre = totalCre + Double .parseDouble(temp.getString("c_amount") != "" ? temp.getString("c_amount") : "0"); totalDeb = totalDeb + Double .parseDouble(temp.getString("d_amount") != "" ? temp.getString("d_amount") : "0"); } for (int col = 0; col < colwidth2.length; col++) { Paragraph para = null; String rowCurrencyId = temp.has("currencyid") ? temp.getString("currencyid") : currencyid; if (align[col].equals("currency") && !temp.getString(colwidth2[col]).equals("")) { String currency = currencyRender(temp.getString(colwidth2[col]), currencyid); para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } else if (align[col].equals("rowcurrency") && !temp.getString(colwidth2[col]).equals("")) { String withCurrency = currencyRender(temp.getString(colwidth2[col]), rowCurrencyId); para = new Paragraph(fontFamilySelector.process(withCurrency, FontContext.TABLE_DATA)); } else if (align[col].equals("date") && !temp.getString(colwidth2[col]).equals("")) { try { String d1 = formatter.format(frmt.parse(temp.getString(colwidth2[col]))); para = new Paragraph(fontFamilySelector.process(d1, FontContext.TABLE_DATA)); } catch (Exception ex) { para = new Paragraph(fontFamilySelector.process(temp.getString(colwidth2[col]), FontContext.TABLE_DATA)); } } else if (colwidth2[col].equals("taxrate") || colwidth2[col].equals("permargin") && !colHeader[col].equals("")) { para = new Paragraph(fontFamilySelector.process( htmlPercentageRender(temp.getString(colwidth2[col]), true), FontContext.TABLE_DATA)); } else { if (colwidth2[col].equals("invoiceno")) { para = new Paragraph(fontFamilySelector.process(temp.getString("no").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("invoicedate")) { para = new Paragraph(fontFamilySelector.process(temp.getString("date").toString(), FontContext.TABLE_DATA)); } else if ((temp.isNull(colwidth2[col])) && !(colwidth2[col].equals("invoiceno")) && !(colwidth2[col].equals("invoicedate"))) { para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_date")) { para = new Paragraph(fontFamilySelector.process(formatter.format( frmt.parse(temp.getString("c_date").toString() == "" ? temp.getString("d_date") : temp.getString("c_date"))), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_accountname")) { para = new Paragraph( fontFamilySelector.process( temp.getString("c_accountname").toString() == "" ? temp.getString("d_accountname").toString() : temp.getString("c_accountname").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_entryno")) { para = new Paragraph( fontFamilySelector.process( temp.getString("c_entryno").toString() == "" ? temp.getString("d_entryno").toString() : temp.getString("c_entryno").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_date")) { para = new Paragraph(fontFamilySelector.process(formatter.format( frmt.parse(temp.getString("d_date").toString() == "" ? temp.getString("c_date") : temp.getString("d_date"))), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_accountname")) { para = new Paragraph( fontFamilySelector.process( temp.getString("d_accountname").toString() == "" ? temp.getString("c_accountname").toString() : temp.getString("d_accountname").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_entryno")) { para = new Paragraph( fontFamilySelector.process( temp.getString("d_entryno").toString() == "" ? temp.getString("c_entryno").toString() : temp.getString("d_entryno").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("perioddepreciation")) { double adj = temp.getDouble("perioddepreciation") - temp.getDouble("firstperiodamt"); String currency = currencyRender("" + adj, currencyid); if (adj < 0.0001) { para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } else { para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } } else if (colHeader[col].equals("Opening Balance") || colHeader[col].equals("Asset Value")) { String currency = currencyRender("" + Math.abs(temp.getDouble("openbalance")), currencyid); para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } else { if (colHeader[col].equals("Opening Balance Type")) { double bal = Double.parseDouble(temp.getString(colwidth2[col])); String str = bal == 0 ? "" : (bal < 0 ? "Credit" : "Debit"); if (str.equals("")) str = "N/A"; para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA)); } else { para = new Paragraph(fontFamilySelector.process( temp.getString(colwidth2[col]).toString(), FontContext.TABLE_DATA)); } } } h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (align[col].equals("currency") || align[col].equals("rowcurrency") || colwidth2[col].equals("taxrate") || colwidth2[col].equals("permargin")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("date")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } if (mode == 116 || mode == 117) { Paragraph para1 = null; PdfPCell h3 = null; String totCr = ""; String totDb = ""; h3 = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA))); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.lightGray); h3.setHorizontalAlignment(Element.ALIGN_CENTER); h3.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h3); para1 = new Paragraph(fontFamilySelector.process("Total", FontContext.REPORT_TITLE)); h3 = new PdfPCell(para1); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.LIGHT_GRAY); h3.setHorizontalAlignment(Element.ALIGN_LEFT); h3.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(h3); for (int col = 1; col < colwidth2.length; col++) { if (colwidth2[col].equals("c_amount")) { totCr = currencyRender(String.valueOf(totalCre), currencyid); para1 = new Paragraph(fontFamilySelector.process(totCr, FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_amount")) { totDb = currencyRender(String.valueOf(totalDeb), currencyid); para1 = new Paragraph(fontFamilySelector.process(totDb, FontContext.TABLE_DATA)); } else { para1 = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } h3 = new PdfPCell(para1); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.LIGHT_GRAY); h3.setHorizontalAlignment(Element.ALIGN_RIGHT); h3.setVerticalAlignment(Element.ALIGN_RIGHT); table.addCell(h3); } } document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }