List of usage examples for com.lowagie.text Rectangle NO_BORDER
int NO_BORDER
To view the source code for com.lowagie.text Rectangle NO_BORDER.
Click Source Link
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void addTotal(String[] data) throws DocumentException { // add dashed line... for (String value : data) { String v = null;//from www. ja v a 2 s. com String rawValue = value(value); if (StringUtils.isNotEmpty(rawValue)) { v = line(rawValue, SINGLE_LINE); } PdfPCell c1 = new PdfPCell(new Phrase(v, font)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(alignment(value)); setCellPadding(c1); detailTable.addCell(c1); } // add totals.... for (String value : data) { PdfPCell c1 = new PdfPCell(new Phrase(value(value), font)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(alignment(value)); setCellPadding(c1); detailTable.addCell(c1); } // add blank line.... for (String value : data) { String v = null; String rawValue = value(value); if (StringUtils.isNotEmpty(rawValue)) { v = line(rawValue, DOUBLE_LINE); } PdfPCell c1 = new PdfPCell(new Phrase(v, font)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(alignment(value)); setCellPadding(c1); detailTable.addCell(c1); } }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createColHeadings(String[] cols) throws DocumentException { createTable(cols.length);/*from w w w . jav a 2 s. co m*/ for (String col : cols) { PdfPCell c1 = new PdfPCell(new Phrase(value(col), font)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(alignment(col)); setCellPadding(c1); c1.setPaddingBottom(5); detailTable.addCell(c1); } }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createFootings(String footing) throws DocumentException { String[] cols = footing.split(ReportProcessor.ALIGN_DELIMITER, 3); float[] colSizes = new float[] { 25, 50, 25 }; footerTable = new PdfPTable(colSizes); footerTable.setWidthPercentage(getHeadingWidth()); int count = 0; for (String c : cols) { PdfPCell c1 = new PdfPCell(new Phrase(value(c), font)); c1.setBorder(Rectangle.NO_BORDER); int alignment = Element.ALIGN_CENTER; if (count == 0) { alignment = Element.ALIGN_LEFT; } else if (count == 2) { alignment = Element.ALIGN_RIGHT; }/*from w w w . j ava2s . co m*/ c1.setHorizontalAlignment(alignment); setCellPadding(c1); footerTable.addCell(c1); count++; } }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createHeading(String heading) throws DocumentException { String[] cols = heading.split(ReportProcessor.ALIGN_DELIMITER, 3); PdfPTable table = new PdfPTable(cols.length); table.setWidthPercentage(getHeadingWidth()); int count = 0; for (String c : cols) { PdfPCell c1 = new PdfPCell(new Phrase(value(c), font)); c1.setBorder(Rectangle.NO_BORDER); int alignment = Element.ALIGN_CENTER; if (count == 0) { alignment = Element.ALIGN_LEFT; } else if (count == 2) { alignment = Element.ALIGN_RIGHT; }/* ww w . j a va 2 s .c o m*/ c1.setHorizontalAlignment(alignment); setCellPadding(c1); table.addCell(c1); count++; } document.add(table); }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createTable(int cols) throws DocumentException { if (colWidths != null) { detailTable = createTableWithAbsoluteWidths(); } else {//from w ww .j ava2s . co m detailTable = new PdfPTable(cols); detailTable.setWidthPercentage(getWidth()); } detailTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); }
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;// w w w .j a 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.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public PdfPCell getEmployeeAndEmployerDetails(User user, Empprofile empprofile, Useraccount useraccount, Company company, PayrollHistory payrollHistory, DateFormat sdf, int border, List<PayrollHistory> list, Map<String, Double> mapEPF, HttpServletRequest request) { PdfPTable mainTable = new PdfPTable(1); PdfPCell mainCell = null;//from w ww . j av a 2 s . co m try { String currencySymbol = getCurrencySymbol(request, false); int paddingTop = 5; int paddingBottom = 5; mainTable.setWidths(new float[] { 100 }); PdfPCell cell1 = null; PdfPTable table1 = new PdfPTable(4); table1.setWidths(new float[] { 14, 36, 25, 25 }); table1.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.reference.no", null, RequestContextUtils.getLocale(request)) + ".", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.this.period", null, RequestContextUtils.getLocale(request)) + " ( " + currencySymbol + " )", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.year.to.date", null, RequestContextUtils.getLocale(request)) + " ( " + currencySymbol + " )", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell1 = new PdfPCell(table1); mainTable.addCell(cell1); cell1.setBorder(border); PdfPCell cell2 = null; PdfPTable table2 = new PdfPTable(7); table2.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell2 = new PdfPCell(table2); mainTable.addCell(cell2); cell2.setBorder(border); String paidEPF = " "; String currentEPF = " "; if (mapEPF != null) { if (mapEPF.get("paidEPF") > 0) { paidEPF = currencyFormat.format(mapEPF.get("paidEPF")); } if (mapEPF.get("currentEPF") > 0) { currentEPF = currencyFormat.format(mapEPF.get("currentEPF")); } } PdfPCell cell3 = null; PdfPTable table3 = new PdfPTable(7); table3.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table3.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.common.epf", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(currentEPF, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(paidEPF, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell3 = new PdfPCell(table3); mainTable.addCell(cell3); cell3.setBorder(border); PdfPCell cell4 = null; PdfPTable table4 = new PdfPTable(7); table4.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table4.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.common.socso", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell4 = new PdfPCell(table4); mainTable.addCell(cell4); cell4.setBorder(border); double currenttax = payrollHistory.getIncometaxAmount(); String currentTax = " "; if (currenttax > 0) { currentTax = currencyFormat.format(currenttax); } HrmsCommonPayroll hrmsCommonPayroll = new HrmsCommonPayroll(); double paidtax = hrmsCommonPayroll.getPaidTax(list, payrollHistory); String paidTax = " "; if (paidtax > 0) { paidTax = currencyFormat.format(paidtax); } PdfPCell cell5 = null; PdfPTable table5 = new PdfPTable(7); table5.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table5.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.payroll.tax", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(currentTax, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(paidTax, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell5 = new PdfPCell(table5); mainTable.addCell(cell5); cell5.setBorder(border); PdfPCell cell6 = null; PdfPTable table6 = new PdfPTable(7); table6.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell6 = new PdfPCell(table6); mainTable.addCell(cell6); cell6.setBorder(border); mainCell = new PdfPCell(mainTable); mainCell.setBorder(Rectangle.NO_BORDER); } catch (Exception e) { e.printStackTrace(); } return mainCell; }
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);/*w ww .ja v a2 s .c o 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.compModel.PDFGenerator.java
License:Apache License
/** * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, interpreter.logger.DocumentLogger) *//* ww w .j a v a 2 s .co 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.prime.location.billing.InvoicedBillingManager.java
/** * Print invoice//from ww w . j a v a2 s . c om */ public void printInvoice() { try { //catch better your exceptions, this is just an example FacesContext context = FacesContext.getCurrentInstance(); Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f); String fileName = "PDFFile"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(pdf, baos); TableHeader event = new TableHeader(); event.setHeader("Header Here"); writer.setPageEvent(event); if (!pdf.isOpen()) { pdf.open(); } PdfPCell cell; PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 }); cell = new PdfPCell(new Paragraph("INVOICE", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); header.setTotalWidth(527); header.setLockedWidth(true); cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription())); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId())); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); cell = new PdfPCell( new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate()))); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); pdf.add(header); PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 }); table.setSpacingBefore(15f); table.setTotalWidth(527); table.setLockedWidth(true); //table.setWidths(new int[]{3, 1, 1}); table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY); table.addCell("Date"); table.addCell("Name"); table.addCell("Service"); table.addCell("Rate"); table.getDefaultCell().setBackgroundColor(null); cell = new PdfPCell(new Phrase("Total(US$): ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); // There are three special rows table.setHeaderRows(2); // One of them is a footer table.setFooterRows(1); Font f = FontFactory.getFont(FontFactory.HELVETICA, 10); //add remaining for (AgencyBilling billing : selectedInvoice.getBillings()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setIndent(2); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f)); table.addCell(new Phrase(billing.getPerson().getName(), f)); table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f)); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } pdf.add(table); writer.getAcroForm().setNeedAppearances(true); //document.add(new Phrase(TEXT)); //Keep modifying your pdf file (add pages and more) pdf.close(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception e) { //e.printStackTrace(); } }