List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:com.krawler.spring.hrms.payroll.payslip.ExportPayslipController.java
License:Open Source License
public ModelAndView exportPDF(HttpServletRequest request, HttpServletResponse response) { JSONObject jsonResp = new JSONObject(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = null;//from w w w .jav a 2s . c o m try { Company company = (Company) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.Company", sessionHandlerImplObj.getCompanyid(request)); int i = 0; DecimalFormat decfm = new DecimalFormat("#,##0.00"); Date d2 = null; Date d3 = null; int days = 0; boolean showborder = true; if (!StringUtil.isNullOrEmpty(request.getParameter("showborder"))) { showborder = Boolean.parseBoolean(request.getParameter("showborder")); } SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); String stDate = request.getParameter("stdate").replace("/", "-"); String endDate = request.getParameter("enddate").replace("/", "-"); d2 = sdf.parse(stDate); d3 = sdf.parse(endDate); days = getWorkingDays(request.getParameter("stdate").replace("/", "-"), request.getParameter("enddate").replace("/", "-"), company.getCompanyID()); String historyid = ""; List<Payhistory> lst = exportPayslipDAO.getPayhistory(request.getParameter("empid"), d2, d3); ; if (lst != null && lst.size() == 0) { throw new Exception("Exception occured"); } else if (lst != null && lst.size() > 0) { String currSymbol = getCurrencySymbol(request, false); masterDB.Payhistory payhistory = (masterDB.Payhistory) lst.get(0); historyid = payhistory.getHistoryid(); double unpaidleaves = payhistory.getUnpaidleaves(); Document document = new Document(PageSize.A4, 15, 15, 15, 15); writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage(request)); document.open(); String userid = request.getParameter("empid"); User userinfo = payhistory.getUserID(); Useraccount ua = (Useraccount) kwlCommonTablesDAOObj .getObject("com.krawler.common.admin.Useraccount", userinfo.getUserID()); String uname = userinfo.getLastName() != null ? userinfo.getLastName() : ""; String empid = getUserCode(ua, company.getCompanyID()); String department = payhistory.getDepartment(); String designation = getUserDesignation(ua); String bankacc = ua.getAccno() != null ? ua.getAccno() : ""; Empprofile empprof = null; String epf = ""; String dateofjoin = ""; try { empprof = (Empprofile) kwlCommonTablesDAOObj.getObject("com.krawler.hrms.ess.Empprofile", userid); epf = StringUtil.isNullOrEmpty(empprof.getPfno()) ? "" : empprof.getPfno(); dateofjoin = empprof.getJoindate() != null ? empprof.getJoindate().toString() : ""; } catch (Exception ex) { epf = ""; } PdfPTable mainTable = new PdfPTable(1); mainTable.setWidthPercentage(100); PdfPTable table1 = new PdfPTable(3); table1.setWidthPercentage(100); table1.setWidths(new float[] { 40, 40, 20 }); PdfPTable userTable1 = new PdfPTable(1); String cmpid = AuthHandler.getCompanyid(request); userTable1.setHorizontalAlignment(Element.ALIGN_MIDDLE); userTable1.setWidthPercentage(10); PdfPCell cell11 = null; PdfPCell cell1x = new PdfPCell( new Paragraph(fontFamilySelector.process(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell1x.setBorder(0); userTable1.addCell(cell1x); try { String imgPath = StorageHandler.GetProfileImgStorePath() + cmpid + ".png"; if (StringUtil.isStandAlone()) { imgPath = URLUtil.getPageURL(request, "").concat(ProfileImageServlet.defaultCompanyImgPath); } Image img = Image.getInstance(imgPath); cell11 = new PdfPCell(img); cell11.setPaddingLeft(5); } catch (Exception e) { cell11 = new PdfPCell(new Paragraph(fontFamilySelector .process(AuthHandler.getCompanyName(request), FontContext.TABLE_BOLD_TIMES_NEW_ROMAN))); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); } if (cell11 != null) { cell11.setBorder(0); userTable1.addCell(cell11); } PdfPCell cell1 = new PdfPCell( new Paragraph(fontFamilySelector.process("", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(0); userTable1.addCell(cell1); PdfPTable userTable2 = new PdfPTable(1); userTable2.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getCompanyName(), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); cell.setPaddingTop(15); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph( fontFamilySelector.process(company.getCity(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getAddress(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph( fontFamilySelector.process(company.getState(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getZipCode(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.payslip.period.params", new Object[] { request.getParameter("stdate"), request.getParameter("enddate") }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); PdfPTable userTable3 = new PdfPTable(1); userTable3.setWidthPercentage(100); PdfPCell cell2 = new PdfPCell( new Paragraph(fontFamilySelector.process("", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); cell2.setBorder(0); userTable1.addCell(cell2); PdfPCell mainCell11 = new PdfPCell(userTable1); if (!showborder) { mainCell11.setBorder(0); } else { mainCell11.setBorder(Rectangle.LEFT); } table1.addCell(mainCell11); PdfPCell mainCell13 = new PdfPCell(userTable2); mainCell13.setBorder(0); table1.addCell(mainCell13); PdfPCell mainCell15 = new PdfPCell(userTable3); if (!showborder) { mainCell15.setBorder(0); } else { mainCell15.setBorder(Rectangle.RIGHT); } table1.addCell(mainCell15); PdfPCell mainCell12 = new PdfPCell(new Paragraph("")); if (!showborder) { mainCell12.setBorder(0); } else { mainCell12.setBorder(Rectangle.LEFT); } table1.addCell(mainCell12); PdfPCell mainCell14 = new PdfPCell(new Paragraph("")); mainCell14.setBorder(0); table1.addCell(mainCell14); PdfPCell mainCell16 = new PdfPCell(new Paragraph("")); if (!showborder) { mainCell16.setBorder(0); } else { mainCell16.setBorder(Rectangle.RIGHT); } table1.addCell(mainCell16); PdfPCell mainCell1 = new PdfPCell(table1); if (!showborder) { mainCell1.setBorder(0); } else { mainCell1.setBorder(1); } mainTable.addCell(mainCell1); // __________________________________________________________________________ PdfPTable table2 = new PdfPTable(4); table2.setWidthPercentage(100); table2.setWidths(new float[] { 20, 30, 20, 30 }); PdfPCell h11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.employee.code", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h11.setHorizontalAlignment(Element.ALIGN_LEFT); h11.setPadding(5); if (!showborder) { h11.setBorder(0); } table2.addCell(h11); PdfPCell h12 = new PdfPCell(new Paragraph( fontFamilySelector.process("" + empid, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h12.setHorizontalAlignment(Element.ALIGN_LEFT); h12.setPadding(5); if (!showborder) { h12.setBorder(0); } table2.addCell(h12); PdfPCell h13 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h13.setHorizontalAlignment(Element.ALIGN_LEFT); h13.setPadding(5); if (!showborder) { h13.setBorder(0); } table2.addCell(h13); PdfPCell h14 = new PdfPCell(new Paragraph(fontFamilySelector .process(userinfo.getFirstName() + " " + uname, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h14.setHorizontalAlignment(Element.ALIGN_LEFT); h14.setPadding(5); if (!showborder) { h14.setBorder(0); } table2.addCell(h14); PdfPCell h21 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.department", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h21.setHorizontalAlignment(Element.ALIGN_LEFT); h21.setPadding(5); if (!showborder) { h21.setBorder(0); } table2.addCell(h21); PdfPCell h22 = new PdfPCell(new Paragraph( fontFamilySelector.process(department, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h22.setHorizontalAlignment(Element.ALIGN_LEFT); h22.setPadding(5); if (!showborder) { h22.setBorder(0); } table2.addCell(h22); PdfPCell h33 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.designation", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h33.setHorizontalAlignment(Element.ALIGN_LEFT); h33.setPadding(5); if (!showborder) { h33.setBorder(0); } table2.addCell(h33); PdfPCell h34 = new PdfPCell(new Paragraph( fontFamilySelector.process(designation, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h34.setHorizontalAlignment(Element.ALIGN_LEFT); h34.setPadding(5); if (!showborder) { h34.setBorder(0); } table2.addCell(h34); PdfPCell h43 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.bank.ac.no", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h43.setHorizontalAlignment(Element.ALIGN_LEFT); h43.setPadding(5); if (!showborder) { h43.setBorder(0); } table2.addCell(h43); PdfPCell h44 = new PdfPCell(new Paragraph( fontFamilySelector.process(bankacc, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h44.setHorizontalAlignment(Element.ALIGN_LEFT); h44.setPadding(5); if (!showborder) { h44.setBorder(0); } table2.addCell(h44); PdfPCell h61 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.working.days", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h61.setHorizontalAlignment(Element.ALIGN_LEFT); h61.setPadding(5); if (!showborder) { h61.setBorder(0); } table2.addCell(h61); PdfPCell h62 = new PdfPCell(new Paragraph(fontFamilySelector.process(String.valueOf(days), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h62.setHorizontalAlignment(Element.ALIGN_LEFT); h62.setPadding(5); if (!showborder) { h62.setBorder(0); } table2.addCell(h62); PdfPCell h63 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.e.p.f", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h63.setHorizontalAlignment(Element.ALIGN_LEFT); h63.setPadding(5); if (!showborder) { h63.setBorder(0); } table2.addCell(h63); PdfPCell h64 = new PdfPCell( new Paragraph(fontFamilySelector.process(epf, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h64.setHorizontalAlignment(Element.ALIGN_LEFT); h64.setPadding(5); if (!showborder) { h64.setBorder(0); } table2.addCell(h64); PdfPCell h65 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.DateofJoining", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h65.setHorizontalAlignment(Element.ALIGN_LEFT); h65.setPadding(5); if (!showborder) { h65.setBorder(0); } table2.addCell(h65); PdfPCell h66 = new PdfPCell(new Paragraph( fontFamilySelector.process(dateofjoin, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h66.setHorizontalAlignment(Element.ALIGN_LEFT); h66.setPadding(5); if (!showborder) { h66.setBorder(0); } table2.addCell(h66); for (int y = 0; y < 2; y++) { PdfPCell h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { h71.setBorder(0); } else { h71.setBorder(Rectangle.LEFT); } table2.addCell(h71); for (i = 0; i < 2; i++) { h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); h71.setBorder(0); table2.addCell(h71); } h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { h71.setBorder(0); } else { h71.setBorder(Rectangle.RIGHT); } table2.addCell(h71); } PdfPCell mainCell2 = new PdfPCell(table2); if (!showborder) { mainCell2.setBorder(0); } else { mainCell2.setBorder(1); } mainTable.addCell(mainCell2); PdfPTable table3main = new PdfPTable(1); table3main.setWidthPercentage(100); PdfPTable table7main = new PdfPTable(1); table7main.setWidthPercentage(100); PdfPTable table31 = new PdfPTable(4); table31.setWidthPercentage(100); table31.setWidths(new float[] { 30, 20, 30, 20 }); PdfPTable table41 = new PdfPTable(2); table41.setWidthPercentage(100); table41.setWidths(new float[] { 50, 50 }); //*************************************************************************************************************** PdfPCell s11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.Earnings", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s11.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s11.setBorder(0); } else { s11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } s11.setPadding(5); table31.addCell(s11); PdfPCell s12 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s12.setHorizontalAlignment(Element.ALIGN_RIGHT); s12.setPadding(5); if (!showborder) { s12.setBorder(0); } else { s12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } table31.addCell(s12); PdfPCell s14 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.Deduction", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s14.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s14.setBorder(0); } else { s14.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } s14.setPadding(5); table31.addCell(s14); PdfPCell s15 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s15.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s15.setBorder(0); } else { s15.setBorder(Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM); } s15.setPadding(5); table31.addCell(s15); int Wcount = 0; float taxtotal = 0; List<Historydetail> lst1 = exportPayslipDAO.getHistorydetail(historyid, "Wages", "Basic"); List<Historydetail> list = exportPayslipDAO.getHistorydetailNotType(historyid, "Wages", "Basic"); if (list != null) { lst1.addAll(list); } List<Historydetail> lst2 = exportPayslipDAO.getHistorydetail(historyid, "Taxes"); CompanyPreferences cp = hrmsCommonDAOObj.getCompanyPreferences(company.getCompanyID()); int financialMonth = cp.getFinancialmonth(); Calendar c1 = Calendar.getInstance(); c1.setTime(d3); c1.set(Calendar.MONTH, financialMonth); c1.set(Calendar.DATE, 1); Date d = c1.getTime(); Date DOJ = new java.util.Date(empprof.getJoindate().getTime()); if (d3.before(d)) { int currentYear = c1.get(Calendar.YEAR) - 1; c1.set(Calendar.YEAR, currentYear); d = c1.getTime(); } if (DOJ.after(d)) { c1.setTime(DOJ); c1.set(Calendar.DATE, 1); d = c1.getTime(); } List<Historydetail> lst3 = exportPayslipDAO.getHistorydetail(historyid, "Deduction"); int size = lst1.size() > (lst2.size() + lst3.size()) ? lst1.size() : lst2.size() + lst3.size(); float wagetotal = 0; double totalYTDEarning = 0, totalYTDDeduction = 0; for (i = 0; i < size; i++) { masterDB.Historydetail hd = null; if (i < lst1.size()) { hd = (masterDB.Historydetail) lst1.get(i); PdfPCell s21 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT); } s21.setPadding(5); table31.addCell(s21); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s22 = new PdfPCell( new Paragraph(fontFamilySelector.process(String.valueOf(decfm.format(newamount)), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s22.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s22.setBorder(0); } else { s22.setBorder(Rectangle.LEFT); } s22.setPadding(5); table31.addCell(s22); List<Historydetail> lstw = exportPayslipDAO.getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); double wageAmt = 0; masterDB.Historydetail hd1 = null; for (int y = 0; y < lstw.size(); y++) { hd1 = (masterDB.Historydetail) lstw.get(y); wageAmt += Double.parseDouble(hd1.getAmount()); } wagetotal = wagetotal + Float.parseFloat(hd.getAmount()); totalYTDEarning = totalYTDEarning + wageAmt; Wcount++; } else { for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph( fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT); } s21.setPadding(5); table31.addCell(s21); } } if (i < lst2.size()) { hd = (masterDB.Historydetail) lst2.get(i); PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table31.addCell(s24); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); } s25.setPadding(5); table31.addCell(s25); List<Historydetail> lstw1 = exportPayslipDAO.getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); double taxAmt = 0; masterDB.Historydetail hd2 = null; for (int y = 0; y < lstw1.size(); y++) { hd2 = (masterDB.Historydetail) lstw1.get(y); taxAmt += Double.parseDouble(hd2.getAmount()); } taxtotal = taxtotal + Float.parseFloat(hd.getAmount()); totalYTDDeduction = totalYTDDeduction + taxAmt; } else { if (i - lst2.size() < lst3.size()) { hd = (masterDB.Historydetail) lst3.get(i - lst2.size()); PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); if (hd.getType().equals("Unpaid_leaves")) { s24 = new PdfPCell(new Paragraph( fontFamilySelector.process(hd.getType() + "(" + unpaidleaves + ")", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); } s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table31.addCell(s24); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); ; } s25.setPadding(5); table31.addCell(s25); List<Historydetail> lstw2 = exportPayslipDAO .getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); masterDB.Historydetail hd3 = null; double deductAmt = 0; for (int y = 0; y < lstw2.size(); y++) { hd3 = (masterDB.Historydetail) lstw2.get(y); deductAmt += Double.parseDouble(hd3.getAmount()); } taxtotal = taxtotal + Float.parseFloat(hd.getAmount()); totalYTDDeduction = totalYTDDeduction + deductAmt; } else { for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph( fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT + Rectangle.RIGHT); } s21.setPadding(5); table31.addCell(s21); } } } } PdfPCell s91 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.earnings", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s91.setHorizontalAlignment(Element.ALIGN_BASELINE); s91.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s91.setBorder(0); } else { s91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s91.setPadding(5); table31.addCell(s91); BigDecimal bd = new BigDecimal(String.valueOf(wagetotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s92.setHorizontalAlignment(Element.ALIGN_BASELINE); s92.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s92.setBorder(0); } else { s92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s92.setPadding(5); table31.addCell(s92); PdfPCell s94 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.deductions", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s94.setHorizontalAlignment(Element.ALIGN_BASELINE); s94.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s94.setBorder(0); } else { s94.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s94.setPadding(5); table31.addCell(s94); bd = new BigDecimal(String.valueOf(taxtotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); PdfPCell s95 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s95.setHorizontalAlignment(Element.ALIGN_BASELINE); s95.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s95.setBorder(0); } else { s95.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s95.setPadding(5); table31.addCell(s95); for (int y = 0; y < 2; y++) { PdfPCell he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { he71.setBorder(0); } else { he71.setBorder(Rectangle.LEFT); } table31.addCell(he71); for (i = 0; i < 2; i++) { he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); he71.setBorder(0); table31.addCell(he71); } he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { he71.setBorder(0); } else { he71.setBorder(Rectangle.RIGHT); } table31.addCell(he71); } List<Historydetail> lst4 = exportPayslipDAO.getHistorydetail(historyid, "Employer Contribution"); double ectotal = 0; PdfPCell ec11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.EmployerContribution", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); ec11.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { ec11.setBorder(0); } else { ec11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } ec11.setPadding(5); table41.addCell(ec11); PdfPCell ec12 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); ec12.setHorizontalAlignment(Element.ALIGN_RIGHT); ec12.setPadding(5); if (!showborder) { ec12.setBorder(0); } else { ec12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT); } table41.addCell(ec12); masterDB.Historydetail hd1 = null; for (i = 0; i < lst4.size(); i++) { hd1 = (masterDB.Historydetail) lst4.get(i); PdfPCell s24 = new PdfPCell(new Paragraph( fontFamilySelector.process(hd1.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table41.addCell(s24); bd = new BigDecimal(hd1.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); ectotal = ectotal + newamount; PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); } s25.setPadding(5); table41.addCell(s25); } PdfPCell se91 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.contribution", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); se91.setHorizontalAlignment(Element.ALIGN_BASELINE); se91.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { se91.setBorder(0); } else { se91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } se91.setPadding(5); table41.addCell(se91); bd = new BigDecimal(String.valueOf(ectotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); PdfPCell se92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); se92.setHorizontalAlignment(Element.ALIGN_BASELINE); se92.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { se92.setBorder(0); } else { se92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM + Rectangle.RIGHT); } se92.setPadding(5); table41.addCell(se92); PdfPCell Cell31 = new PdfPCell(table31); if (!showborder) { Cell31.setBorder(0); } else { Cell31.setBorder(1); } table3main.addCell(Cell31); PdfPCell mainCell4 = new PdfPCell(table3main); if (!showborder) { mainCell4.setBorder(0); } else { mainCell4.setBorder(1); } mainTable.addCell(mainCell4); PdfPCell Cell41 = new PdfPCell(table41); if (!showborder) { Cell41.setBorder(0); } else { Cell41.setBorder(1); } table7main.addCell(Cell41); PdfPCell mainCell44 = new PdfPCell(table7main); if (!showborder) { mainCell44.setBorder(0); } else { mainCell44.setBorder(1); } mainTable.addCell(mainCell44); //*************************************************************************************************************** PdfPTable table4 = new PdfPTable(2); table4.setWidthPercentage(100); for (i = 0; i < 4; i++) { PdfPCell i33 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i33.setHorizontalAlignment(Element.ALIGN_CENTER); if (!showborder) { i33.setBorder(0); } else { i33.setBorder(Rectangle.LEFT + Rectangle.RIGHT); } table4.addCell(i33); } PdfPCell i31 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.netpay", null, RequestContextUtils.getLocale(request)) + " ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i31.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i31.setBorder(0); } else { i31.setBorder(Rectangle.LEFT + Rectangle.TOP); } i31.setPadding(5); table4.addCell(i31); double netpay = 0; netpay = wagetotal - taxtotal; netpay = Math.round(netpay); String amount = numberFormatter((double) netpay, currSymbol); PdfPCell i33 = new PdfPCell( new Paragraph(fontFamilySelector.process(amount, FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i33.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { i33.setBorder(0); } else { i31.setBorder(Rectangle.RIGHT); } i33.setPadding(5); table4.addCell(i33); PdfPCell i32 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.in.words", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i32.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i32.setBorder(0); } else { i31.setBorder(Rectangle.LEFT); } i32.setPadding(5); table4.addCell(i32); EnglishNumberToWords enw = new EnglishNumberToWords(request, messageSource); String netinword = enw.convert(netpay); PdfPCell i34 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.only", new Object[] { getCurrencyName(request), netinword }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i34.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i34.setBorder(0); } else { i31.setBorder(Rectangle.RIGHT); } i34.setPadding(5); table4.addCell(i34); PdfPCell mainCell5 = new PdfPCell(table4); if (!showborder) { mainCell5.setBorder(0); } else { mainCell5.setBorder(1); } mainTable.addCell(mainCell5); document.add(new Paragraph("\n\n")); PdfPTable table5 = new PdfPTable(2); table5.setWidthPercentage(80); cell = new PdfPCell(new Paragraph("___________________________")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell(new Paragraph("___________________________")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.employee.signature", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.manager.signature", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); document.add(mainTable); document.close(); } String filename = "Employee_Payslip.pdf"; if (!StringUtil.isNullOrEmpty(request.getParameter("reportname"))) { String temp = request.getParameter("reportname"); filename = temp.lastIndexOf(".pdf") >= 0 ? temp : temp + ".pdf"; } response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); jsonResp.put("valid", true); jsonResp.put("data", ""); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (response.getOutputStream() != null) { response.getOutputStream().flush(); response.getOutputStream().close(); } } catch (IOException e) { e.printStackTrace(); } writer.close(); } return new ModelAndView("jsonView", "model", jsonResp.toString()); }
From source file:com.logiware.accounting.reports.ArDisputeReportCreator.java
private void writeHeaders() throws Exception { headerTable = new PdfPTable(1); headerTable.setWidthPercentage(100); String imagePath = LoadLogisoftProperties.getProperty("application.image.logo"); Image image = Image.getInstance(contextPath + imagePath); image.scalePercent(75);//from ww w .ja v a2s. co m PdfPCell logoCell = createImageCell(image); headerTable.addCell(logoCell); headerTable.addCell(createCell("AR Dispute Report", headerBoldFont15, Element.ALIGN_CENTER, Rectangle.BOX, Color.LIGHT_GRAY)); headerTable.addCell(createEmptyCell(Rectangle.NO_BORDER)); headerTable.addCell(createEmptyCell(Rectangle.NO_BORDER)); if (arReportsForm.isAllCustomers()) { PdfPCell cell = createCell("For ALL Customers", headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); } else if (CommonUtils.isNotEmpty(arReportsForm.getCollector())) { PdfPCell cell = createCell("For Collector : " + arReportsForm.getCollector(), headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); } else if (CommonUtils.isNotEmpty(arReportsForm.getCustomerNumber())) { PdfPCell cell = createCell("Customer Name : " + arReportsForm.getCustomerName(), headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); cell = createCell("Customer Number : " + arReportsForm.getCustomerNumber(), headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); } PdfPCell cell = createCell("Date From : " + arReportsForm.getFromDate(), headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); cell = createCell("Date To : " + arReportsForm.getToDate(), headerBoldFont11, Element.ALIGN_LEFT, Rectangle.NO_BORDER); headerTable.addCell(cell); }
From source file:com.orange.atk.atkUI.corecli.utils.PdfUtilities.java
License:Apache License
/** * Adds a logo to the given pdf file.//ww w . j a va2 s . co m * @param pdfFileName * @param imageFileName * @param x position for image * @param y position for image * @throws Exception */ public void addWatermark(String pdfFileName, String imageFileName, int x, int y) throws Exception { // 1. copy File tmpPDFFile = new File(tmpDir, "tmpPDF.pdf"); copyFile(new File(pdfFileName), tmpPDFFile); // 2. add watermark // we create a reader for a certain document PdfReader reader = new PdfReader(tmpPDFFile.getAbsolutePath()); int n = reader.getNumberOfPages(); // we create a stamper that will copy the document to a new file PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(pdfFileName)); // adding content to each page int i = 0; PdfContentByte under; Image img = Image.getInstance(imageFileName); img.setAbsolutePosition(x, y); while (i < n) { i++; // watermark under the existing page under = stamp.getUnderContent(i); under.addImage(img); } // closing PdfStamper will generate the new PDF file stamp.close(); }
From source file:com.orange.atk.compModel.PDFGenerator.java
License:Apache License
/** * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, interpreter.logger.DocumentLogger) *//*from w ww .j a v a 2 s.c o m*/ public void dumpInStream(boolean isParseErrorHappened, /*DocumentLogger dl,*/ org.w3c.dom.Document xmlDoc, Model model3) { long endTime = new Date().getTime(); // step 1: creation of a document-object Document document = new Document(); PdfWriter writer = null; // step 2: // we create a writer that listens to the document // and directs a PDF-stream to the outputStream try { writer = PdfWriter.getInstance(document, outputStream); } catch (DocumentException e1) { e1.printStackTrace(); return; } writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3: we open the document document.open(); document.addTitle("REPORT"); document.addCreationDate(); HeaderFooter headerPage = new HeaderFooter(new Phrase("ScreenShot report"), false); HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - ")); headerPage.setAlignment(Element.ALIGN_CENTER); footerPage.setAlignment(Element.ALIGN_CENTER); document.setHeader(headerPage); document.setFooter(footerPage); // Chapter 1 : Summary // Section 1 : Informations Chunk c = new Chunk("Summary"); c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c.setFont(FONT_PAR_TITLE); Paragraph title1 = new Paragraph(c); title1.setAlignment("CENTER"); title1.setLeading(20); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("Informations"); Section section1 = chapter1.addSection(title11); Paragraph pSum = new Paragraph(); pSum.add("Author : " + author); pSum.add(Chunk.NEWLINE); pSum.add("Group : " + group); pSum.add(Chunk.NEWLINE); pSum.add("Script : " + script); pSum.add(Chunk.NEWLINE); pSum.add("Reference directory: " + model3.getRefDirectory()); pSum.add(Chunk.NEWLINE); pSum.add("Test directory: " + model3.getTestDirectory()); pSum.add(Chunk.NEWLINE); SimpleDateFormat formatter = new SimpleDateFormat("MMMMM dd, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); pSum.add("Date : " + dateString); pSum.add(Chunk.NEWLINE); pSum.add(Chunk.NEWLINE); if (model3.getNbFail() > 0) { pSum.add(model3.getNbFail() + "/" + model3.getNbImages() + " images didn't succeed the test."); } else { pSum.add("All images (" + model3.getNbImages() + ") have succeed this comparaison."); } pSum.add(Chunk.NEWLINE); pSum.setIndentationLeft(20); section1.add(pSum); section1.add(new Paragraph(Chunk.NEXTPAGE)); try { document.add(chapter1); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); if (isParseErrorHappened) { document.close(); return; } // Add generated pictures Chunk c3 = new Chunk("ScreenShots"); c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c3.setFont(FONT_PAR_TITLE); Paragraph p3 = new Paragraph(c3); p3.setAlignment("CENTER"); p3.setLeading(20); Chapter chapter3 = new Chapter(p3, 1); chapter3.setNumberDepth(0); NodeList imgs = xmlDoc.getElementsByTagName("img"); for (int i = 0; i < imgs.getLength(); i++) { org.w3c.dom.Element eImg = (org.w3c.dom.Element) imgs.item(i); if (eImg.getElementsByTagName("Pass").item(0).getTextContent().equals(Model.FAIL)) { org.w3c.dom.Element eRef = (org.w3c.dom.Element) eImg.getElementsByTagName("Ref").item(0); org.w3c.dom.Element eTest = (org.w3c.dom.Element) eImg.getElementsByTagName("Test").item(0); Paragraph pScreen = new Paragraph(eTest.getAttributes().getNamedItem("name").getNodeValue() + " " + eImg.getElementsByTagName("Pass").item(0).getTextContent()); Section section31 = chapter3.addSection(pScreen); PdfPTable scTable = null; scTable = new PdfPTable(2); scTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); scTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); scTable.getDefaultCell().setPadding(5); if (new File(eRef.getTextContent()).exists()) { Image refImg; try { refImg = Image.getInstance(eRef.getTextContent()); refImg.scaleToFit(310, 260); refImg.setAlignment(Element.ALIGN_BASELINE); scTable.addCell(refImg); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (DOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (new File(eTest.getTextContent()).exists()) { Image testImg; try { BufferedImage bi = ImageIO.read(new File(eTest.getTextContent())); Graphics2D g2d = (Graphics2D) bi.getGraphics(); g2d.setStroke(new BasicStroke(1.5f)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f)); Boolean2D dif = model3.getCouplesComparaison().get(i).getDifWithMask(); // if (squarable){ g2d.setColor(Color.red); int w = bi.getWidth(); int h = bi.getHeight(); //TODO: Gurvan, Maybe we need to have the list of masks in the report? Mask mask = model3.getCouplesComparaison().get(i).getMaskSum(); //g2d.drawRect(0, 0, mask.getWidth()*2*sampleWidth, mask.getHeight()*2*sampleHeight); for (int x = 0; x < mask.getWidth(); x++) { for (int y = 0; y < mask.getHeight(); y++) { if (mask.getCell(x, y)) { g2d.setColor(Color.blue); ////Logger.getLogger(this.getClass() ).debug("grise"); g2d.fillRect(x * 2 * Mask.getCELL_HALF_SIZE(), y * 2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE()); } if (!dif.get(x, y)) { g2d.setColor(Color.green); g2d.fillRect(x * 2 * Mask.getCELL_HALF_SIZE(), y * 2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE(), 2 * Mask.getCELL_HALF_SIZE()); } } } testImg = Image.getInstance(bi, null); testImg.scaleToFit(310, 260); testImg.setAlignment(Element.ALIGN_BASELINE); scTable.addCell(testImg); section31.add(Chunk.NEWLINE); section31.add(scTable); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (DOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } section31.add(new Paragraph("Reference screenshot description : " + eImg.getElementsByTagName("RefDescription").item(0).getTextContent())); section31.add(Chunk.NEWLINE); section31 .add(new Paragraph("Mask : " + eImg.getElementsByTagName("Mask").item(0).getTextContent())); section31.add(Chunk.NEWLINE); section31.add(new Paragraph( "Comment : " + eImg.getElementsByTagName("Comment").item(0).getTextContent())); section31.add(new Paragraph(Chunk.NEXTPAGE)); } } try { document.add(chapter3); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // step 5: we close the document document.close(); }
From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
public void createHTMLFile(DocumentLogger dl) { File htmlfile = new File(dir + Platform.FILE_SEPARATOR + "report.html"); FileOutputStream out = null;// w w w .j a va 2s. c o m PrintStream ps = null; try { out = new FileOutputStream(htmlfile); ps = new PrintStream(out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); Logger.getLogger(this.getClass()).warn("Can't Create HTML file"); return; } ps.println("<html>"); ps.println("<body>"); long endTime = new Date().getTime(); ps.println("<span style=\"font-weight: bold;\">Summary</span>"); ps.println("<br>"); ps.println("Author : " + author); ps.println("<br>"); ps.println("Group : " + group); ps.println("<br>"); ps.println("Script : " + script); ps.println("<br>"); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); ps.println("Date : " + dateString); ps.println("<br>"); ps.println("<br>"); ps.println("<span style=\"font-weight: bold;\">Last logged lines :</span>"); ps.println("<br>"); ps.println("<br>"); List<Message> msgLogged = dl.getMsgsLogged(); int startIndex = msgLogged.size() > 5 ? msgLogged.size() - 5 : 0; for (int i = startIndex; i < msgLogged.size(); i++) { Message m = msgLogged.get(i); switch (m.getType()) { case Message.INFO_MSG: ps.println("INFO : " + m.getMessage()); ps.println("<br>"); break; case Message.WARN_MSG: ps.println(" <span style=\"color: rgb(255, 102, 0);\"> WARN : " + m.getMessage() + "</span>"); ps.println("<br>"); break; case Message.ERROR_MSG: ps.println(" <span style=\"color: red;\">ERROR : " + m.getMessage() + "</span>"); ps.println("<br>"); break; default: break; } } ps.println("<br>"); ps.println("<br>"); ps.println("<span style=\"font-weight: bold;\">Executive summary</span>"); ps.println("<br>"); // Chapter 2 : Log information ps.println("<span style=\"font-weight: bold;\">Log information:</span>"); ps.println("<br>"); // step 4: we add a paragraph to the document // logged messages for (int i = 0; i < msgLogged.size(); i++) { Message msg = msgLogged.get(i); formatter = new SimpleDateFormat("H:mm:ssSSS"); dateString = formatter.format(msg.getTimestamp()); switch (msg.getType()) { case Message.INFO_MSG: ps.println("[" + dateString + "] " + msg.getMessage()); ps.println("<br>"); break; case Message.WARN_MSG: ps.println(" <span style=\"color: rgb(255, 102, 0);\">[" + dateString + "] WARN : " + msg.getMessage() + " at line : " + msg.getLine() + "</span><br>"); ps.println("<br>"); break; case Message.ERROR_MSG: ps.println(" <span style=\"color: red;\">[" + dateString + "] ERROR : " + msg.getMessage() + " at line : " + msg.getLine() + "</span><br>"); ps.println("<br>"); break; default: break; } } // Add generated pictures ps.println("<span style=\"font-weight: bold;\">Graphics</span>"); ps.println("<br>"); Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } PlotList plotlist = mapint.get(cle); DecimalFormat df = new DecimalFormat("#,###.##"); ps.println("<br>"); if (plotlist.getType() == PlotList.TYPE_SUM) { ps.println("<span style=\"font-weight: bold;\">" + plotlist.getYComment() + ":" + " (Total : " + df.format(plotlist.getTotal() / plotlist.getScale()) + " " + plotlist.getunit() + ")</span>"); } else { // PlotList.TYPE_AVG ps.println("<span style=\"font-weight: bold;\">" + plotlist.getYComment() + ":" + " (Average : " + df.format(plotlist.getAverage() / plotlist.getScale()) + " " + plotlist.getunit() + ")</span>"); } ps.println("<br>"); ps.println("<br>"); ps.println("<img style=\"width: 640px; height: 480px;\" alt=\"\"title=\"" + cle + "\" src=\"" + cle + ".png\"><br> </span><br>"); } } ps.println("</body>"); ps.println("</html>"); ps.flush(); ps.close(); }
From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
public void createHTMLFileactionlog(ActionsLogger actionlog, DocumentLogger dl) { Vector VectAction = actionlog.getActions(); // step 2:/*ww w . j a va 2s . c o m*/ // we create a writer that listens to the document // and directs a PDF-stream to the outputStream File htmlfile = new File(dir + Platform.FILE_SEPARATOR + "report.html"); FileOutputStream out = null; PrintStream ps = null; try { out = new FileOutputStream(htmlfile); ps = new PrintStream(out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); Logger.getLogger(this.getClass()).warn("Can't Create PDF file"); return; } ps.println("<html>"); ps.println("<body>"); long endTime = new Date().getTime(); ps.println("<span style=\"font-weight: bold;\">Summary</span>"); ps.println("<br>"); ps.println("Author : " + author); ps.println("<br>"); ps.println("Group : " + group); ps.println("<br>"); ps.println("Script : " + script); ps.println("<br>"); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); ps.println("Date : " + dateString); ps.println("<br>"); ps.println("<br>"); ps.println("<span style=\"font-weight: bold;\">Last logged lines :</span>"); ps.println("<br>"); ps.println("<br>"); int startIndex = VectAction.size() > 5 ? VectAction.size() - 5 : 0; for (int i = startIndex; i < VectAction.size(); i++) { Action action = (Action) VectAction.get(i); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); dateString = spf.format(action.getStartTime()); ps.println("[ " + dateString + "] : " + action.getActionName()); ps.println("<br>"); } ps.println("<br>"); ps.println("<br>"); ps.println("<span style=\"font-weight: bold;\">Executive summary</span>"); ps.println("<br>"); // Chapter 2 : Log information ps.println("<span style=\"font-weight: bold;\">Log information:</span>"); ps.println("<br>"); // step 4: we add a paragraph to the document // logged messages for (int i = 0; i < VectAction.size(); i++) { // formatter = new SimpleDateFormat("H:mm:ssSSS"); Action action = (Action) VectAction.get(i); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); dateString = spf.format(action.getStartTime()); ps.println("[ " + dateString + "] : " + action.getActionName()); ps.println("<br>"); } // Add generated pictures ps.println("<span style=\"font-weight: bold;\">Graphics</span>"); ps.println("<br>"); Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } PlotList plotlist = mapint.get(cle); DecimalFormat df = new DecimalFormat("#,###.##"); ps.println("<br>"); if (plotlist.getType() == PlotList.TYPE_SUM) { ps.println("<span style=\"font-weight: bold;\">" + plotlist.getYComment() + ":" + " (Total : " + df.format(plotlist.getTotal() / plotlist.getScale()) + " " + plotlist.getunit() + ")</span>"); } else { // PlotList.TYPE_AVG ps.println("<span style=\"font-weight: bold;\">" + plotlist.getYComment() + ":" + " (Average : " + df.format(plotlist.getAverage() / plotlist.getScale()) + " " + plotlist.getunit() + ")</span>"); } ps.println("<br>"); ps.println("<br>"); ps.println("<img style=\"width: 640px; height: 480px;\" alt=\"\"title=\"" + cle + "\" src=\"" + cle + ".png\"><br> </span><br>"); } } ps.println("</body>"); ps.println("</html>"); ps.flush(); ps.close(); }
From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
/** * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, * com.orange.atk.results.logger.log.DocumentLogger) *//*from w w w. j a va 2s . co m*/ public void dumpInStream(boolean isParseErrorHappened, DocumentLogger dl) { long endTime = new Date().getTime(); // step 1: creation of a document-object Document document = new Document(); PdfWriter writer = null; // step 2: // we create a writer that listens to the document // and directs a PDF-stream to the outputStream try { writer = PdfWriter.getInstance(document, outputStream); } catch (DocumentException e1) { e1.printStackTrace(); return; } writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document List<Message> msgLogged = dl.getMsgsLogged(); Paragraph pLoggedMsg = new Paragraph(); // logged messages for (int i = 0; i < msgLogged.size(); i++) { Message msg = msgLogged.get(i); SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); String dateString = formatter.format(msg.getTimestamp()); switch (msg.getType()) { case Message.INFO_MSG: pLoggedMsg.add("[" + dateString + "] " + msg.getMessage()); break; case Message.WARN_MSG: pLoggedMsg.add("[" + dateString + "] WARN : " + msg.getMessage() + " at line : " + msg.getLine()); break; case Message.ERROR_MSG: pLoggedMsg.add("[" + dateString + "] ERROR : " + msg.getMessage() + " at line : " + msg.getLine()); break; default: break; } pLoggedMsg.add(Chunk.NEWLINE); } Paragraph pLastLogguedLines = new Paragraph(); int startIndex = msgLogged.size() > 5 ? msgLogged.size() - 5 : 0; for (int i = startIndex; i < msgLogged.size(); i++) { Message m = msgLogged.get(i); switch (m.getType()) { case Message.INFO_MSG: pLastLogguedLines.add("INFO : " + m.getMessage()); break; case Message.WARN_MSG: pLastLogguedLines.add("WARN : " + m.getMessage()); break; case Message.ERROR_MSG: pLastLogguedLines.add("ERROR : " + m.getMessage()); break; default: break; } pLastLogguedLines.add(Chunk.NEWLINE); } // l.setIndentationLeft(40); // Min/Max/Ave values /* * PdfPTable table = new PdfPTable(4); table.addCell(""); * table.addCell("Min"); table.addCell("Max"); table.addCell("Avg"); * * * table.addCell("Battery in %"); table.addCell(String.valueOf(dl * .getMinValueFromList(dl.getplt("BATTERY")))); * table.addCell(String.valueOf(dl * .getMaxValueFromList(dl.getplt("BATTERY")))); * table.addCell(String.valueOf(dl * .getAveValueFromList(dl.getplt("BATTERY")))); * table.addCell("Storage in bytes"); table.addCell(String.valueOf(dl * .getMinValueFromList(dl.getplt("Storage")))); * table.addCell(String.valueOf(dl * .getMaxValueFromList(dl.getplt("Storage")))); * table.addCell(String.valueOf(dl * .getAveValueFromList(dl.getplt("Storage")))); */ document.addTitle("REPORT"); document.addCreationDate(); HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false); HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - ")); headerPage.setAlignment(Element.ALIGN_CENTER); footerPage.setAlignment(Element.ALIGN_CENTER); document.setHeader(headerPage); document.setFooter(footerPage); // Chapter 1 : Summary // Section 1 : Informations Chunk c = new Chunk("Summary"); c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c.setFont(FONT_PAR_TITLE); Paragraph title1 = new Paragraph(c); title1.setAlignment("CENTER"); title1.setLeading(20); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("Informations"); Section section1 = chapter1.addSection(title11); Paragraph pSum = new Paragraph(); pSum.add("Author : " + author); pSum.add(Chunk.NEWLINE); pSum.add("Group : " + group); pSum.add(Chunk.NEWLINE); pSum.add("Script : " + script); pSum.add(Chunk.NEWLINE); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); pSum.add("Date : " + dateString); pSum.add(Chunk.NEWLINE); pSum.setIndentationLeft(20); section1.add(pSum); section1.add(new Paragraph(Chunk.NEXTPAGE)); Chunk c11 = new Chunk("Executive summary"); c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c11.setFont(FONT_PAR_TITLE); Paragraph title12 = new Paragraph(c11); Section section12 = chapter1.addSection(title12); Paragraph pExecSum = new Paragraph(); // pExecSum.add("Value : "); // pExecSum.add(Chunk.NEWLINE); // pExecSum.add(table); pExecSum.add(Chunk.NEWLINE); pExecSum.add("Last logged lines : "); pExecSum.add(Chunk.NEWLINE); pExecSum.add(pLastLogguedLines); pExecSum.add(Chunk.NEWLINE); pExecSum.setIndentationLeft(20); section12.add(pExecSum); try { document.add(chapter1); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // Chapter 2 : Log information Chunk c2 = new Chunk("Log information"); c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c2.setFont(FONT_PAR_TITLE); Paragraph title2 = new Paragraph(c2); title2.setAlignment("CENTER"); title2.setLeading(20); Chapter chapter2 = new Chapter(title2, 1); chapter2.setNumberDepth(0); Section section2 = chapter2.addSection("Log"); // Add log information section2.add(pLoggedMsg); section2.add(Chunk.NEWLINE); // section2.add(table); try { document.add(chapter2); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); if (isParseErrorHappened) { document.close(); return; } // Add generated pictures Chunk c3 = new Chunk("Graphics"); c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c3.setFont(FONT_PAR_TITLE); Paragraph p3 = new Paragraph(c3); p3.setAlignment("CENTER"); p3.setLeading(20); Chapter chapter3 = new Chapter(p3, 1); chapter3.setNumberDepth(0); // add current graph Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); Paragraph pCPUimg = new Paragraph(cle); Section section31 = chapter3.addSection(pCPUimg); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (jpg1 == null) { Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null"); return; } // jpg1.setRotationDegrees(270); jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); section31.add(jpg1); PlotList plotlist = mapint.get(cle); DecimalFormat df = new DecimalFormat("#,###.##"); if (plotlist.getType() == PlotList.TYPE_SUM) { section31.add(new Paragraph("Total : " + df.format(plotlist.getTotal() / plotlist.getScale()) + " " + plotlist.getunit())); } else { // PlotList.TYPE_AVG section31.add(new Paragraph("Average : " + df.format(plotlist.getAverage() / plotlist.getScale()) + " " + plotlist.getunit())); } } section31.add(new Paragraph(Chunk.NEXTPAGE)); } /* * // Section 3.1 : CPU data Paragraph pCPUimg = new * Paragraph("CPU data"); Section section31 = * chapter3.addSection(pCPUimg); if (new * File(dl.getPNGpath("CPU")).exists()) { Image jpg1 = null; try { jpg1 * = Image.getInstance(dl.getPNGpath("CPU")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg1.setRotationDegrees(270); * jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); * section31.add(jpg1); } section31.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.2 : BAT data Paragraph pBATimg = new * Paragraph("Battery data"); Section section32 = * chapter3.addSection(pBATimg); if (new * File(dl.getPNGpath("BATTERY")).exists()) { Image jpg2 = null; try { * jpg2 = Image.getInstance(dl.getPNGpath("BATTERY")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg2.setRotationDegrees(270); * jpg2.scalePercent(75); jpg2.setAlignment(Element.ALIGN_CENTER); * section32.add(jpg2); } section32.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.3 : MEM data Paragraph pMEMimg = new * Paragraph("Memory data"); Section section33 = * chapter3.addSection(pMEMimg); if (new * File(dl.getPNGpath("MEMORY")).exists()) { * * Image jpg3 = null; try { jpg3 = * Image.getInstance(dl.getPNGpath("MEMORY")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg3.setRotationDegrees(270); * jpg3.scalePercent(75); jpg3.setAlignment(Element.ALIGN_CENTER); * section33.add(jpg3); } section33.add(new Paragraph(Chunk.NEXTPAGE)); * * // Section 3.4 : STO data Paragraph pSTOimg = new * Paragraph("Storage data"); Section section34 = * chapter3.addSection(pSTOimg); if (new * File(dl.getPNGpath("Storage")).exists()) { * * Image jpg4 = null; try { jpg4 = * Image.getInstance(dl.getPNGpath("Storage")); } catch * (BadElementException e) { e.printStackTrace(); } catch * (MalformedURLException e) { e.printStackTrace(); } catch (IOException * e) { e.printStackTrace(); } //jpg4.setRotationDegrees(270); * jpg4.scalePercent(75); jpg4.setAlignment(Element.ALIGN_CENTER); * section34.add(jpg4); } * * * // Section 3.5 : Network connection //Paragraph pNetworkimg = new * Paragraph("Network QoS data"); //Section section35 = * chapter3.addSection(pNetworkimg); // if (new * File(dl.getNetworkPNGfile()).exists()) { * * // Image jpg5 = null; // try { // jpg5 = * Image.getInstance(dl.getNetworkPNGfile()); // } catch * (BadElementException e) { // e.printStackTrace(); // } catch * (MalformedURLException e) { // e.printStackTrace(); // } catch * (IOException e) { // e.printStackTrace(); // } * //jpg4.setRotationDegrees(270); // jpg5.scalePercent(75); // * jpg5.setAlignment(Element.ALIGN_CENTER); // section35.add(jpg5); //} */ try { document.add(chapter3); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // if (isTableEnabled) { // // Add tables filled with measurement // // Chapter 4 : Measurement tables // Chunk c4 = new Chunk("Statistics tables"); // c4.setBackground(new Color(0xFF, 0x66, 0x00), 200, 3f, 200f, 3f); // c4.setFont(FontFactory.getFont(BaseFont.HELVETICA, // BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 16)); // Paragraph title4 = new Paragraph(c4); // title4.setAlignment("CENTER"); // title4.setLeading(20); // Chapter chapter4 = new Chapter(title4, 1); // chapter4.setNumberDepth(0); // // // Section 4.1 : Battery value // Paragraph titleSection41 = new Paragraph("Battery value"); // Section section41 = chapter4.addSection(titleSection41); // Paragraph pBatList = new Paragraph(); // pBatList.add(Chunk.NEWLINE); // pBatList.add(createPDFTableFromList(dl // .getList(DocumentLogger.BATTERY), "Battery")); // pBatList.setAlignment("CENTER"); // section41.add(pBatList); // // // Section 4.2 : CPU value // Paragraph titleSection42 = new Paragraph("CPU value"); // Section section42 = chapter4.addSection(titleSection42); // Paragraph pCPUList = new Paragraph(); // pCPUList.add(Chunk.NEWLINE); // pCPUList.add(createPDFTableFromList(dl.getList(DocumentLogger.CPU), // "CPU")); // pCPUList.setAlignment("CENTER"); // section42.add(pCPUList); // // // Section 4.3 : Memory value // Paragraph titleSection43 = new Paragraph("Memory value"); // Section section43 = chapter4.addSection(titleSection43); // Paragraph pMemList = new Paragraph(); // pMemList.add(Chunk.NEWLINE); // pMemList.add(createPDFTableFromList(dl // .getList(DocumentLogger.MEMORY), "Memory")); // pMemList.setAlignment("CENTER"); // section43.add(pMemList); // // // Section 4.4 : Storage value // Paragraph titleSection44 = new Paragraph("Storage value"); // Section section44 = chapter4.addSection(titleSection44); // Paragraph pStoList = new Paragraph(); // pStoList.add(Chunk.NEWLINE); // pStoList.add(createPDFTableFromList(dl // .getList(DocumentLogger.STORAGE), "Storage")); // pStoList.setAlignment("CENTER"); // section44.add(pStoList); // // try { // document.add(chapter4); // } catch (DocumentException e) { // e.printStackTrace(); // } // } // step 5: we close the document document.close(); createHTMLFile(dl); }
From source file:com.orange.atk.results.logger.documentGenerator.PDFGenerator.java
License:Apache License
public void dumpInStreamactionlogger(boolean isParseErrorHappened, ActionsLogger actionlog, DocumentLogger dl) { long endTime = new Date().getTime(); // step 1: creation of a document-object Document document = new Document(); PdfWriter writer = null;//from w w w . ja v a 2 s. co m Vector VectAction = actionlog.getActions(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to the outputStream try { writer = PdfWriter.getInstance(document, outputStream); } catch (DocumentException e1) { e1.printStackTrace(); return; } writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document Paragraph pLoggedMsg = new Paragraph(); // logged messages for (int i = 0; i < VectAction.size(); i++) { Action action = (Action) VectAction.get(i); SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); String dateString = spf.format(action.getStartTime()); pLoggedMsg.add("[" + dateString + "] : " + action.getActionName()); pLoggedMsg.add(Chunk.NEWLINE); } Paragraph pLastLogguedLines = new Paragraph(); int startIndex = VectAction.size() > 5 ? VectAction.size() - 5 : 0; for (int i = startIndex; i < VectAction.size(); i++) { Action action = (Action) VectAction.get(i); // SimpleDateFormat formatter = new SimpleDateFormat("H:mm:ssSSS"); SimpleDateFormat spf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS"); String dateString = spf.format(action.getStartTime()); pLastLogguedLines.add("[" + dateString + "] : " + action.getActionName()); pLastLogguedLines.add(Chunk.NEWLINE); } document.addTitle("REPORT"); document.addCreationDate(); HeaderFooter headerPage = new HeaderFooter(new Phrase("Execution report"), false); HeaderFooter footerPage = new HeaderFooter(new Phrase(" - "), new Phrase(" - ")); headerPage.setAlignment(Element.ALIGN_CENTER); footerPage.setAlignment(Element.ALIGN_CENTER); document.setHeader(headerPage); document.setFooter(footerPage); // Chapter 1 : Summary // Section 1 : Informations Chunk c = new Chunk("Summary"); c.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c.setFont(FONT_PAR_TITLE); Paragraph title1 = new Paragraph(c); title1.setAlignment("CENTER"); title1.setLeading(20); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("Informations"); Section section1 = chapter1.addSection(title11); Paragraph pSum = new Paragraph(); pSum.add("Author : " + author); pSum.add(Chunk.NEWLINE); pSum.add("Group : " + group); pSum.add(Chunk.NEWLINE); pSum.add("Script : " + script); pSum.add(Chunk.NEWLINE); SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy - hh:mm aaa"); String dateString = formatter.format(endTime); pSum.add("Date : " + dateString); pSum.add(Chunk.NEWLINE); pSum.setIndentationLeft(20); section1.add(pSum); section1.add(new Paragraph(Chunk.NEXTPAGE)); Chunk c11 = new Chunk("Executive summary"); c11.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c11.setFont(FONT_PAR_TITLE); Paragraph title12 = new Paragraph(c11); Section section12 = chapter1.addSection(title12); Paragraph pExecSum = new Paragraph(); // pExecSum.add("Value : "); // pExecSum.add(Chunk.NEWLINE); // pExecSum.add(table); pExecSum.add(Chunk.NEWLINE); pExecSum.add("Last logged lines : "); pExecSum.add(Chunk.NEWLINE); pExecSum.add(pLastLogguedLines); pExecSum.add(Chunk.NEWLINE); pExecSum.setIndentationLeft(20); section12.add(pExecSum); try { document.add(chapter1); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); // Chapter 2 : Log information Chunk c2 = new Chunk("Log information"); c2.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c2.setFont(FONT_PAR_TITLE); Paragraph title2 = new Paragraph(c2); title2.setAlignment("CENTER"); title2.setLeading(20); Chapter chapter2 = new Chapter(title2, 1); chapter2.setNumberDepth(0); Section section2 = chapter2.addSection("Log"); // Add log information section2.add(pLoggedMsg); section2.add(Chunk.NEWLINE); // section2.add(table); try { document.add(chapter2); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); if (isParseErrorHappened) { document.close(); return; } // Add generated pictures Chunk c3 = new Chunk("Graphics"); c3.setBackground(ORANGE_COLOR, 200, 3f, 200f, 3f); c3.setFont(FONT_PAR_TITLE); Paragraph p3 = new Paragraph(c3); p3.setAlignment("CENTER"); p3.setLeading(20); Chapter chapter3 = new Chapter(p3, 1); chapter3.setNumberDepth(0); // add current graph Map<String, PlotList> mapint = dl.getMapint(); Set<String> cles = mapint.keySet(); Iterator<String> it = cles.iterator(); while (it.hasNext()) { String cle = (String) it.next(); Paragraph pCPUimg = new Paragraph(cle); Section section31 = chapter3.addSection(pCPUimg); if (new File(dl.getPNGpath(cle)).exists()) { Image jpg1 = null; try { jpg1 = Image.getInstance(dl.getPNGpath(cle)); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (jpg1 == null) { Logger.getLogger(this.getClass()).warn("Error when Creating image jpg1 is null"); return; } // jpg1.setRotationDegrees(270); jpg1.scalePercent(75); jpg1.setAlignment(Element.ALIGN_CENTER); section31.add(jpg1); } section31.add(new Paragraph(Chunk.NEXTPAGE)); } try { document.add(chapter3); } catch (DocumentException e) { e.printStackTrace(); } document.newPage(); document.close(); createHTMLFileactionlog(actionlog, dl); }
From source file:com.pfe.web.UtilisateurControler.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();//from w ww .j av a2 s. c om pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "pdfs.png"; pdf.add(Image.getInstance(logo)); }
From source file:com.preparatic.archivos.PdfGenerator.java
License:Apache License
/** * Genera un pdf para las preguntas y otro para las soluciones. * // w w w .j av a 2 s . c o m * @throws Exception */ public String guardarPDF() throws Exception { // Abrir documentos docpregs = new Document(); docsols = new Document(); String pregsFilename = FactoriaArchivo.pdfTestFilename(test.getTipoTest(), test.getIdBloqueTematicaAnho(), test.getIdTest()); PdfWriter writerPregs = PdfWriter.getInstance(docpregs, FactoriaArchivo.pdfTest(test.getTipoTest(), test.getIdBloqueTematicaAnho(), test.getIdTest())); TestFooter footerPregs = new TestFooter(test.getTitulo()); //mod_AZ_2018-02-04 writerPregs.setPageEvent(footerPregs); PdfWriter.getInstance(docsols, FactoriaArchivo.pdfSol(test.getTipoTest(), test.getIdBloqueTematicaAnho(), test.getIdTest())); docpregs.open(); docsols.open(); docpregs.setMargins(80, 80, 72, 36); docsols.setMargins(80, 80, 36, 36); // Aadir logo Image gif = Image.getInstance(ConfigProperties.getProperty("files.rootDir") + "/images/logo-alpha.png"); //mod_AZE_2018-02-04 (logo con fondo blanco) gif.setAlignment(Image.LEFT); gif.scaleAbsolute(148, 46); //mod_AZE_2018-02-04 (para que entre bien el logo nuevo) docpregs.add(gif); docsols.add(gif); ponerTitulo(docpregs, docsols); // Adimos las preguntas al documento de preguntas docpregs.add(listaPreguntas); /* * Aadimos las respuestas, en varias columnas al documento de * respuestas. */ MultiColumnText multiColumnTextSoluciones = new MultiColumnText(); multiColumnTextSoluciones.addRegularColumns(docsols.left(), docsols.right(), 20f, Integer.parseInt(ConfigProperties.getProperty("tests.solucion.columnas"))); multiColumnTextSoluciones.addElement(listaSoluciones); docsols.add(multiColumnTextSoluciones); // Cerramos los documentos docpregs.close(); docsols.close(); return pregsFilename; }