List of usage examples for com.lowagie.text Cell addElement
public void addElement(Element element) throws BadElementException
Cell
. From source file:com.afunms.report.abstraction.ExcelReport1.java
/** * @author sunqichang//*from www . j a v a 2 s . c o m*/ * @param filename * * @param type * pdfdoc */ public void createReport_hardwareNew(String filename, String type) { try { int diskcount = Integer.parseInt(request.getParameter("diskcount")); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); List networkList = (List) reportHash.get("networkList"); List serverList = (List) reportHash.get("serverList"); List dbList = (List) reportHash.get("dbList"); List midwareList = (List) reportHash.get("midwareList"); Document document = new Document(PageSize.A4); if ("doc".equalsIgnoreCase(type)) { RtfWriter2.getInstance(document, new FileOutputStream(filename)); } else { PdfWriter.getInstance(document, new FileOutputStream(filename)); } BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontChineseTitle = new Font(bfChinese, 14, Font.BOLD); Font fontChineseRow = new Font(bfChinese, 12, Font.NORMAL); fileName = filename; document.open(); Paragraph title = new Paragraph("", fontChineseTitle); title.setAlignment(Element.ALIGN_CENTER); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, fontChineseTitle); context.setAlignment(Element.ALIGN_CENTER); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Iterator networkIt = null; if (networkList != null) { networkIt = networkList.iterator(); } Iterator serverIt = null; if (serverList != null) { serverIt = serverList.iterator(); } Iterator dbIt = null; if (dbList != null) { dbIt = dbList.iterator(); } Iterator midwareIt = null; if (midwareList != null) { midwareIt = midwareList.iterator(); } String[] networkTitle = { "", "", "", "", "IP", "" }; String[] serverTitle = { "", "", "", "", "IP", "", "" }; String[] dbTitle = { "", "", "", "IP" }; String[] midwareTitle = { "", "", "", "IP" }; Table table = new Table(9); table.setWidth(100); table.setAlignment(Element.ALIGN_CENTER);// table.setAutoFillEmptyCells(true); // table.setBorderWidth(1); // table.setBorderColor(new Color(0, 125, 255)); // table.setPadding(2);// table.setSpacing(0);// table.setBorder(2);// for (int i = 0; i < networkTitle.length; i++) { Cell cell = new Cell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.addElement(new Paragraph(networkTitle[i], fontChineseTitle)); if (i == 0) { cell.setRowspan(networkList.size() + 1); } if (i == 1 || i == 4 || i == 3) { cell.setColspan(2); } cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); } if (networkIt != null) { while (networkIt.hasNext()) { Cell cell1 = new Cell(); Cell cell2 = new Cell(); Cell cell3 = new Cell(); Cell cell4 = new Cell(); Cell cell5 = new Cell(); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); MonitorNodeDTO monitorNodeDTO = (MonitorNodeDTO) networkIt.next(); cell1.addElement(new Paragraph(monitorNodeDTO.getAlias(), fontChineseRow)); cell2.addElement(new Paragraph(monitorNodeDTO.getCategory(), fontChineseRow)); cell3.addElement(new Paragraph(monitorNodeDTO.getType(), fontChineseRow)); cell4.addElement(new Paragraph(monitorNodeDTO.getIpAddress(), fontChineseRow)); cell5.addElement( new Paragraph(String.valueOf(monitorNodeDTO.getEntityNumber()), fontChineseRow)); cell1.setColspan(2); // cell2.setColspan(2); cell3.setColspan(2); cell4.setColspan(2); // cell5.setColspan(2); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); table.addCell(cell5); } } for (int i = 0; i < serverTitle.length; i++) { Cell cell = new Cell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.addElement(new Paragraph(serverTitle[i], fontChineseTitle)); if (i == 0) { cell.setRowspan(diskcount + 1 + serverList.size()); } if (i == 5 || i == 6) { cell.setColspan(2); } cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); } if (serverIt != null) { while (serverIt.hasNext()) { Cell cell1 = new Cell(); Cell cell2 = new Cell(); Cell cell3 = new Cell(); Cell cell44 = new Cell(); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell44.setVerticalAlignment(Element.ALIGN_MIDDLE); MonitorNodeDTO monitorNodeDTO = (MonitorNodeDTO) serverIt.next(); AssetHelper helper = new AssetHelper(); List<StatisNumer> diskList = helper.getAssetList(monitorNodeDTO.getIpAddress(), "Disk"); List<StatisNumer> memList = helper.getAssetList(monitorNodeDTO.getIpAddress(), "Memory"); cell1.addElement(new Paragraph(monitorNodeDTO.getAlias(), fontChineseRow)); cell2.addElement(new Paragraph(monitorNodeDTO.getCategory(), fontChineseRow)); cell3.addElement(new Paragraph(monitorNodeDTO.getType(), fontChineseRow)); cell44.addElement(new Paragraph(monitorNodeDTO.getIpAddress(), fontChineseRow)); cell1.setRowspan(diskList.size() + 2); cell2.setRowspan(diskList.size() + 2); cell3.setRowspan(diskList.size() + 2); cell44.setRowspan(diskList.size() + 2); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell44); Iterator<StatisNumer> diskIt = diskList.iterator(); int flag = 0; int rowspan = diskList.size() + 2; double sum = 0; while (diskIt.hasNext()) { if (flag == 0 || flag == rowspan / 2) { if (flag == 0) { Cell cellt1 = new Cell(); Cell cellt2 = new Cell(); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellt1.add(new Paragraph("", fontChineseRow)); cellt2.add(new Paragraph("", fontChineseRow)); table.addCell(cellt1); table.addCell(cellt2); } Iterator<StatisNumer> memIt = memList.iterator(); while (memIt.hasNext()) { StatisNumer numer = memIt.next(); if (flag == rowspan / 2) { flag++; continue; } Cell cell6 = new Cell(); Cell cell7 = new Cell(); cell6.setVerticalAlignment(Element.ALIGN_MIDDLE); cell7.setVerticalAlignment(Element.ALIGN_MIDDLE); cell6.addElement(new Paragraph(numer.getName(), fontChineseRow)); cell7.addElement(new Paragraph(numer.getCurrent(), fontChineseRow)); if (flag == 0) { cell6.setRowspan(rowspan / 2); cell7.setRowspan(rowspan / 2); table.addCell(cell6); table.addCell(cell7); break; } else { cell6.setRowspan(rowspan - rowspan / 2); cell7.setRowspan(rowspan - rowspan / 2); table.addCell(cell6); table.addCell(cell7); } } } Cell cell4 = new Cell(); Cell cell5 = new Cell(); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); StatisNumer numer = diskIt.next(); cell4.addElement(new Paragraph(numer.getName(), fontChineseRow)); cell5.addElement(new Paragraph(numer.getCurrent(), fontChineseRow)); table.addCell(cell4); table.addCell(cell5); sum = Arith.add(sum, Double.parseDouble(numer.getCurrent().replaceAll("[a-zA-Z]", ""))); flag++; } Cell cell6 = new Cell(); Cell cell7 = new Cell(); cell6.setVerticalAlignment(Element.ALIGN_MIDDLE); cell7.setVerticalAlignment(Element.ALIGN_MIDDLE); cell6.addElement(new Paragraph("", fontChineseRow)); cell7.addElement(new Paragraph(Arith.round(sum, 2) + "G", fontChineseRow)); table.addCell(cell6); table.addCell(cell7); } } for (int i = 0; i < dbTitle.length; i++) { Cell cell = new Cell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.addElement(new Paragraph(dbTitle[i], fontChineseTitle)); if (i == 0) { cell.setRowspan(dbList.size() + 1); } if (i == 3) { cell.setColspan(4); } else if (i != 0) { cell.setColspan(2); } cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); } if (dbIt != null) { while (dbIt.hasNext()) { Cell cell2 = new Cell(); Cell cell3 = new Cell(); Cell cell4 = new Cell(); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); MonitorDBDTO monitorNodeDTO = (MonitorDBDTO) dbIt.next(); cell2.addElement(new Paragraph(monitorNodeDTO.getAlias(), fontChineseRow)); cell3.addElement(new Paragraph(monitorNodeDTO.getDbtype(), fontChineseRow)); cell4.addElement(new Paragraph(monitorNodeDTO.getIpAddress(), fontChineseRow)); cell2.setColspan(2); cell3.setColspan(2); cell4.setColspan(4); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); } } for (int i = 0; i < midwareTitle.length; i++) { Cell cell = new Cell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.addElement(new Paragraph(midwareTitle[i], fontChineseTitle)); if (i == 0) { cell.setRowspan(midwareList.size() + 1); } if (i == 3) { cell.setColspan(4); } else if (i != 0) { cell.setColspan(2); } cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); } if (midwareIt != null) { while (midwareIt.hasNext()) { Cell cell2 = new Cell(); Cell cell3 = new Cell(); Cell cell4 = new Cell(); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); MonitorMiddlewareDTO monitorNodeDTO = (MonitorMiddlewareDTO) midwareIt.next(); cell2.addElement(new Paragraph(monitorNodeDTO.getAlias(), fontChineseRow)); cell3.addElement(new Paragraph(monitorNodeDTO.getCategory(), fontChineseRow)); cell4.addElement(new Paragraph(monitorNodeDTO.getIpAddress(), fontChineseRow)); cell2.setColspan(2); cell3.setColspan(2); cell4.setColspan(4); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); } } document.add(table); document.close(); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_hostDoc(String file) throws DocumentException, IOException { String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String hostname = (String) reportHash.get("equipname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip);//from ww w. j av a 2 s . c o m // WritableSheet sheet = wb.createSheet(hostname + "", 0); Hashtable CPU = (Hashtable) reportHash.get("CPU"); if (CPU == null) CPU = new Hashtable(); String Ping = (String) reportHash.get("Ping"); Calendar colTime = (Calendar) reportHash.get("time"); Date cc = colTime.getTime(); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] memoryItemch = { "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization" }; String[] diskItemch = { "", "", "" }; // Document document = new Document(PageSize.A4); // (Writer)document(Writer) RtfWriter2.getInstance(document, new FileOutputStream(file)); document.open(); // BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 10, Font.NORMAL); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, titleFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black); Table aTable = new Table(4); float[] widths = { 220f, 300f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidth(100); // 90% aTable.setAlignment(Element.ALIGN_CENTER);// aTable.setAutoFillEmptyCells(true); // aTable.setBorderWidth(1); // aTable.setBorderColor(new Color(0, 125, 255)); // aTable.setPadding(2);// aTable.setSpacing(0);// aTable.setBorder(2);// aTable.endHeaders(); Cell cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); aTable.addCell(Ping + "%"); aTable.addCell((String) maxping.get("pingmax")); aTable.addCell((String) maxping.get("avgpingcon")); Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.LEFT);// document.add(aTable); document.add(img); String cpu = ""; if (CPU.get("cpu") != null) cpu = (String) CPU.get("cpu"); String cpumax = ""; if (CPU.get("cpumax") != null) cpumax = (String) CPU.get("cpumax"); String avgcpu = ""; if (CPU.get("avgcpu") != null) avgcpu = (String) CPU.get("avgcpu"); Table aTable1 = new Table(4); float[] width = { 220f, 300f, 220f, 220f }; aTable1.setWidths(width); aTable1.setWidth(100); // 90% aTable1.setAlignment(Element.ALIGN_CENTER);// aTable1.setAutoFillEmptyCells(true); // aTable1.setBorderWidth(1); // aTable1.setBorderColor(new Color(0, 125, 255)); // aTable1.setPadding(2);// aTable1.setSpacing(0);// aTable1.setBorder(2);// aTable1.endHeaders(); cell = new Cell(); cell.addElement(new Paragraph("CPU", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cell); aTable1.addCell(cpu + "%"); aTable1.addCell(cpumax); aTable1.addCell(avgcpu); Image img1 = Image.getInstance( ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(aTable1); document.add(img1); if (Memory != null && Memory.size() > 0) { Table aTable2 = new Table(6); float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f }; aTable2.setWidths(widthss); aTable2.setWidth(100); // 90% aTable2.setAlignment(Element.ALIGN_CENTER);// aTable2.setAutoFillEmptyCells(true); // aTable2.setBorderWidth(1); // aTable2.setBorderColor(new Color(0, 125, 255)); // aTable2.setPadding(2);// aTable2.setSpacing(0);// aTable2.setBorder(2);// aTable2.endHeaders(); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); // for (int i = 0; i < memoryItemch.length; i++) { cell = new Cell(memoryItemch[i]); cell.setBackgroundColor(Color.LIGHT_GRAY); // cell.setHorizontalAlignment(Element.ALIGN_CENTER); aTable2.addCell(cell); } // for (int i = 0; i < Memory.size(); i++) { aTable2.addCell(""); Hashtable mhash = (Hashtable) (Memory.get(new Integer(i))); String name = (String) mhash.get("name"); Cell cell1 = new Cell(name); aTable2.addCell(cell1); for (int j = 0; j < memoryItem.length; j++) { String value = ""; if (mhash.get(memoryItem[j]) != null) { value = (String) mhash.get(memoryItem[j]); } Cell cell2 = new Cell(value); aTable2.addCell(cell2); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); Cell cell3 = new Cell(value); aTable2.addCell(cell3); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); aTable2.addCell(avgvalue); } } // end // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(aTable2); document.add(img2); } else { Table aTable2 = new Table(6); float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f }; aTable2.setWidths(widthss); aTable2.setWidth(100); // 90% aTable2.setAlignment(Element.ALIGN_CENTER);// aTable2.setAutoFillEmptyCells(true); // aTable2.setBorderWidth(1); // aTable2.setBorderColor(new Color(0, 125, 255)); // aTable2.setPadding(2);// aTable2.setSpacing(0);// aTable2.setBorder(2);// aTable2.endHeaders(); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); // for (int i = 0; i < memoryItemch.length; i++) { cell = new Cell(memoryItemch[i]); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); } // String[] names = null; HostNodeDao dao = new HostNodeDao(); HostNode node = (HostNode) dao.findByCondition("ip_address", ip).get(0); // Monitoriplist monitor = monitorManager.getByIpaddress(ip); if (node.getSysOid().startsWith("1.3.6.1.4.1.311")) { names = new String[] { "PhysicalMemory", "VirtualMemory" }; } else { names = new String[] { "PhysicalMemory", "SwapMemory" }; } for (int i = 0; i < names.length; i++) { String name = names[i]; aTable2.addCell(""); cell = new Cell(names[i]); aTable2.addCell(cell); for (int j = 0; j < memoryItem.length; j++) { // String value = ""; Cell cell1 = new Cell(value); aTable2.addCell(cell1); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); Cell cell2 = new Cell(value); aTable2.addCell(cell2); } else { Cell cell3 = new Cell(value); aTable2.addCell(cell3); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); Cell cell4 = new Cell(avgvalue); aTable2.addCell(cell4); } else { Cell cell5 = new Cell(avgvalue); aTable2.addCell(cell5); } } // end // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(aTable2); document.add(img2); } Table aTable3 = new Table(5); float[] widthss1 = { 220f, 440f, 150f, 150f, 220f }; aTable3.setWidths(widthss1); aTable3.setWidth(100); // 90% aTable3.setAlignment(Element.ALIGN_CENTER);// aTable3.setAutoFillEmptyCells(true); // aTable3.setBorderWidth(1); // aTable3.setBorderColor(new Color(0, 125, 255)); // aTable3.setPadding(2);// aTable3.setSpacing(0);// aTable3.setBorder(2);// aTable3.endHeaders(); if (Disk != null && Disk.size() > 0) { cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable3.addCell(cell); cell = new Cell(""); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable3.addCell(cell); for (int i = 0; i < diskItemch.length; i++) { cell = new Cell(diskItemch[i]); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable3.addCell(cell); } // for (int i = 0; i < Disk.size(); i++) { aTable3.addCell(""); Hashtable diskhash = (Hashtable) (Disk.get(new Integer(i))); String name = (String) diskhash.get("name"); cell = new Cell(name); aTable3.addCell(cell); for (int j = 0; j < diskItem.length; j++) { String value = ""; if (diskhash.get(diskItem[j]) != null) { value = (String) diskhash.get(diskItem[j]); } Cell cell1 = new Cell(value); // System.out.println(value+"================value==============="); aTable3.addCell(cell1); } } // end // Image img3 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "disk" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(aTable3); document.add(img3); } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } Image img3 = Image.getInstance(baos.toByteArray()); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(img3); } document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_hostPDF(String file) throws DocumentException, IOException { String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String hostname = (String) reportHash.get("equipname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip);//ww w.ja v a 2 s . c o m // WritableSheet sheet = wb.createSheet(hostname + "", 0); Hashtable CPU = (Hashtable) reportHash.get("CPU"); if (CPU == null) CPU = new Hashtable(); String Ping = (String) reportHash.get("Ping"); Calendar colTime = (Calendar) reportHash.get("time"); Date cc = colTime.getTime(); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] memoryItemch = { "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization" }; String[] diskItemch = { "", "", "" }; // Document document = new Document(PageSize.A4); // (Writer)document(Writer) PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 10, Font.NORMAL); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Phrase("\n")); Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black); Table aTable = new Table(4); aTable.setAutoFillEmptyCells(true); aTable.setWidth(100); // float[] widths = { 220f, 300f, 220f, 220f }; // aTable.setWidths(widths); aTable.setPadding(5); // aTable.setWidthPercentage(100); Cell cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cell); aTable.addCell(Ping + "%"); aTable.addCell((String) maxping.get("pingmax")); aTable.addCell((String) maxping.get("avgpingcon")); Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); img.setAlignment(Image.LEFT);// img.scalePercent(75); document.add(aTable); document.add(img); String cpu = ""; if (CPU.get("cpu") != null) cpu = (String) CPU.get("cpu"); String cpumax = ""; if (CPU.get("cpumax") != null) cpumax = (String) CPU.get("cpumax"); String avgcpu = ""; if (CPU.get("avgcpu") != null) avgcpu = (String) CPU.get("avgcpu"); Table aTable1 = new Table(4); aTable1.setAutoFillEmptyCells(true); aTable1.setWidth(100); aTable1.setPadding(5); // float[] width = { 220f, 300f, 220f, 220f }; // aTable1.setWidths(width); // aTable1.setWidthPercentage(100); cell = new Cell(); cell.addElement(new Paragraph("CPU", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable1.addCell(cell); cell = new Cell(); cell.addElement(new Paragraph("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable1.addCell(cell); aTable1.addCell(cpu + "%"); aTable1.addCell(cpumax); aTable1.addCell(avgcpu); Image img1 = Image.getInstance( ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); img.setAlignment(Image.MIDDLE);// img1.scalePercent(75); document.add(aTable1); document.add(img1); if (Memory != null && Memory.size() > 0) { Table aTable2 = new Table(6); aTable2.setPadding(5); aTable2.setAutoFillEmptyCells(true); aTable2.setWidth(100); // float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f }; // aTable2.setWidths(widthss); // aTable2.setWidthPercentage(100); cell = new Cell(new Phrase("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); cell = new Cell(new Phrase("", contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); // for (int i = 0; i < memoryItemch.length; i++) { cell = new Cell(new Phrase(memoryItemch[i], contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); } // for (int i = 0; i < Memory.size(); i++) { aTable2.addCell(""); Hashtable mhash = (Hashtable) (Memory.get(new Integer(i))); String name = (String) mhash.get("name"); cell = new Cell(new Phrase(name)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); for (int j = 0; j < memoryItem.length; j++) { String value = ""; if (mhash.get(memoryItem[j]) != null) { value = (String) mhash.get(memoryItem[j]); } cell = new Cell(new Phrase(value)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); Cell cell3 = new Cell(new Phrase(value)); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell3); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); cell = new Cell(new Phrase(avgvalue)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); } } // end // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); img.setAlignment(Image.MIDDLE);// img2.scalePercent(75); document.add(aTable2); document.add(img2); } else { Table aTable2 = new Table(6); float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f }; aTable2.setWidths(widthss); // aTable2.setWidthPercentage(100); /* * aTable2.setWidth(100); // 90% * aTable2.setAlignment(Element.ALIGN_CENTER);// * aTable2.setAutoFillEmptyCells(true); // * aTable2.setBorderWidth(1); // aTable2.setBorderColor(new * Color(0, 125, 255)); // aTable2.setPadding(2);// * aTable2.setSpacing(0);// * aTable2.setBorder(2);// aTable2.endHeaders(); */ cell = new Cell(new Phrase("", contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); cell = new Cell(new Phrase("", contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); // for (int i = 0; i < memoryItemch.length; i++) { cell = new Cell(new Phrase(memoryItemch[i], contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); } // String[] names = null; HostNodeDao dao = new HostNodeDao(); HostNode node = (HostNode) dao.findByCondition("ip_address", ip).get(0); // Monitoriplist monitor = monitorManager.getByIpaddress(ip); if (node.getSysOid().startsWith("1.3.6.1.4.1.311")) { names = new String[] { "PhysicalMemory", "VirtualMemory" }; } else { names = new String[] { "PhysicalMemory", "SwapMemory" }; } for (int i = 0; i < names.length; i++) { String name = names[i]; aTable2.addCell(""); cell = new Cell(new Phrase(names[i])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); for (int j = 0; j < memoryItem.length; j++) { // String value = ""; cell = new Cell(new Phrase(value)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); Cell cell2 = new Cell(new Phrase(value)); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell2); } else { Cell cell3 = new Cell(new Phrase(value)); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell3); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); Cell cell4 = new Cell(new Phrase(avgvalue)); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell4); } else { Cell cell5 = new Cell(new Phrase(avgvalue)); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(cell5); } } // end // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); img.setAlignment(Image.MIDDLE);// img2.scalePercent(75); document.add(aTable2); document.add(img2); } Table aTable3 = new Table(5); aTable3.setAutoFillEmptyCells(true); aTable3.setPadding(5); aTable3.setWidth(100); // float[] widthss1 = { 220f, 440f, 150f, 150f, 220f }; // aTable3.setWidths(widthss1); // aTable3.setWidthPercentage(100); if (Disk != null && Disk.size() > 0) { cell = new Cell(new Phrase("", contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable3.addCell(cell); cell = new Cell(new Phrase("", contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable3.addCell(cell); for (int i = 0; i < diskItemch.length; i++) { cell = new Cell(new Phrase(diskItemch[i], contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable3.addCell(cell); } // for (int i = 0; i < Disk.size(); i++) { aTable3.addCell(""); Hashtable diskhash = (Hashtable) (Disk.get(new Integer(i))); String name = (String) diskhash.get("name"); cell = new Cell(new Phrase(name)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable3.addCell(cell); for (int j = 0; j < diskItem.length; j++) { String value = ""; if (diskhash.get(diskItem[j]) != null) { value = (String) diskhash.get(diskItem[j]); } cell = new Cell(new Phrase(value)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable3.addCell(cell); } } // end // Image img3 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "disk" + ".png"); img3.setAlignment(Image.MIDDLE);// img3.scalePercent(78); document.add(aTable3); // document.add(new Paragraph("\n")); document.add(img3); } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } Image img3 = Image.getInstance(baos.toByteArray()); img3.setAlignment(Image.MIDDLE);// img3.scalePercent(76); document.add(new Paragraph("\n")); // document.add(aTable3); document.add(img3); } document.close(); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeBooleanQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel, String trueLabel, String falseLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel); Cell cell; Boolean foundOption = false;//from www . jav a 2 s . c o m cell = new Cell(new Paragraph(trueLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("1")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } foundOption = false; cell = new Cell(new Paragraph(falseLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("0")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } document.add(statsTable); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
License:Open Source License
private void writeOptionsQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel); Cell cell; int rowIndex = 0; for (QuestionOption option : question.getOptions()) { Boolean foundOption = false; cell = new Cell(new Paragraph(option.getText(), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell);/* ww w . j a v a 2s . c o m*/ if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (question.getType().getIsMultipleValue()) { //multiple value question (checkboxes) match on order if (questionStatistic.getOptionOrder().equals(option.getOrder())) { foundOption = true; cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } else { //single value question match on value if (questionStatistic.getEntry() != null && questionStatistic.getEntry().equals(option.getValue())) { foundOption = true; cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell); cell = new Cell(); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} statsTable.addCell(cell); cell = new Cell(); //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));} cell.setColspan(5); statsTable.addCell(cell); } rowIndex++; } document.add(statsTable); }
From source file:org.activityinfo.server.report.renderer.itext.ItextMapRenderer.java
License:Open Source License
private void renderLegend(MapReportElement element, Document doc) throws DocumentException, IOException { Table table = new Table(2); table.setBorderWidth(1);// ww w. j a v a2 s . com table.setWidth(100f); table.setBorderColor(new Color(100, 100, 100)); table.setPadding(5); table.setSpacing(0); table.setCellsFitPage(true); table.setTableFitsPage(true); table.setWidths(new int[] { 1, 3 }); Cell cell = new Cell(I18N.CONSTANTS.legend()); cell.setHeader(true); cell.setColspan(2); table.addCell(cell); table.endHeaders(); for (MapLayerLegend legend : element.getContent().getLegends()) { Cell symbolCell = new Cell(); symbolCell.setHorizontalAlignment(Element.ALIGN_CENTER); symbolCell.setVerticalAlignment(Element.ALIGN_MIDDLE); Image symbol = createLegendSymbol(legend, imageCreator); symbolCell.addElement(symbol); Cell descriptionCell = new Cell(); addLegendDescription(element, legend.getDefinition(), descriptionCell); table.addCell(symbolCell); table.addCell(descriptionCell); } doc.add(table); }
From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Cell columnHeaderCell(String label, boolean leaf, int hAlign) throws BadElementException { Paragraph para = new Paragraph(label); para.setFont(new Font(Font.HELVETICA, BODY_FONT_SIZE, Font.NORMAL, Color.WHITE)); Cell cell = new Cell(); cell.addElement(para); cell.setHorizontalAlignment(hAlign); cell.setHeader(true);//from w ww. j av a2 s. com cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); cell.setBackgroundColor(BLUE3); cell.setBorderWidth(0); return cell; }
From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
/** * Renders a Cell for/*w ww .j a v a 2s .c om*/ * * @param label * @param header * @param depth * @param leaf * @param horizantalAlignment * @return * @throws BadElementException */ public static Cell bodyCell(String label, boolean header, int depth, boolean leaf, int horizantalAlignment) throws BadElementException { Cell cell = new Cell(); cell.setHorizontalAlignment(horizantalAlignment); if (label != null) { Paragraph para = new Paragraph(label); Font font = bodyFont(); if (depth == 0 && !leaf) { font.setColor(Color.WHITE); } para.setFont(font); para.setIndentationLeft(LEFT_INDENT + (header ? HEADER3_FONT_SIZE * depth : 0)); cell.addElement(para); } cell.setBorderWidthLeft(0f); cell.setBorderWidthRight(0); cell.setBorderWidthTop(0); if (!leaf && depth == 0) { cell.setBackgroundColor(BLUE4); // #95B3D7 cell.setBorderWidthBottom(THIN_BORDER_WIDTH); cell.setBorderColorBottom(BLUE5); // #DBE5F1 } else if (!leaf && depth == 1) { cell.setBackgroundColor(BLUE5); cell.setBorderWidthBottom(THIN_BORDER_WIDTH); cell.setBorderColorBottom(BLUE2); } else { cell.setBorderWidthBottom(THIN_BORDER_WIDTH); cell.setBorderColorBottom(BLUE5); cell.setBorderWidthTop(THIN_BORDER_WIDTH); cell.setBorderColorTop(BLUE5); } return cell; }
From source file:org.bambrikii.photobank.web.documents.paymentcertificates.impl.PaymentCertificateBuilderRU.java
public void build(OutputStream outputStream) throws DocumentGenerationException { Document doc = new Document(PageSize.A4); PdfWriter writer;//from w w w . ja v a 2 s . co m BaseFont baseFont = null; try { writer = PdfWriter.getInstance(doc, outputStream); writer.setEncryption(null, "qweasdzxc".getBytes(), PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); doc.open(); String baseFontPath = getResourcesPath() + "org/bambrikii/photobank/web/documents/ARIAL.TTF"; final String stampImagePath = getResourcesPath() + "org/bambrikii/photobank/web/documents/paymentcertificates/PersonaStarsStamp.png"; baseFont = BaseFont.createFont(baseFontPath, "Cp1251", true); Font baseTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.NORMAL, new Color(0, 0, 0)); Font baseBoldTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.BOLD, new Color(0, 0, 0)); Calendar cal = Calendar.getInstance(getLocale()); cal.setTime(getData().getDate()); // Act number String actNumber = MessageFormat.format( "\u0410\u043a\u0442 \u2116 {0} \u043e\u0442 \u00ab{1}\u00bb {2} {3} \u0433\u043e\u0434\u0430", String.valueOf(getData().getNumber()), cal.get(Calendar.DAY_OF_MONTH), monthsGenitiveCase.get(cal.get(Calendar.MONTH)).toLowerCase(), String.valueOf(cal.get(Calendar.YEAR))); Paragraph actNumberParagraph = new Paragraph(actNumber, new com.lowagie.text.Font(baseFont, 12, com.lowagie.text.Font.BOLD, new Color(0, 0, 0))); actNumberParagraph.setSpacingAfter(19); Paragraph cityParagraph = new Paragraph("\u0433. \u041c\u043e\u0441\u043a\u0432\u0430", baseTextStyle); cityParagraph.setSpacingAfter(15); // Licensor Paragraph licensorParagraph = new Paragraph(); licensorParagraph .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440: ", baseBoldTextStyle)); licensorParagraph.add(new Chunk(MessageFormat.format("{0}", "\u0418\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415\u0432\u0433\u0435\u043d\u0438\u0439 \u0410\u0440\u043a\u0430\u0434\u044c\u0435\u0432\u0438\u0447, \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0421\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u041e\u0413\u0420\u041d \u2116 305501025600011 \u043e\u0442 13.09.2005\u0433."), baseTextStyle)); licensorParagraph.setSpacingAfter(15); // Licensee Paragraph licenseeParagraph = new Paragraph(); licenseeParagraph .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442: ", baseBoldTextStyle)); licenseeParagraph.add(new Chunk(getData().getLicensee(), baseTextStyle)); licenseeParagraph.setSpacingAfter(15); // Pre text Paragraph pretextParagraph = new Paragraph(); pretextParagraph.add(new Chunk( "\u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0414\u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043c \u041e\u0444\u0435\u0440\u0442\u044b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u043b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0435 \u043a\u043e\u043f\u0438\u0438) \u0438 \u043d\u0435\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 (\u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f): ", baseTextStyle)); pretextParagraph.setSpacingAfter(15); int defaultLeading = 9; // Files table Table filesTbl = new Table(5); filesTbl.setWidths(new int[] { 5, 35, 35, 10, 15 }); filesTbl.setBorder(Table.RECTANGLE); filesTbl.setBorderWidth(1); filesTbl.setSpacing(0); filesTbl.setPadding(2); filesTbl.setCellsFitPage(false); filesTbl.setUseVariableBorders(true); filesTbl.setAlignment(Element.ALIGN_LEFT); filesTbl.setWidth(100); Cell cellheader1 = new Cell(new Phrase(new Chunk("\u2116", baseBoldTextStyle))); cellheader1.setHeader(true); cellheader1.setLeading(defaultLeading); cellheader1.setHorizontalAlignment(Cell.ALIGN_CENTER); filesTbl.addCell(cellheader1); Cell cellheader2 = new Cell(new Phrase( new Chunk("\u041d\u043e\u043c\u0435\u0440 \u0444\u043e\u0442\u043e", baseBoldTextStyle))); cellheader2.setHeader(true); cellheader2.setLeading(defaultLeading); cellheader2.setHorizontalAlignment(Cell.ALIGN_CENTER); filesTbl.addCell(cellheader2); Cell cellheader3 = new Cell( new Phrase(new Chunk("\u041f\u0435\u0440\u0441\u043e\u043d\u0430", baseBoldTextStyle))); cellheader3.setHeader(true); cellheader3.setLeading(defaultLeading); cellheader3.setHorizontalAlignment(Cell.ALIGN_CENTER); filesTbl.addCell(cellheader3); Cell cellheader4 = new Cell( new Phrase(new Chunk("\u0420\u0430\u0437\u043c\u0435\u0440", baseBoldTextStyle))); cellheader4.setHeader(true); cellheader4.setLeading(defaultLeading); cellheader4.setHorizontalAlignment(Cell.ALIGN_CENTER); filesTbl.addCell(cellheader4); Cell cellheader5 = new Cell( new Phrase(new Chunk("\u0426\u0435\u043d\u0430 \u0440\u0443\u0431.", baseBoldTextStyle))); cellheader5.setHeader(true); cellheader5.setLeading(defaultLeading); cellheader5.setHorizontalAlignment(Cell.ALIGN_CENTER); filesTbl.addCell(cellheader5); filesTbl.endHeaders(); Integer i = 0; for (PaymentCertificateDataItem item : getData().getItems()) { i++; Cell cell1 = new Cell(new Phrase(new Chunk(Integer.toString(i), baseTextStyle))); cell1.setLeading(defaultLeading); cell1.setHorizontalAlignment(Cell.ALIGN_CENTER); cell1.setBorder(Cell.NO_BORDER); filesTbl.addCell(cell1); Cell cell2 = new Cell(new Phrase(new Chunk(item.getFilename(), baseTextStyle))); cell2.setLeading(defaultLeading); cell2.setHorizontalAlignment(Cell.ALIGN_LEFT); cell2.setBorder(Cell.NO_BORDER); filesTbl.addCell(cell2); Cell cell3 = new Cell(new Phrase(new Chunk(item.getName(), baseTextStyle))); cell3.setLeading(defaultLeading); cell3.setHorizontalAlignment(Cell.ALIGN_LEFT); cell3.setBorder(Cell.NO_BORDER); filesTbl.addCell(cell3); Cell cell4 = new Cell(new Phrase(new Chunk(item.getSizeName(), baseTextStyle))); cell4.setLeading(defaultLeading); cell4.setHorizontalAlignment(Cell.ALIGN_CENTER); cell4.setBorder(Cell.NO_BORDER); filesTbl.addCell(cell4); Cell cell5 = new Cell(new Phrase(new Chunk(Double.toString(item.getPrice()), baseTextStyle))); cell5.setLeading(defaultLeading); cell5.setHorizontalAlignment(Cell.ALIGN_CENTER); cell5.setBorder(Cell.NO_BORDER); filesTbl.addCell(cell5); } filesTbl.complete(); // filesTbl.normalize(); String totalPrice = MessageFormat.format("{0} {1}", String.valueOf(getData().getTotal()), getData().getCurrency()); Paragraph totalParagraph = new Paragraph(); totalParagraph.setAlignment(Paragraph.ALIGN_RIGHT); totalParagraph.add(new Chunk("\u0418\u0442\u043e\u0433\u043e: ", baseTextStyle)); totalParagraph.add(new Chunk(totalPrice, baseBoldTextStyle)); totalParagraph.setSpacingAfter(25); Paragraph posttext1Paragraph = new Paragraph(); posttext1Paragraph.add(new Chunk( "\u0412\u043e\u0437\u043d\u0430\u0433\u0440\u0430\u0436\u0434\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442: ", baseTextStyle)); posttext1Paragraph.add(new Chunk(totalPrice, baseBoldTextStyle)); // posttext1Paragraph.setSpacingAfter(15); Paragraph posttext2Paragraph = new Paragraph( "\u041d\u0414\u0421 \u043d\u0435 \u043e\u0431\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u0443\u043d\u043a\u0442\u0430\u043c\u0438 2, 3 \u0438 5 \u0441\u0442\u0430\u0442\u044c\u0438 346.11 \u041d\u0430\u043b\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0435\u043a\u0441\u0430 \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438.", baseTextStyle); posttext2Paragraph.setSpacingAfter(15); Paragraph posttext3Paragraph = new Paragraph( "\u041f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0440\u043e\u043a\u043e\u043c \u043d\u0430 1 (\u043e\u0434\u0438\u043d) \u0433\u043e\u0434 \u0441 \u0434\u0430\u0442\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u0410\u043a\u0442\u0435.", baseTextStyle); posttext3Paragraph.setSpacingAfter(15); Paragraph posttext4Paragraph = new Paragraph(); posttext4Paragraph.add(new Chunk( "\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442 \u043d\u0435 \u0432\u043f\u0440\u0430\u0432\u0435 ", baseTextStyle)); posttext4Paragraph.add(new Chunk("(\u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442\u0441\u044f)", baseBoldTextStyle)); posttext4Paragraph.add(new Chunk( ": \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043a\u043e\u043f\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u0442\u044c, \u0441\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u043a\u0430\u0442, \u0430\u0440\u0435\u043d\u0434\u0443, \u043b\u0438\u0437\u0438\u043d\u0433, \u043a\u0430\u043a \u0441\u0430\u043c\u0438 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435\u0439, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u043a\u0430\u0440\u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043a, \u043f\u043e\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0439 \u0432 \u0446\u0435\u043b\u044f\u0445 \u043f\u0440\u043e\u0434\u0430\u0436\u0438; \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0442\u044c \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0440\u0435\u0442\u044c\u0438\u043c\u0438 \u043b\u0438\u0446\u0430\u043c\u0438, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u0434\u0435\u043b\u0430\u044f \u0438\u0445 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438.", baseTextStyle)); posttext4Paragraph.setSpacingAfter(15); Paragraph posttext5Paragraph = new Paragraph( "\u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0443\u0441\u043b\u0443\u0433\u0438 \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043f\u0440\u0430\u0432 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435. \u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0439 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442.", baseTextStyle); posttext5Paragraph.setSpacingAfter(15); // Signatures Table signaturesTable = new Table(4); signaturesTable.setWidths(new int[] { 10, 40, 10, 40 }); signaturesTable.setWidth(100); signaturesTable.setSpacing(0); signaturesTable.setPadding(5); signaturesTable.setBorder(Table.NO_BORDER); Cell licensorSignature1Cell = new Cell(new Phrase( new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440:", baseBoldTextStyle))); licensorSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT); licensorSignature1Cell.setBorder(Cell.NO_BORDER); Cell licensorSignature2Cell = new Cell(new Phrase(new Chunk( "______________/ \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415.\u0410. /", baseTextStyle))); licensorSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT); licensorSignature2Cell.setBorder(Cell.NO_BORDER); licensorSignature2Cell.addElement(new Paragraph("\n\n\n\n")); licensorSignature2Cell.add( // Stamp Image.getInstance(stampImagePath)); Cell licenseeSignature1Cell = new Cell(new Phrase( new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442:", baseBoldTextStyle))); licenseeSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT); licenseeSignature1Cell.setBorder(Cell.NO_BORDER); Cell licenseeSignature2Cell = new Cell(new Phrase(new Chunk( MessageFormat.format("______________/ {0} /", getData().getLicensee()), baseTextStyle))); licenseeSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT); licenseeSignature2Cell.setBorder(Cell.NO_BORDER); signaturesTable.addCell(new Cell() { { setBorder(Cell.NO_BORDER); } }); signaturesTable.addCell(licensorSignature1Cell); signaturesTable.addCell(new Cell(true) { { setBorder(Cell.NO_BORDER); } }); signaturesTable.addCell(licenseeSignature1Cell); signaturesTable.addCell(new Cell(true) { { setBorder(Cell.NO_BORDER); } }); signaturesTable.addCell(licensorSignature2Cell); signaturesTable.addCell(new Cell(true) { { setBorder(Cell.NO_BORDER); } }); signaturesTable.addCell(licenseeSignature2Cell); signaturesTable.addCell(new Cell(true) { { setBorder(Cell.NO_BORDER); } }); signaturesTable.addCell(new Cell(true) { { setBorder(Cell.NO_BORDER); } }); signaturesTable.complete(); // PdfPTable signaturePdPfTable = signaturesTable.createPdfPTable(); // Document items doc.add(actNumberParagraph); doc.add(cityParagraph); doc.add(licensorParagraph); doc.add(licenseeParagraph); doc.add(pretextParagraph); doc.add(filesTbl); doc.add(totalParagraph); doc.add(posttext1Paragraph); doc.add(posttext2Paragraph); doc.add(posttext3Paragraph); doc.add(posttext4Paragraph); doc.add(posttext5Paragraph); doc.add(signaturesTable); doc.close(); } catch (DocumentException ex) { throw new DocumentGenerationException("Exception creating document.", ex); } catch (IOException ex) { throw new DocumentGenerationException( "Exception creating document, required font file may not be found.", ex); } }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Cell columnHeaderCell(String label, boolean leaf, int hAlign) throws BadElementException { Paragraph para = new Paragraph(label); para.setFont(new Font(Font.HELVETICA, 10, Font.NORMAL, Color.WHITE)); Cell cell = new Cell(); cell.addElement(para); cell.setHorizontalAlignment(hAlign); cell.setHeader(true);/* w ww .j a v a 2 s . c o m*/ cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); cell.setBackgroundColor(new Color(55, 96, 145)); cell.setBorderWidth(0); return cell; }