List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createWordReport_hardware(String filename) { try {//from w ww . ja va 2s . c o m String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Document document = new Document(PageSize.A4); RtfWriter2.getInstance(document, new FileOutputStream(filename)); fileName = filename; 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(""); title.setAlignment(Element.ALIGN_CENTER); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Table aTable = new Table(4); float[] widths = { 100f, 100f, 300f, 100f }; 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(); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); Vector deviceV = (Vector) reportHash.get("deviceV"); for (int m = 0; m < deviceV.size(); m++) { Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m); String name = devicedata.getName(); String type = devicedata.getType(); String status = devicedata.getStatus(); aTable.addCell(m + 1 + ""); aTable.addCell(type); aTable.addCell(name); aTable.addCell(status); } document.add(aTable); document.close(); // System.out.println("abcdefg"); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_pingDoc(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);// w w w . j av a2 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 + ""); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // 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(); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); // aTable.addCell("3.2",Ping+"%"); aTable.addCell(""); 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); document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_ServicePingDoc(String file) throws DocumentException, IOException { String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String servicename = (String) reportHash.get("servicename"); String ip = (String) reportHash.get("ip"); String newip = doip(ip);//from w ww .j a v a 2s.com String Ping = (String) reportHash.get("Ping"); Hashtable ping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 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(servicename + ""); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // 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(); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(Ping + "%"); aTable.addCell((String) ping.get("minPing") + "%"); aTable.addCell((String) ping.get("avgPing") + "%"); Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "pingConnect" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.LEFT);// document.add(aTable); document.add(img); document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
/** * @author wxy word/*from w w w .j ava2s . co m*/ * @param filename * @throws IOException * @throws DocumentException * @date 2010-3-27 */ public void createReport_ServiceCompDoc(String filename) throws DocumentException, IOException { String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String servicename = (String) reportHash.get("servicename"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); String Ping = (String) reportHash.get("Ping"); Hashtable ping = (Hashtable) reportHash.get("ping"); WebConfig config = (WebConfig) reportHash.get("webconfig"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List comInfo = (List) reportHash.get("comInfo"); String type = (String) reportHash.get("type"); // Document document = new Document(PageSize.A4); // (Writer)document(Writer) RtfWriter2.getInstance(document, new FileOutputStream(filename)); 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(servicename + ""); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); StringBuffer sb = new StringBuffer(); sb.append(":" + impReport.getTimeStamp() + " \n"); sb.append(":" + starttime + " " + totime + " \n"); if (comInfo != null) { for (int i = 0; i < comInfo.size(); i++) { sb.append(comInfo.get(i)); } } Paragraph context = new Paragraph(sb.toString()); // 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(); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(Ping + "%"); aTable.addCell((String) ping.get("minPing") + "%"); aTable.addCell((String) ping.get("avgPing") + "%"); document.add(aTable); Image img1 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "pingConnect" + ".png"); if (type != null && type.equals("web")) { Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "delayConnect" + ".png"); Image img3 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "pageConnect" + ".png"); Image img4 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "changeConnect" + ".png"); document.add(img1); document.add(img2); document.add(img3); document.add(img4); } else { document.add(img1); } // img1.setAbsolutePosition(0, 0); // img1.setAlignment(Image.LEFT);// document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_capacityDoc(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 . java 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 + ""); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // 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); // Image img = // Image.getInstance(ResourceCenter.getInstance().getSysPath() // + "/resource/image/jfreechart/" + newip + "ConnectUtilization" // + ".png"); 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(); aTable1.addCell("CPU"); aTable1.addCell(""); aTable1.addCell(""); aTable1.addCell(""); // aTable.addCell("3.2",Ping+"%"); aTable1.addCell(""); aTable1.addCell(cpu + "%"); aTable1.addCell(cpumax); aTable1.addCell(avgcpu); Image img1 = Image.getInstance( ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); img1.setAbsolutePosition(0, 0); img1.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(); aTable2.addCell(""); aTable2.addCell(""); // for (int i = 0; i < memoryItemch.length; i++) { Cell cell = new Cell(memoryItemch[i]); 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"); img2.setAbsolutePosition(0, 0); img2.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(); aTable2.addCell(""); aTable2.addCell(""); // for (int i = 0; i < memoryItemch.length; i++) { Cell cell = new Cell(memoryItemch[i]); 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 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"); img2.setAbsolutePosition(0, 0); img2.setAlignment(Image.MIDDLE);// document.add(aTable2); document.add(img2); } 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.setAbsolutePosition(0, 0); img3.setAlignment(Image.MIDDLE);// document.add(img3); } document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_diskDoc(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 .j av a 2 s. c om // 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 + ""); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // 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); // Image img = // Image.getInstance(ResourceCenter.getInstance().getSysPath() // + "/resource/image/jfreechart/" + newip + "ConnectUtilization" // + ".png"); // img.setAbsolutePosition(0, 0); // img.setAlignment(Image.LEFT);// 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) { aTable3.addCell(""); aTable3.addCell(""); for (int i = 0; i < diskItemch.length; i++) { Cell cell = new Cell(diskItemch[i]); 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 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"); img3.setAbsolutePosition(0, 0); img3.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()); img3.setAbsolutePosition(0, 0); img3.setAlignment(Image.MIDDLE);// document.add(img3); } document.close(); }
From source file:com.aryjr.nheengatu.pdf.PDFDocument.java
License:Open Source License
private void extractVisibleComponents(final Tag tag, final Document doc, final MultiColumnText mct, final Paragraph paragraph, final List list) throws DocumentException { final Iterator tags = tag.tags(); Object component;// w w w .java2s . co m Image image; PDFTable table; final TagsManager tm = TagsManager.getInstance(); PDFDocument.log.info("extractVisibleComponents"); // PDFDocument.log.info(tm.states.size()); // PDFDocument.log.info(tm.getTextIndent()); // if (paragraph != null) // PDFDocument.log.info(paragraph.getFirstLineIndent()); while (tags.hasNext()) { component = tags.next(); if (component instanceof Text) { System.out.println("Processamento: Iniciou while -> if instanceof text"); String s = ((Text) component).getText(); if (s.contains("\\\"")) { s = s.replace("\\\"", "\""); ((Text) component).setText(s); } PDFDocument.log.info("text: " + ((Text) component).getText()); // PDFDocument.log.info(tm.states.size()); // PDFDocument.log.info(tm.getTextIndent()); // PDFDocument.log.info(tm.getSpacingBefore()); // PDFDocument.log.info(tm.getSpacingAfter()); // If it's a text, create a iText text component for it if (paragraph != null) paragraph.add(PDFText.createChunk((Text) component)); else if (list != null) list.add(PDFText.createParagraph((Text) component, tm)); else mct.addElement(PDFText.createParagraph((Text) component, tm)); System.out.println("Processamento: terminou while -> if instanceof text"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("br")) { // PDFDocument.log.info("br"); // PDFDocument.log.info(tm.states.size()); // PDFDocument.log.info(tm.getTextIndent()); // If it's a HTML line break if (paragraph == null) { mct.addElement(new Paragraph("\n")); } else { paragraph.add("\n"); } System.out.println("Processamento: Iniciou while -> if instanceof tag br"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("p")) { // If it's a HTML paragraph, create a iText paragraph for it tm.checkTag((Tag) component); final Paragraph p = PDFText.createParagraph(null, tm); PDFDocument.log.info("p"); PDFDocument.log.info(tm.getFont().getSize()); PDFDocument.log.info(p.getLeading()); // PDFDocument.log.info(tm.states.size()); // PDFDocument.log.info(tm.getTextIndent()); // PDFDocument.log.info("align:"); // PDFDocument.log.info(((Tag) // component).getPropertyValue("align")); // PDFDocument.log.info(tm.getAlign()); // Paragraph p = new Paragraph(); // p.setAlignment(tm.getAlign()); // p.setKeepTogether(true); // // float b = tm.getSpacingBefore(); // // float a = tm.getSpacingAfter(); // p.setSpacingBefore(tm.getSpacingBefore()); // p.setSpacingAfter(tm.getSpacingAfter()); // p.setFirstLineIndent(tm.getTextIndent()); extractVisibleComponents((Tag) component, doc, mct, p, list); if (paragraph != null) paragraph.add(p); else mct.addElement(p); // String align = ((Tag) component).getPropertyValue("align"); // if (align != null) { // p.setAlignment(align.toLowerCase()); // } tm.back(); System.out.println("Processamento: Iniciou while -> if instanceof tag p"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("ol")) { // If it's a HTML paragraph, create a iText paragraph for it tm.checkTag((Tag) component); if (tm.getListStyleType() == null) { ((GraphicsState) tm.states.get(tm.states.size() - 1)).setListStyleType("upper-roman"); } else if (tm.getListStyleType().equals("upper-roman")) { ((GraphicsState) tm.states.get(tm.states.size() - 1)).setListStyleType("lower-alpha"); } final List l = new RomanList(tm.getListStyleType(), 30); if (list != null) list.add(l); else mct.addElement(l); extractVisibleComponents((Tag) component, doc, mct, null, l); tm.back(); System.out.println("Processamento: Iniciou while -> if instanceof tag ol"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("ul")) { // If it's a HTML paragraph, create a iText paragraph for it final List l = new List(false, false, 20.0f); tm.checkTag((Tag) component); if (paragraph != null) paragraph.add(l); else mct.addElement(l); extractVisibleComponents((Tag) component, doc, mct, null, l); tm.back(); System.out.println("Processamento: Iniciou while -> if instanceof tag ul"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("li")) { // If it's a HTML paragraph, create a iText paragraph for it final ListItem li = new ListItem(tm.getFont().getSize() * 1.25f); li.setSpacingAfter(tm.getFont().getSize() * 0.5f); PDFDocument.log.info("li"); PDFDocument.log.info(tm.getFont().getSize()); PDFDocument.log.info(li.getLeading()); tm.checkTag((Tag) component); if (list == null) mct.addElement(li); else list.add(li); extractVisibleComponents((Tag) component, doc, mct, li, list); tm.back(); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("img")) { // If it's a HTML image, create a iText image component for it try { // TODO the image path can't be static image = PDFImage.createImage((Tag) component); if (paragraph == null) { mct.addElement(image); } else { paragraph.add(image); } } catch (final Exception e) { e.printStackTrace(); } System.out.println("Processamento: Iniciou while -> if instanceof tag img"); } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("table")) { // If it's a HTML table, create a iText table component for it try { table = PDFTable.createTable((Tag) component); mct.addElement(table); } catch (final Exception e) { e.printStackTrace(); } } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("div")) { final String s = ((Tag) component).getPropertyValue("style"); if (s != null && s.equals("PAGE-BREAK-AFTER: always")) { doc.add(mct); mct.nextColumn(); } tm.checkTag((Tag) component); extractVisibleComponents((Tag) component, doc, mct, paragraph, list); tm.back(); System.out.println("Processamento: Iniciou while -> if instanceof tag div"); } else { // If it's an another tag, check the name and call this method // again // PDFDocument.log.info("other!"); // PDFDocument.log.info(tm.states.size()); // PDFDocument.log.info(tm.getTextIndent()); tm.checkTag((Tag) component); extractVisibleComponents((Tag) component, doc, mct, paragraph, list); tm.back(); System.out.println("Processamento: Iniciou while -> else if"); } } }
From source file:com.aryjr.nheengatu.testes.AbsolutePosition.java
License:Open Source License
private static PdfPTable createTable() { final PdfPTable table = new PdfPTable(3); table.setTotalWidth(200);/* w ww. j av a 2s .com*/ PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3")); cell.setColspan(3); table.addCell(cell); table.addCell("1.1"); table.addCell("2.1"); table.addCell("3.1"); table.addCell("1.2"); table.addCell("2.2"); table.addCell("3.2"); cell = new PdfPCell(new Paragraph("cell test1")); cell.setBorderColor(new Color(255, 0, 0)); table.addCell(cell); cell = new PdfPCell(new Paragraph("cell test2")); cell.setColspan(2); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); table.addCell(cell); return table; }
From source file:com.bean.UserBean.java
public void gerarPDF1() { try {/*from w w w . ja v a 2 s.co m*/ Document doc = new Document(PageSize.A4); OutputStream os = new FileOutputStream("C:/Users/lprates/Downloads/out.pdf"); PdfWriter.getInstance(doc, os); doc.open(); Paragraph p = new Paragraph("Meu primeiro arquivo PDF!"); doc.add(p); doc.close(); os.close(); //abre pdf usando o PDF Reader instalado na maquina do Usuario Desktop.getDesktop().open(new File("C:/Users/lprates/Downloads/out.pdf")); } catch (Exception e) { } }
From source file:com.bean.UserBean.java
public void gerarPDF2() { try {/*from w w w . j a va 2 s . c om*/ Document doc = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null; docWriter = PdfWriter.getInstance(doc, baosPDF); doc.open(); doc.add(new Paragraph("This document was created by a class named: " + this.getClass().getName())); doc.add(new Paragraph("This document was created on " + new java.util.Date())); doc.close(); docWriter.close(); FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/pdf"); // com a opcao inline abre o PDF no browser do usuario //externalContext.setResponseHeader("Content-Disposition", "inline; filename=\"my.pdf\""); // com a opcao attachment faz download do PDF no computador do usuario externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"my.pdf\""); OutputStream responseOutputStream = externalContext.getResponseOutputStream(); baosPDF.writeTo(responseOutputStream); responseOutputStream.flush(); baosPDF.reset(); facesContext.responseComplete(); } catch (Exception e) { } }