List of usage examples for com.lowagie.text HeaderFooter HeaderFooter
public HeaderFooter(Phrase before, boolean numbered)
Header
-object with a pagenumber at the end. From source file:com.kahlon.guard.controller.DocumentManager.java
/** * * @param document/*from www .j a v a2 s . co m*/ */ public void preProcessPDF(Object document) { try { BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.setMargins(5f, 5f, 10f, 5f); // headers and footers must be added before the document is opened HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); pdf.setFooter(footer); // HeaderFooter header = new HeaderFooter( // new Phrase("This is a header without a page number", new Font(bf_courier)), false); // header.setAlignment(Element.ALIGN_CENTER); // pdf.setHeader(header); pdf.open(); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); pdf.add(Image.getInstance(logo)); Person person = context.getSelectedPerson().getDisplayPerson(); String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName(); String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge()); String gender = FacesMessageUtil.getMessage("person.gender") + " : " + person.getGender().getDescription(); String race = FacesMessageUtil.getMessage("person.ethnicity") + " : " + person.getEthnicity().getDescription(); Person rootPerson = person.getRootPerson(); PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId()); Image imgb = Image.getInstance(imgp.getContent()); imgb.scaleToFit(100, 120); PdfPTable headerTable = new PdfPTable(2); PdfPTable personTable = new PdfPTable(1); personTable.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(name)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(age)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(gender)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(race)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.setText(Integer.toString(person.getId())); Image img = pdf417.getImage(); img.scalePercent(150, 60 * pdf417.getYHeight()); cell = new PdfPCell(img); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(15); personTable.addCell(cell); cell.addElement(personTable); headerTable.addCell(cell); cell = new PdfPCell(imgb); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(cell); headerTable.setSpacingAfter(15); pdf.add(headerTable); LineSeparator lineSeparator = new LineSeparator(); lineSeparator.setPercentage(82); pdf.add(lineSeparator); Paragraph space = new Paragraph(); space.add(""); space.setSpacingAfter(15); pdf.add(space); } catch (IOException e) { logger.log(Level.INFO, e.getMessage()); } catch (BadElementException e) { logger.log(Level.INFO, e.getMessage()); } catch (DocumentException e) { logger.log(Level.INFO, e.getMessage()); } catch (Exception e) { logger.log(Level.INFO, e.getMessage()); } }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getInvoiceForm1(String invoice) { ByteArrayOutputStream os = null; try {/*from w w w . j av a 2s . c om*/ os = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document, os); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document.setFooter(temp); document.open(); JSONObject jbj = new JSONObject(invoice); String currency = ""; com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ids[] = { "name", "address", "invoiceno", "paymentdate" }; String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } PdfPTable tableinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(2); Font font1 = FontFactory.getFont("Helvetica", 24, Font.BOLD, Color.BLACK); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableinfo.addCell(cell1); tableinfo = addspace(1, tableinfo); tableinfo = addspace(4, tableinfo); cell1 = new PdfPCell(new Paragraph("INVOICE", font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableinfo.addCell(cell1); tableinfo = addspace(2, tableinfo); table = addspace(1, table); // cell1 = new PdfPCell(new Paragraph(uinfo[uinfo.length - 1],font9)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableinfo.addCell(cell1); // tableinfo = addspace(1, tableinfo); // tableinfo = addspace(2, tableinfo); cell1 = new PdfPCell(tableinfo); cell1.setBorder(0); table.addCell(cell1); PdfPTable tb = new PdfPTable(1); document.add(new Paragraph("\u00a0")); tableinfo = addspace(1, tableinfo); Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font2 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); //Font font3 = FontFactory.getFont("Helvetica", 8, Font.ITALIC, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); PdfPCell c1 = null; c1 = new PdfPCell(new Paragraph("Bill To :", font2)); c1.setBorder(0); tb.addCell(c1); for (int i = 0; i < 2; i++) { PdfPCell c = null; if (i == 0) c = new PdfPCell(new Paragraph(uinfo[i], font11)); else c = new PdfPCell(new Paragraph(uinfo[i])); //c.(20); c.setBorder(0); tb.addCell(c); } PdfPCell c = new PdfPCell(tb); c.setBorder(0); table.addCell(c); PdfPTable tb1 = new PdfPTable(1); for (int i = 2; i < 4; i++) { PdfPTable nested1 = new PdfPTable(3); c = new PdfPCell(); c.setBorder(0); c.setPaddingRight(5); nested1.addCell(c); c = new PdfPCell(new Paragraph(invoiceheadings[i], font)); c.setBorder(0); nested1.addCell(c); c = new PdfPCell(new Paragraph(uinfo[i], font2)); c.setBorder(0); c.setHorizontalAlignment(Element.ALIGN_RIGHT); //c.setPaddingLeft(5); nested1.addCell(c); c = new PdfPCell(nested1); c.setBorder(0); tb1.addCell(c); } PdfPCell c2 = new PdfPCell(tb1); c2.setBorder(0); table.addCell(c2); PdfPTable tb2 = new PdfPTable(new float[] { 60, 40 }); /* for (int i = 6; i < 7; i++) { PdfPTable tb3 = new PdfPTable(2);//new float[]{20, 40}); tb3.setWidths(new int[]{1, 3}); c2 = new PdfPCell(new Paragraph(invoiceheadings[i], font)); c2.setBorder(0); tb3.addCell(c2); c2 = new PdfPCell(new Paragraph(uinfo[i])); c2.setBorder(0); tb3.addCell(c2); c2 = new PdfPCell(tb3); c2.setBorder(0); c2.setHorizontalAlignment(Element.ALIGN_LEFT); tb2.addCell(c2); tb2 = addspace(1, tb2); } */ PdfPTable maintable = new PdfPTable(1); c2 = new PdfPCell(table); c2.setBorder(0); maintable.addCell(c2); maintable = addspace(0, maintable); c2 = new PdfPCell(tb2); c2.setBorder(0); maintable.addCell(c2); document.add(maintable); //for (int i = 0; i < 2; i++) { document.add(new Paragraph("\u00a0")); //} String[] colwidth2 = { "Subscription date", "Description", "Rate ($/Project)", "Amount ($)" }; PdfPTable table1 = new PdfPTable(4); table1.setWidths(new float[] { 2, 3, 1, 1 }); for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); cell.setBorder(0); if (i != 1) { cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); } if (i == 3) { cell.setBorderWidthLeft(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } cell.setBorderWidthTop(1); cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setBorderWidthBottom(1); cell.setPaddingBottom(5); cell.setPaddingTop(5); table1.addCell(cell); } //table1.setHeaderRows(1); double d = 0; String[] di = { "billdate", "description", "rate", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { currency = "USD";//gridinfo.getJSONObject(i).getString("currency"); PdfPCell cell = null; for (int j = 0; j < di.length; j++) { if (j == 3) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(di[j]))), font2)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell = new PdfPCell(new Paragraph(gridinfo.getJSONObject(i).getString(di[j]), font2)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } cell.setBorder(0); if (j != 1) { cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); } if (j == 3) { cell.setBorder(0); cell.setBorderWidthRight(1); } cell.setPaddingTop(10); cell.setFixedHeight(100); table1.addCell(cell); } d += Double.parseDouble(gridinfo.getJSONObject(i).getString(di[3])); } PdfPCell cell = null; cell = new PdfPCell(new Paragraph(" ", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(0); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" ", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(0); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" Total", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(0); cell.setPaddingBottom(5); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" " + df.format(d), font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table1.addCell(cell); EnglishDecimalFormat f1 = new EnglishDecimalFormat(); if (currency.equals("USD")) { cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); } else { cell = new PdfPCell(new Paragraph(CurrencyConvert(currency, d), font)); } cell.setColspan(4); cell.setBorder(0); //cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table1.addCell(cell); document.add(table1); document.add(new Paragraph("\u00a0")); PdfPTable inst = new PdfPTable(1); // for (int i = 0; i < Inst1.length; i++) { // c2 = new PdfPCell(new Paragraph(Inst1[i])); // c2.setBorder(0); // inst.addCell(c2); // } document.add(inst); document.close(); writer.close(); os.close(); } // catch (ConfigurationException ex) { // Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); // } catch (JSONException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception exp) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, exp); } return os; }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getReceiptAcc1(String ackrecp) { ByteArrayOutputStream os = null; try {/* w w w . j av a 2 s . co m*/ os = new ByteArrayOutputStream(); JSONObject jbj = new JSONObject(ackrecp); com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ginfo[] = new String[gridinfo.length() * 2]; String ids[] = { "name", "receiptno", "paymentdate", "address" }; String currency = "USD"; // String address = jbj.getString("address"); String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); Font font3 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); //Font font4 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font12 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); Document document1 = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document1, os); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document1.setFooter(temp); document1.open(); PdfPTable tableHinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(1); font3.setStyle(Font.UNDERLINE); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); // img.scalePercent(90); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setPaddingTop(18); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(1, tableHinfo); tableHinfo = addspace(4, tableHinfo); cell1 = new PdfPCell(new Paragraph("RECEIPT", font1)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(0, tableHinfo); // cell1 = new PdfPCell(new Paragraph(uinfo[4], font11)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableHinfo.addCell(cell1); document1.add(tableHinfo); PdfPTable tableUinfo = new PdfPTable(1); cell1 = new PdfPCell(new Paragraph(receiptheading[0], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[0], font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[3], font11)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); document1.add(new Paragraph("\u00a0")); tableUinfo = addspace(1, tableUinfo); String hed[] = { "", "Receipt No : ", "Date : ", "" }; PdfPTable tableDinfo = new PdfPTable(1); //tableDinfo.setTotalWidth(100); for (int j = 1; j < 3; j++) { PdfPTable nested1 = new PdfPTable(3); cell1 = new PdfPCell(); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(hed[j], font)); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[j], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); nested1.addCell(cell1); cell1 = new PdfPCell(nested1); cell1.setBorder(0); tableDinfo.addCell(cell1); } PdfPTable container = new PdfPTable(2); cell1 = new PdfPCell(tableUinfo); cell1.setBorder(0); cell1.setPaddingBottom(15); container.addCell(cell1); cell1 = new PdfPCell(tableDinfo); cell1.setBorder(0); container.addCell(cell1); document1.add(container); PdfPTable table1 = new PdfPTable(2); String[] colwidth2 = { "Invoice No.", "Amount Paid($)" }; for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); if (i == 1) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setPaddingBottom(5); cell.setBorderWidthRight(1); cell.setBorderWidthTop(1); table1.addCell(cell); } table1.setHeaderRows(1); double d = 0; colwidth2 = new String[] { "invoicenum", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { for (int j = 0; j < colwidth2.length; j++) { PdfPCell cell = null; if (j == 1) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]))), font12)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell = new PdfPCell( new Paragraph(gridinfo.getJSONObject(i).getString(colwidth2[j]), font12)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } //cell.setMinimumHeight(25); cell.setBorderWidthRight(1); cell.setPaddingTop(5); cell.setFixedHeight(100); table1.addCell(cell); if (j == colwidth2.length - 1) { d += Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j])); } } } // EnglishDecimalFormat f1 = new EnglishDecimalFormat(); PdfPCell cell = new PdfPCell(new Paragraph("", font)); cell.setBorderWidthBottom(1); cell.setBorderWidthRight(0); cell.setBorderWidthLeft(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(cell); cell = new PdfPCell(new Paragraph("Total " + df.format(d), font)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); //cell.setPaddingBottom(15); cell.setPaddingLeft(15); cell.setPaddingBottom(5); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); table1.addCell(cell); PdfPTable table3 = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); //cell.setPaddingBottom(15); cell.setBorder(0); cell.setColspan(4); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table3.addCell(cell); document1.add(table1); document1.add(table3); document1.add(new Paragraph("\u00a0")); cell = new PdfPCell(new Paragraph(String.format( "All payments are non-refundable and non-transferable. \nThis Receipt is valid subject to clearance of the payments."), font11)); //cell.setPaddingLeft(5); cell.setBorder(0); table.addCell(cell); // String delFlag = jbj.getString("delflag"); // if(delFlag.compareTo("2")==0){ // BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); // PdfContentByte cb = writer.getDirectContentUnder(); // cb.saveState(); // cb.setColorFill(Color.BLACK); // cb.beginText(); // cb.setFontAndSize(bf, 48); // cb.showTextAligned(Element.ALIGN_CENTER, "Canceled Payment", document1.getPageSize().getWidth() / 2, document1.getPageSize().getHeight() / 2, 45); // cb.endText(); // cb.restoreState(); // } document1.add(table); document1.close(); writer.close(); os.close(); } catch (Exception e) { System.out.println(e); } return os; }
From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
public static void setHeaderFooter(Document doc, String headerText) { HeaderFooter footer = new HeaderFooter( new Phrase(" ", FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK)), true); footer.setBorderWidth(0);//from w ww .j av a2s . c om footer.setBorderWidthTop(1); footer.setAlignment(HeaderFooter.ALIGN_RIGHT); doc.setFooter(footer); HeaderFooter header = new HeaderFooter( new Phrase(headerText, FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK)), false); doc.setHeader(header); }
From source file:com.krawler.esp.servlets.ExportReportServlet.java
License:Open Source License
public static HeaderFooter addFooter() { HeaderFooter hf = new HeaderFooter(new Phrase("Page ", fontSmallRegular), new Phrase(" of " + pages, fontSmallRegular)); hf.setBorderWidth(0);/* w w w . ja va 2s . co m*/ hf.setBorderWidthTop(1); hf.setAlignment(Element.ALIGN_RIGHT); return hf; }
From source file:com.krawler.esp.servlets.ExportServlet.java
License:Open Source License
public static void setHeaderFooter(Document doc, String headerText) { HeaderFooter footer = new HeaderFooter( new Phrase(" ", FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK)), true); footer.setBorderWidth(0);//from w w w.j ava 2 s . co m footer.setBorderWidthTop(1); footer.setAlignment(HeaderFooter.ALIGN_RIGHT); doc.setFooter(footer); HeaderFooter header = new HeaderFooter( new Phrase(headerText, FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK)), false); doc.setHeader(header); }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public void setHeaderFooter(Document doc, String headerText) { HeaderFooter footer = new HeaderFooter( new Phrase(" ", FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK)), true); footer.setBorderWidth(0);/*from w w w . j a va 2s. c o m*/ footer.setBorderWidthTop(1); footer.setAlignment(HeaderFooter.ALIGN_RIGHT); doc.setFooter(footer); HeaderFooter header = new HeaderFooter( new Phrase(headerText, FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK)), false); doc.setHeader(header); }
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 www. java2 s .com 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
/** * @see com.orange.atk.results.logger.documentGenerator.DocumentGenerator#dumpInStream(boolean, * com.orange.atk.results.logger.log.DocumentLogger) */// w w w . ja v a 2 s . c o 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 . j a v a 2s . 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); }