List of usage examples for com.lowagie.text Document newPage
public boolean newPage()
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;// w w w. j a va 2s . c om } 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);//from w w w .ja v a2s. c o 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 w w w. ja v a2s. com*/ 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 {/*from www . j av a 2 s .co m*/ 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; }
From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java
License:Open Source License
public int addGroupableTable(JSONObject groupingConfig, String groupByField, String groupHeaderText, int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] dataIndexArr, String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request) throws ServiceException { try {/*from w w w.java2 s .co m*/ String groupSummaryField = groupingConfig.getString("groupSummaryField"); String groupSummaryText = groupingConfig.getString("groupSummaryText"); String reportSummaryField = groupingConfig.getString("reportSummaryField"); String reportSummaryText = groupingConfig.getString("reportSummaryText"); DateFormat formatter = authHandlerDAOObj.getUserDateFormatter( sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request), true); DateFormat frmt = authHandler.getDateFormatter(request); String currencyid = sessionHandlerImpl.getCurrencyID(request); java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); java.awt.Color gsBGColor = new Color(Integer.parseInt("E5E5E5", 16)); java.awt.Color rsBGColor = new Color(Integer.parseInt("808080", 16)); // fontRegular.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(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 < dataIndexArr.length; hcol++) { if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) { String currency = currencyRender("", currencyid); h1 = new PdfPCell(new Paragraph(fontFamilySelector .process(colHeader[hcol] + "(" + currency + ")", FontContext.TABLE_HEADER, tColor))); } else { 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); String groupName = "", rowCurrency = ""; Double subTotal = 0.0; Double grandTotal = 0.0; int rowSpan = 0; for (int row = strow; row < stprow; row++) { rowSpan++; JSONObject rowData = store.getJSONObject(row); if (row == 0) { groupName = rowData.getString(groupByField); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; subTotal = 0.0; addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr); } if (!groupName.equalsIgnoreCase(rowData.getString(groupByField))) { addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr, false, gsBGColor); groupName = rowData.getString(groupByField); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr); subTotal = 0.0; rowSpan = 1; } subTotal += Double.parseDouble(rowData.getString(groupSummaryField)); grandTotal += Double.parseDouble(rowData.getString(reportSummaryField)); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; h2 = new PdfPCell(new Paragraph( fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_HEADER, 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); for (int col = 0; col < dataIndexArr.length; col++) { String cellData = null; if (align[col].equals("currency") && !rowData.getString(dataIndexArr[col]).equals("")) { cellData = currencyRender(rowData.getString(dataIndexArr[col]), rowData.getString("currencyid")); } else if (align[col].equals("date") && !rowData.getString(dataIndexArr[col]).equals("")) { try { cellData = formatter.format(frmt.parse(rowData.getString(dataIndexArr[col]))); } catch (Exception ex) { cellData = rowData.getString(dataIndexArr[col]); } } else { cellData = rowData.getString(dataIndexArr[col]); } Paragraph para = new Paragraph( fontFamilySelector.process(cellData, FontContext.TABLE_HEADER, 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("currency") && !align[col].equals("date")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } else if (align[col].equals("currency")) { 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); } table.addCell(h1); } } if (rowSpan > 0) { addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr, false, gsBGColor); } addSummaryRow(reportSummaryText, grandTotal, currencyid, table, dataIndexArr, false, rsBGColor); document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
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 = {/* ww w .j a v a 2 s. com*/ 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.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public void exportSalarySlip(String userid, Date startdate, Date enddate, HttpServletRequest request, HttpServletResponse response, String historyid) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter writer = null;/*from w w w . ja v a 2 s .c o m*/ try { HrmsCommonPayroll hrmsCommonPayroll = new HrmsCommonPayroll(); DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); User user = exportSalarySlipDAO.getUser(userid); Empprofile empprofile = exportSalarySlipDAO.getEmpprofile(userid); Useraccount useraccount = exportSalarySlipDAO.getUserAccount(userid); Company company = user.getCompany(); PayrollHistory payrollHistory = exportSalarySlipDAO.getPayrollHistory(historyid); CompanyPreferences preferences = (CompanyPreferences) kwlCommonTablesDAO .getObject("com.krawler.common.admin.CompanyPreferences", company.getCompanyID()); Date financialStartDate = hrmsCommonPayroll.getFinanacialYearStartDate(enddate, preferences.getFinancialmonth()); Date financialEndDate = hrmsCommonPayroll.getFinanacialYearEndDate(enddate, preferences.getFinancialmonth() + 11); IncomeTax incomeTax = getIncomTaxObj(request); List<PayrollHistory> list = null; Map<String, Double> mapEPF = null; if (incomeTax != null) { list = incomeTax.getPayrollHistories(userid, HrmsPayrollConstants.PAYROLL_HISTORY_STATUS_PROCESSED_FINAL, financialStartDate, financialEndDate); mapEPF = incomeTax.getEPF(list, payrollHistory); } writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage(RequestContextUtils.getLocale(request))); document.open(); PdfPTable mainTable = new PdfPTable(1); mainTable.setWidthPercentage(100); mainTable.addCell(getEmployeeDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.NO_BORDER, request)); mainTable.addCell(getSalaryDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.NO_BORDER, request)); mainTable.addCell(getEmployeeAndEmployerDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.CELL, list, mapEPF, request)); document.newPage(); document.add(mainTable); document.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + user.getFirstName() + "_" + sdf.format(startdate) + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); } catch (Exception e) { e.printStackTrace(); } finally { writer.close(); } }
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;// ww w . jav a2 s .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.matic.sudoku.io.export.PdfExporter.java
License:Open Source License
/** * Generate and export multiple boards to PDF * /* w w w. ja v a 2 s . c om*/ * @param exporterParameters PDF exporter parameters * @param generator Generator used for puzzle generation * @throws IOException If any PDF library error occurs * @throws DocumentException If any error occurs while writing the PDF file */ public void write(final ExporterParameters exporterParameters, final Generator generator, final int boardDimension) throws IOException, DocumentException { //How many PDF-pages are needed to fit all puzzles using the desired page formatting final int optimisticPageCount = exporterParameters.getPuzzleCount() / exporterParameters.getPuzzlesPerPage(); final int pageCount = exporterParameters.getPuzzleCount() % exporterParameters.getPuzzlesPerPage() > 0 ? optimisticPageCount + 1 : optimisticPageCount; final Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN); final OutputStream outputStream = new FileOutputStream(exporterParameters.getOutputPath()); final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); final String creator = Sudoku.getNameAndVersion(); document.addSubject("Puzzles generated by " + creator); document.addCreator(creator); document.open(); final Rectangle pageSize = document.getPageSize(); final int pageHeight = (int) pageSize.getHeight(); final int pageWidth = (int) pageSize.getWidth(); //Get appropriate number of rows and columns needed to divide a page into final int horizontalDimension = exporterParameters.getPuzzlesPerPage() > 2 ? 2 : 1; final int verticalDimension = exporterParameters.getPuzzlesPerPage() > 1 ? 2 : 1; //Get available space for each board (with margins) on a page final int boardWidth = pageWidth / horizontalDimension; final int boardHeight = pageHeight / verticalDimension; final Board board = new Board(boardDimension, SymbolType.DIGITS); board.setSize(boardWidth, boardHeight); board.handleResized(); //Get available height/width on a page for a puzzle itself final int puzzleWidth = board.getPuzzleWidth(); int puzzlesPrinted = 0; final PdfContentByte contentByte = pdfWriter.getDirectContent(); final Grading[] gradings = getGeneratedPuzzleGradings(exporterParameters.getGradings(), exporterParameters.getOrdering(), exporterParameters.getPuzzleCount()); pageCounter: for (int page = 0; page < pageCount; ++page) { document.newPage(); final Graphics2D g2d = contentByte.createGraphics(pageWidth, pageHeight); for (int y = 0, i = 0; i < verticalDimension; y += boardHeight, ++i) { for (int x = 0, j = 0; j < horizontalDimension; x += boardWidth, ++j) { //Check whether to generate a new puzzle or print empty boards final ExportMode exportMode = exporterParameters.getExportMode(); final Grading selectedGrading = exportMode == ExportMode.BLANK ? null : gradings[puzzlesPrinted]; if (exportMode == ExportMode.GENERATE_NEW) { board.setPuzzle(generatePuzzle(generator, getSymmetry(exporterParameters.getSymmetries()), selectedGrading)); board.recordGivens(); } //Calculate puzzle drawing origins final int originX = x + (int) (boardWidth / 2 - (puzzleWidth / 2)); final int originY = y + (int) (boardHeight / 2) - (puzzleWidth / 2); board.setSymbolType(getSymbolType(exporterParameters.getSymbolType())); board.setDrawingOrigin(originX, originY); board.draw(g2d, false, false); drawLegend(g2d, getLegendString(exporterParameters.isShowNumbering(), exporterParameters.isShowGrading(), puzzlesPrinted + 1, selectedGrading), originX, originY, puzzleWidth); if (++puzzlesPrinted == exporterParameters.getPuzzleCount()) { //We've printed all puzzles, break g2d.dispose(); break pageCounter; } } } g2d.dispose(); } document.close(); outputStream.flush(); outputStream.close(); }
From source file:com.moss.pdf.template.core.Renderer.java
License:Open Source License
public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception { PdfReader reader = new PdfReader(in); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from w w w. j a va 2s .c om for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte cb = writer.getDirectContent(); PdfImportedPage customPage = writer.getImportedPage(reader, i); /* * add the page to our new document, turning this page to its * original rotation */ int pageRotation = reader.getPageRotation(i); if (pageRotation > 0) { System.out.println("page rotation found: " + pageRotation); double angle = -((2 * Math.PI) * pageRotation / 360); // double angle = -(Math.PI / 2); cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle), (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x document.top() + document.topMargin() // y ); } else { cb.addTemplate(customPage, 0f, 0f); } Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>(); for (PropertyMapping field : fields) { if (field.getPageNumber() != i) { continue; } /* * Only builtin fonts are supported at the moment */ BaseFont font; int fontSize; int alignment; String text; float x, y; float rotation; { font = fonts.get(field.getFontName()); if (font == null) { FontName e = field.getFontName(); String name = null; if (FontName.COURIER == e) { name = BaseFont.COURIER; } else if (FontName.COURIER_BOLD == e) { name = BaseFont.COURIER_BOLD; } else if (FontName.COURIER_BOLD_OBLIQUE == e) { name = BaseFont.COURIER_BOLDOBLIQUE; } else if (FontName.COURIER_OBLIQUE == e) { name = BaseFont.COURIER_OBLIQUE; } else if (FontName.HELVETICA == e) { name = BaseFont.HELVETICA; } else if (FontName.HELVETICA_BOLD == e) { name = BaseFont.HELVETICA_BOLD; } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) { name = BaseFont.HELVETICA_BOLDOBLIQUE; } else if (FontName.HELVETICA_OBLIQUE == e) { name = BaseFont.HELVETICA_OBLIQUE; } else if (FontName.TIMES_BOLD == e) { name = BaseFont.TIMES_BOLD; } else if (FontName.TIMES_BOLD_ITALIC == e) { name = BaseFont.TIMES_BOLDITALIC; } else if (FontName.TIMES_ITALIC == e) { name = BaseFont.TIMES_ITALIC; } else if (FontName.TIMES_ROMAN == e) { name = BaseFont.TIMES_ROMAN; } if (name == null) { throw new RuntimeException("Unknown font type: " + e); } font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); fonts.put(field.getFontName(), font); } fontSize = field.getFontSize(); if (TextAlignment.LEFT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_LEFT; } else if (TextAlignment.CENTER == field.getAlignment()) { alignment = PdfContentByte.ALIGN_CENTER; } else if (TextAlignment.RIGHT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_RIGHT; } else { alignment = PdfContentByte.ALIGN_LEFT; } Object value = p.eval(field.getExpr()); if (value == null) { text = ""; } else { text = value.toString(); } x = field.getX() * POINTS_IN_A_CM; y = field.getY() * POINTS_IN_A_CM; rotation = 0; } cb.beginText(); cb.setFontAndSize(font, fontSize); cb.showTextAligned(alignment, text, x, y, rotation); cb.endText(); } document.newPage(); } reader.close(); document.close(); }