List of usage examples for com.lowagie.text PageSize A4
Rectangle A4
To view the source code for com.lowagie.text PageSize A4.
Click Source Link
From source file:classroom.intro.HelloWorld10.java
public static void main(String[] args) { // step 1/*w w w . j a v a 2 s. c o m*/ Document.compress = false; Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Graphics2D graphics2D = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight()); graphics2D.drawString("Hello World", 36, 54); graphics2D.dispose(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld11.java
public static void main(String[] args) { // step 1/*from w ww . java2 s . co m*/ Document.compress = false; Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Graphics2D graphics2D = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight()); graphics2D.drawString("Hello World", 36, 54); graphics2D.dispose(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:cn.js.nt.yao.sudokupdf.A4Layout.java
License:Apache License
@Override
Rectangle getPageSize() {
return PageSize.A4;
}
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc, boolean whiteBackground) throws Exception { final int margin = 15; File f = File.createTempFile("cages__", ".pdf"); Document doc = new Document(PageSize.A4.rotate()); Image maleImg, femaleImg, nosexImg; try {/*from ww w . java 2s .c o m*/ maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png")); femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png")); nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png")); } catch (Exception e) { throw new Exception("Could not find images in the classpath: " + e); } FileOutputStream os = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(doc, os); doc.open(); PdfContentByte canvas = writer.getDirectContentUnder(); float tileW = (doc.getPageSize().getWidth()) / 4; float tileH = (doc.getPageSize().getHeight()) / 2; for (int i = 0; i < cages.size(); i++) { Container cage = cages.get(i); Study study = cage.getStudy(); Set<Group> groups = cage.getGroups(); Group group = cage.getGroup(); Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME); animals.addAll(cage.getBiosamples()); //Find the treatments applied to this group Set<NamedTreatment> allTreatments = new LinkedHashSet<>(); for (Group gr : groups) { allTreatments.addAll(gr.getAllTreatments(-1)); } //Draw if (i % 8 == 0) { if (i > 0) doc.newPage(); drawCageSeparation(doc, canvas); } int col = (i % 8) % 4; int row = (i % 8) / 4; float x = margin + tileW * col; float x2 = x + tileW - margin; float baseY = tileH * row; float y; //Display Sex canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50)); Image img = null; String sex = getMetadata(animals, "Sex"); if (study.isBlindAll()) { img = nosexImg; } else if (sex.equals("M")) { img = maleImg; } else if (sex.equals("F")) { img = femaleImg; } else if (sex.length() > 0) { img = nosexImg; } if (img != null) { img.scaleToFit(20, 20); img.setAbsolutePosition(tileW * (col + 1) - 33, doc.getPageSize().getHeight() - (tileH * row + 12 + margin)); doc.add(img); } if (group != null && group.getColor() != null && (study != null && !study.isBlind()) && !whiteBackground) { Color c = group.getColor(); canvas.saveState(); canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170); canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2, tileH - 2); canvas.fill(); canvas.restoreState(); } Color treatmentColor = Color.BLACK; if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) { int offset = 0; for (NamedTreatment t : allTreatments) { if (t.getColor() != null) { if (allTreatments.size() == 1) treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2, t.getColor().getBlue() / 2); canvas.saveState(); canvas.setColorStroke(Color.BLACK); canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue()); y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28; canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4, 22, 22); canvas.fillStroke(); canvas.restoreState(); offset++; } } } canvas.beginText(); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f); canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x, doc.getPageSize().getHeight() - (baseY + 23), 0); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f); y = 42 + baseY; canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0); y += 15; canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0); y += 86; canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0); y += 22; canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0); y += 14; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0); y += 23; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0); y += 50; canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0); canvas.endText(); y = 42 + baseY; print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65, doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f); y += 15; if (animals.size() <= 6) { int n = 0; for (Biosample animal : animals) { print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50, 12, 12, FontFactory.HELVETICA, Color.BLACK, 11f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60, doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 11f); } n++; } } else { int nPerRow = animals.size() / 2; int n = 0; for (Biosample animal : animals) { int nx = n / nPerRow; int ny = n % nPerRow; print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA, Color.BLACK, 10f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f); } n++; } } y += 86; print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 22; print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 14; if (!study.isBlind() && printGroupsTreatments) print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 23; if (!study.isBlind() && printGroupsTreatments) print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y, x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor, printTreatmentDesc ? 9f : 10f); y += 50; print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2, 15, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2, 20, 10, FontFactory.HELVETICA, Color.BLACK, 10f); } doc.close(); os.close(); Desktop.getDesktop().open(f); try { Thread.sleep(500); } catch (Exception e) { } }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void convertHSSF2Pdf(Workbook wb, String header, File reportFile) throws Exception { assert wb != null; assert reportFile != null; //Precompute formula FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); for (int i = 0; i < wb.getNumberOfSheets(); i++) { Sheet sheet = wb.getSheetAt(i);//from w ww .j a va 2s. co m for (Row r : sheet) { for (Cell c : r) { if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { try { evaluator.evaluateFormulaCell(c); } catch (Exception e) { System.err.println(e); } } } } } File tmp = File.createTempFile("tmp_", ".xlsx"); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) { wb.write(out); } //Find page orientation int maxColumnsGlobal = 0; for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); maxColumnsGlobal = Math.max(maxColumnsGlobal, row.getLastCellNum()); } } Rectangle pageSize = maxColumnsGlobal < 10 ? PageSize.A4 : PageSize.A4.rotate(); Document pdfDocument = new Document(pageSize, 10f, 10f, 20f, 20f); PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(reportFile)); addHeader(writer, header); pdfDocument.open(); //we have two columns in the Excel sheet, so we create a PDF table with two columns //Note: There are ways to make this dynamic in nature, if you want to. //Loop through sheets for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); //Loop through rows, to find number of columns int minColumns = 1000; int maxColumns = 0; for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); if (row.getFirstCellNum() >= 0) minColumns = Math.min(minColumns, row.getFirstCellNum()); if (row.getLastCellNum() >= 0) maxColumns = Math.max(maxColumns, row.getLastCellNum()); } if (maxColumns == 0) continue; //Loop through first rows, to find relative width float[] widths = new float[maxColumns]; int totalWidth = 0; for (int c = 0; c < maxColumns; c++) { int w = sheet.getColumnWidth(c); widths[c] = w; totalWidth += w; } for (int c = 0; c < maxColumns; c++) { widths[c] /= totalWidth; } //Create new page and a new chapter with the sheet's name if (sheetNo > 0) pdfDocument.newPage(); Chapter pdfSheet = new Chapter(sheet.getSheetName(), sheetNo + 1); PdfPTable pdfTable = null; PdfPCell pdfCell = null; boolean inTable = false; //Loop through cells, to create the content // boolean leftBorder = true; // boolean[] topBorder = new boolean[maxColumns+1]; for (int r = 0; r <= sheet.getLastRowNum(); r++) { Row row = sheet.getRow(r); //Check if we exited a table (empty line) if (row == null) { if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); pdfTable = null; } inTable = false; continue; } //Check if we start a table (>MIN_COL_IN_TABLE columns) if (row.getLastCellNum() >= MIN_COL_IN_TABLE) { inTable = true; } if (!inTable) { //Process the data outside table, just add the text boolean hasData = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getCellType() == Cell.CELL_TYPE_BLANK) continue; Chunk chunk = getChunk(wb, cell); pdfSheet.add(chunk); pdfSheet.add(new Chunk(" ")); hasData = true; } if (hasData) pdfSheet.add(Chunk.NEWLINE); } else { //Process the data in table if (pdfTable == null) { //Create table pdfTable = new PdfPTable(maxColumns); pdfTable.setWidths(widths); // topBorder = new boolean[maxColumns+1]; } int cellNumber = minColumns; // leftBorder = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); for (; cellNumber < cell.getColumnIndex(); cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } Chunk phrase = getChunk(wb, cell); pdfCell = new PdfPCell(new Phrase(phrase)); pdfCell.setFixedHeight(row.getHeightInPoints() - 3); pdfCell.setNoWrap(!cell.getCellStyle().getWrapText()); pdfCell.setPaddingLeft(1); pdfCell.setHorizontalAlignment( cell.getCellStyle().getAlignment() == CellStyle.ALIGN_CENTER ? PdfPCell.ALIGN_CENTER : cell.getCellStyle().getAlignment() == CellStyle.ALIGN_RIGHT ? PdfPCell.ALIGN_RIGHT : PdfPCell.ALIGN_LEFT); pdfCell.setUseBorderPadding(false); pdfCell.setUseVariableBorders(false); pdfCell.setBorderWidthRight(cell.getCellStyle().getBorderRight() == 0 ? 0 : .5f); pdfCell.setBorderWidthBottom(cell.getCellStyle().getBorderBottom() == 0 ? 0 : cell.getCellStyle().getBorderBottom() > 1 ? 1 : .5f); pdfCell.setBorderWidthLeft(cell.getCellStyle().getBorderLeft() == 0 ? 0 : cell.getCellStyle().getBorderLeft() > 1 ? 1 : .5f); pdfCell.setBorderWidthTop(cell.getCellStyle().getBorderTop() == 0 ? 0 : cell.getCellStyle().getBorderTop() > 1 ? 1 : .5f); String color = cell.getCellStyle().getFillForegroundColorColor() == null ? null : ((XSSFColor) cell.getCellStyle().getFillForegroundColorColor()).getARGBHex(); if (color != null) pdfCell.setBackgroundColor(new Color(Integer.decode("0x" + color.substring(2)))); pdfTable.addCell(pdfCell); cellNumber++; } for (; cellNumber < maxColumns; cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } } //Custom code to add all images on the first sheet (works for reporting) if (sheetNo == 0 && row.getRowNum() == 0) { for (PictureData pd : wb.getAllPictures()) { try { Image pdfImg = Image.getInstance(pd.getData()); pdfImg.scaleToFit( pageSize.getWidth() * .8f - pageSize.getBorderWidthLeft() - pageSize.getBorderWidthRight(), pageSize.getHeight() * .8f - pageSize.getBorderWidthTop() - pageSize.getBorderWidthBottom()); pdfSheet.add(pdfImg); } catch (Exception e) { e.printStackTrace(); } } } } if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); } pdfDocument.add(pdfSheet); } pdfDocument.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createWordReport_hardware(String filename) { try {//ww w . j av a 2s. c om 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
/** * @author sunqichang//*from w ww .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 createPdfReport_hardware(String filename) { try {/*from w w w . ja v a 2s. co m*/ String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Document document = new Document(PageSize.A4); // (Writer)document(Writer) PdfWriter.getInstance(document, new FileOutputStream(filename)); fileName = filename; 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("", 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); PdfPTable aTable = new PdfPTable(4); float[] widths = { 100f, 100f, 300f, 100f }; aTable.setWidths(widths); aTable.setWidthPercentage(100); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); 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(new Phrase(m + 1 + "", contextFont)); aTable.addCell(new Phrase(type, contextFont)); aTable.addCell(new Phrase(name, contextFont)); aTable.addCell(new Phrase(status, contextFont)); } /* * 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); */ document.add(aTable); document.close(); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReportusa_oraPDF(String filename) throws DocumentException, IOException { if (impReport.getTable() == null) { fileName = null;/*w ww. j a v a2 s . c o m*/ return; } try { // Document document = new Document(PageSize.A4); // (Writer)document(Writer) PdfWriter.getInstance(document, new FileOutputStream(filename)); 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, 12, Font.NORMAL); Font contextFont1 = new Font(bfChinese, 11, Font.NORMAL); String hostname = (String) reportHash.get("dbname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); document.add(title); String Ping = (String) reportHash.get("Ping"); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont1); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Paragraph("\n")); PdfPTable aTable = new PdfPTable(4); float[] widths = { 220f, 220f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidthPercentage(100); PdfPCell cell = null; cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new PdfPCell(new Phrase((String) maxping.get("pingmax"))); cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new PdfPCell(new Phrase((String) maxping.get("ping"))); cell = new PdfPCell(new Phrase((String) maxping.get("pingmin")));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon"))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); img.setAlignment(Image.MIDDLE);// img.scalePercent(76); document.add(aTable); document.add(img); document.add(new Paragraph("\n")); 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 img1 = Image.getInstance(baos.toByteArray()); img1.setAbsolutePosition(0, 0); img1.setAlignment(Image.MIDDLE);// document.add(img1); } document.close(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReportusa_oraDoc(String filename) throws DocumentException, IOException { try {// w w w . j a v a2 s . c o m // 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, 12, Font.NORMAL); String hostname = (String) reportHash.get("dbname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); // System.out.println("newi ========================"+newip); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String Ping = (String) reportHash.get("Ping"); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String contextString = ":" + impReport.getTimeStamp() + " \n" + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Table aTable = new Table(4); float[] widths = { 220f, 220f, 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 = null; cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(""); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new Cell(new Phrase((String) // maxping.get("pingmax"),contextFont)); cell = new Cell(new Phrase((String) maxping.get("pingnow"), contextFont));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new Cell(new Phrase((String) // maxping.get("ping"),contextFont)); cell = new Cell(new Phrase((String) maxping.get("pingmin"), contextFont));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); document.add(aTable); document.add(img); document.close(); } catch (Exception e) { SysLogger.error("", e); } }