List of usage examples for com.lowagie.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java
License:Open Source License
/** * @param widths The maximum width of each column's contents in * points. THIS ARRAY WILL BE MODIFIED to the width of the widest * single word in the heading if it is wider than the existing * width value for that column. Words are split using the default * settings for java.util.StringTokenizer. * @param headerTopNColumns reference to the null count/% inner table in the header * @param headerValueColumns reference to the unique count/% inner table in the header * @param headerLengthColumns reference to the length min/max/avg inner table in the header * @param headerUniqueColumns reference to the value min/max/avg inner table in the header * @param headerNullColumns reference to the top N Value/count inner table in the header * we will resert widths of these inner table after we have all rows *//*from ww w. j av a2 s.c o m*/ private void addHeaderRow(TableProfileResult result, ProfileTableStructure profile, BaseFont bf, float titleFSize, float colHeadingFSize, float[] widths) throws DocumentException, IOException, SQLObjectException { int ncols = headings.length; Font titleFont = new Font(bf, titleFSize, Font.BOLD); Font colHeadingFont = new Font(bf, colHeadingFSize); PdfPTable table = profile.getMainTable(); SQLTable sqlTable = result.getProfiledObject(); // TableProfileResult tProfile = (TableProfileResult) pm.getResult(sqlTable); PdfPTable infoTable = new PdfPTable(2); StringBuffer heading = new StringBuffer(); heading.append("Connection: ").append(sqlTable.getParentDatabase().getName()).append("\n"); heading.append("Table: ").append(SQLObjectUtils.toQualifiedName(sqlTable, SQLDatabase.class)); if (result.getException() != null) { heading.append("\nProfiling Error"); if (result.getException() != null) { heading.append(":\n").append(result.getException()); StackTraceElement[] stackTrace = result.getException().getStackTrace(); for (int i = 0; i < STACK_TRACE_LENGTH && i < stackTrace.length; i++) { StackTraceElement element = stackTrace[i]; heading.append("\n ").append(element.getFileName()).append(".").append(element.getClassName()) .append(".").append(element.getMethodName()).append("(").append(element.getLineNumber()) .append(")"); } if (stackTrace.length > STACK_TRACE_LENGTH) { heading.append("\n ... ").append(stackTrace.length).append(" more"); } } } else { PdfPCell infoCell; infoCell = new PdfPCell(new Phrase("Row Count:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase(String.valueOf(result.getRowCount()), colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase("Create Date:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); infoCell = new PdfPCell(new Phrase(df.format(new Date(result.getCreateStartTime())), colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase("Elapsed:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase(result.getTimeToCreate() + "ms", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); } PdfPCell hcell = new PdfPCell(new Phrase(heading.toString(), titleFont)); hcell.setColspan(ncols - 3); hcell.setBorder(Rectangle.NO_BORDER); hcell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(hcell); hcell = new PdfPCell(infoTable); hcell.setColspan(3); hcell.setBorder(Rectangle.NO_BORDER); table.addCell(hcell); if (sqlTable.getColumns().size() > 0) { int colNo = 0; // column name Phrase colTitle = new Phrase("Column Name", colHeadingFont); PdfPCell cell = new PdfPCell(colTitle); cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); cell.setBorderWidth(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); // ensure column width is at least enough for widest word in heading widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; // date type colTitle = new Phrase("Data Type", colHeadingFont); cell = new PdfPCell(colTitle); cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); cell.setBorderWidth(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; // null count and % colTitle = new Phrase("NULL", colHeadingFont); cell = new PdfPCell(colTitle); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("%", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableNullColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // unique count and % colTitle = new Phrase("Unique", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); profile.getInnerTableUniqueColumn().addCell(cell); colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableUniqueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("%", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableUniqueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableUniqueColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); cell.setBorderWidth(2); table.addCell(cell); // length max/min/avg colTitle = new Phrase("Length", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); profile.getInnerTableLengthColumn().addCell(cell); colTitle = new Phrase("Min", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Max", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Avg", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableLengthColumn()); cell.setColspan(3); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // value max/min/avg colTitle = new Phrase("Value", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); profile.getInnerTableValueColumn().addCell(cell); colTitle = new Phrase("Min", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Max", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Avg", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableValueColumn()); cell.setColspan(3); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // top n colTitle = new Phrase("Top N", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); profile.getInnerTableTopNColumn().addCell(cell); colTitle = new Phrase("Values", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableTopNColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableTopNColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableTopNColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); } else { hcell = new PdfPCell(new Phrase("No Column Found in the table", titleFont)); hcell.setColspan(ncols); hcell.setBorder(Rectangle.BOTTOM); hcell.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(hcell); } table.setHeaderRows(2); }
From source file:classroom.filmfestival_b.Movies14.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from w w w .jav a 2 s .c om Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 1, 5 }); File f; Paragraph p; Chunk c; PdfPCell cell = new PdfPCell(); Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); p = new Paragraph("FILMFESTIVAL", bold); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new Movies14().new PageCell()); table.addCell(cell); table.setHeaderRows(2); table.setFooterRows(1); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { cell = new PdfPCell(Image.getInstance(f.getPath()), true); cell.setPadding(2); } else { cell = new PdfPCell(); } table.addCell(cell); p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); cell = new PdfPCell(); cell.setUseAscender(true); cell.setUseDescender(true); cell.addElement(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } cell.addElement(list); table.addCell(cell); } document.add(table); // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies15.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1// www . ja v a 2s . c o m Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); PdfPTable table = new PdfPTable(2); table.setComplete(false); table.setWidths(new float[] { 1, 5 }); File f; Paragraph p; Chunk c; PdfPCell cell = new PdfPCell(); Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); p = new Paragraph("FILMFESTIVAL", bold); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new Movies14().new PageCell()); table.addCell(cell); table.setHeaderRows(2); table.setFooterRows(1); int counter = 10; for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { cell = new PdfPCell(Image.getInstance(f.getPath()), true); cell.setPadding(2); } else { cell = new PdfPCell(); } table.addCell(cell); p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); cell = new PdfPCell(); cell.setUseAscender(true); cell.setUseDescender(true); cell.addElement(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } cell.addElement(list); table.addCell(cell); if (counter % 10 == 0) { document.add(table); } System.out.println(writer.getPageNumber()); counter++; } table.setComplete(true); document.add(table); // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf.java
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try {/* ww w. j a va 2 s . com*/ java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40); // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // pdfWriter = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize()); String compName = null; String date = null; try { java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); // com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase("Internal Requisition - Page:",pFontHeader ), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); // docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.open(); String Username = null; int numColumns = 9; try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); // java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = { 15, 15, 30, 15, 15, 15 }; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); // table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark")); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(50); table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo())); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(25); java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3 .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile"); while (rset3.next()) { table1.getDefaultCell().setColspan(6); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10); table1.getDefaultCell().setPadding(3); int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 }; // table1.setWidths(headerwidths1); table1.setWidthPercentage((100)); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); Phrase phrase = new Phrase("", pFontHeader); try { // java.sql.Statement st3 = conDB.createStatement(); // java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner"); // java.sql.Statement st3 = conDb.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); //java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.Statement st6 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile"); //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name ilike '"+selectSupp+"'"); java.sql.ResultSet rset4 = st4.executeQuery( "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier," + " received_requisation,reason,date,store_name FROM st_receive_requisation where REQUISITION_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset5 = st5.executeQuery( "select DISTINCT date_due from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset11 = st11.executeQuery( "select initcap(user_name) from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); while (rset11.next()) { Username = rset11.getObject(1).toString(); } table1.getDefaultCell().setBorderColor(java.awt.Color.white); while (rset4.next()) { table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("FROM TEAM LEADER LOGISTICS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); // phrase = new Phrase("NUMBER KNH/SCM-MTCE STORES/......", pFontHeader5); // table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(6); phrase = new Phrase("FROM : " + rset4.getObject(8).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(4); phrase = new Phrase("DATE: " + rset4.getObject(7).toString() + "PR NO: " + rset4.getObject(1).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("TO : " + rset4.getObject(3).toString(), pFontHeader); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // phrase = new Phrase(" " + rset4.getObject(2).toString(), pFontHeader); // table1.addCell(phrase); /* * table1.getDefaultCell().setColspan(5); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table1.addCell(phrase); phrase = new * Phrase("PROCUREMENT METHOD : ", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REQUISITION NO: " + * rset4.getObject(1).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("ACCOUNT NO: ", * pFontHeader); table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REASON FOR PURCHASE " + * rset4.getObject(6).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); * * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase("NAME OF THE SUPPLIER " + * rset4.getObject(4).toString(), pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("CONTRACT NO: ", * pFontHeader); table1.addCell(phrase); * */ } docPdf.add(table1); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } double Total = 0.00; double discount = 0.00; double vat = 0.00; double qty = 0.00; double price = 0.00; double value = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9); // table3.getDefaultCell().setPadding(3); int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table3.setWidths(headerwidths3); table3.setWidthPercentage((100)); //table.getDefaultCell().setBorderColor(java.awt.Color.black); //table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table3.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); table3.getDefaultCell().setColspan(1); phrase = new Phrase("NOs ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Item No/Code ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Item Description", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Units of Issue. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Qty Required. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Monthly Usage ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Remarks", pFontHeader); table3.addCell(phrase); // phrase = new Phrase("Est.Cost ", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Actual Cost", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Tender/Qtn Ref.", pFontHeader); // table3.addCell(phrase); phrase = new Phrase("", pFontHeader); //table.addCell(phrase); table3.setHeaderRows(1); // table3.getDefaultCell().setColspan(1); // // table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); String coment = ""; try { // java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.ResultSet rset1 = st1 .executeQuery("SELECT initcap(item_description),units,cos_glcode," + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation" + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); table.getDefaultCell().setBorderColor(java.awt.Color.lightGray); while (rset1.next()) { // value = qty * price; cnt = cnt + 1; table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase("" + cnt, pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString()); phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); table3.addCell(phrase); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2); // // table3.addCell(phrase); // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2); // table3.addCell(phrase); // // // System.out.println("Second "+docPdf.top()); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2); // // table3.addCell(phrase); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2); // // table3.addCell(phrase); // // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // value = value + rset1.getDouble(6); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); // // // table.addCell(phrase); // // coment = rset1.getObject(12).toString(); } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); table.getDefaultCell().setFixedHeight(350); table.addCell(table3); table.getDefaultCell().setFixedHeight(20); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); // phrase = new Phrase("TOTAL COST", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(value)), pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("", pFontHeader); // table3.addCell(phrase); table.getDefaultCell().setColspan(9); table.getDefaultCell() .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorder(Rectangle.TOP); table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP); /* * * * table.getDefaultCell().setColspan(6); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("Prepared By :" * +Username.toUpperCase(), pFontHeader); * * table.addCell(phrase); */ table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("PREPARED BY.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); // table.getDefaultCell().setColspan(4); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Amount Voted..................................................", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(5); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Balance.........................................................", pFontHeader); // table.addCell(phrase); // // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................", pFontHeader); // // table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("SIGN..........................................................", pFontHeader); //table.addCell(phrase); table.getDefaultCell().setColspan(9); //table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("", pFontHeader); table.addCell(phrase); //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader); //table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM); //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Approved/Not Approved.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Procurement Section.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Inv No.......................", pFontHeader); // // table.addCell(phrase); // // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign....................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date.......................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Time...........................", pFontHeader); // // table.addCell(phrase); /* * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new * Phrase("REMARK___________________________________", * pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setColspan(4); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("DATE * RECEIVED____________________________", * pFontHeader); table.addCell(phrase); * * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table.addCell(phrase); * * table.getDefaultCell().setColspan(9); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); * phrase = new Phrase(" ", pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setBorder(Rectangle.TOP); * * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("1. Original__________ Use * department", pFontHeader); * * table.addCell(phrase); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("2. Duplicate________ * Procurement office", pFontHeader); * * table.addCell(phrase); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("3. Triplicate_________ Book * copy", pFontHeader); * * table.addCell(phrase); */ docPdf.add(table); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } // } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } // System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize()); docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf1_.java
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try {// w w w. j a v a 2s.c o m java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40); // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // pdfWriter = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize()); String compName = null; String date = null; try { java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); // com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase("Internal Requisition - Page:",pFontHeader ), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); // docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.open(); String Username = null; int numColumns = 9; try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); // java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = { 15, 15, 30, 15, 15, 15 }; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); // table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark")); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(50); table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo())); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table1.getDefaultCell().setFixedHeight(25); java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3 .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile"); while (rset3.next()) { table1.getDefaultCell().setColspan(6); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10); table1.getDefaultCell().setPadding(3); int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 }; // table1.setWidths(headerwidths1); table1.setWidthPercentage((100)); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); Phrase phrase = new Phrase("", pFontHeader); try { // java.sql.Statement st3 = conDB.createStatement(); // java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner"); // java.sql.Statement st3 = conDb.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); //java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.Statement st6 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile"); //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name ilike '"+selectSupp+"'"); java.sql.ResultSet rset4 = st4.executeQuery( "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier," + " received_requisation,reason,date,store_name,requisation FROM st_receive_requisation where REQUISITION_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset5 = st5.executeQuery( "select DISTINCT date_due from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); java.sql.ResultSet rset11 = st11.executeQuery( "select initcap(user_name) from st_receive_requisation where requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); while (rset11.next()) { Username = rset11.getObject(1).toString(); } table1.getDefaultCell().setBorderColor(java.awt.Color.white); while (rset4.next()) { table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("FROM TEAM LEADER LOGISTICS- " + Department + " ", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("NUMBER KNH/" + Department + "/ " + OrderNo, pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); //table1.addCell(phrase); table1.getDefaultCell().setColspan(6); phrase = new Phrase("Requisitioning Store : " + rset4.getObject(3).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(4); phrase = new Phrase("DATE: " + rset4.getObject(9).toString(), pFontHeader); table1.addCell(phrase); table1.getDefaultCell().setColspan(10); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Receiving Store : " + rset4.getObject(8).toString(), pFontHeader); table1.addCell(phrase); // table1.getDefaultCell().setColspan(10); // phrase = new Phrase(" " + rset4.getObject(2).toString(), pFontHeader); // table1.addCell(phrase); /* * table1.getDefaultCell().setColspan(5); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table1.addCell(phrase); phrase = new * Phrase("PROCUREMENT METHOD : ", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REQUISITION NO: " + * rset4.getObject(1).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("ACCOUNT NO: ", * pFontHeader); table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase(" ", pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("REASON FOR PURCHASE " + * rset4.getObject(6).toString(), pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); * * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("", pFontHeader); * table1.addCell(phrase); * * table1.getDefaultCell().setColspan(5); phrase * = new Phrase("NAME OF THE SUPPLIER " + * rset4.getObject(4).toString(), pFontHeader); * table1.addCell(phrase); * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("CONTRACT NO: ", * pFontHeader); table1.addCell(phrase); * */ } docPdf.add(table1); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } double Total = 0.00; double discount = 0.00; double vat = 0.00; double qty = 0.00; double price = 0.00; double value = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9); // table3.getDefaultCell().setPadding(3); int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table3.setWidths(headerwidths3); table3.setWidthPercentage((100)); //table.getDefaultCell().setBorderColor(java.awt.Color.black); //table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table3.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); table3.getDefaultCell().setColspan(1); phrase = new Phrase("NOs ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Item No/Code ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Item Description", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Units of Issue. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Qty Required. ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase("Store Balance ", pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); phrase = new Phrase("Monthly Usage", pFontHeader); table3.addCell(phrase); // table3.getDefaultCell().setColspan(1); // phrase = new Phrase(" ", pFontHeader); // table3.addCell(phrase); // phrase = new Phrase("Est.Cost ", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Actual Cost", pFontHeader); // table3.addCell(phrase); // // phrase = new Phrase("Tender/Qtn Ref.", pFontHeader); // table3.addCell(phrase); phrase = new Phrase("", pFontHeader); //table.addCell(phrase); table3.setHeaderRows(1); // table3.getDefaultCell().setColspan(1); // // table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); String coment = ""; try { // java.sql.Statement st6 = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.ResultSet rset1 = st1 .executeQuery("SELECT initcap(item_description),units,cos_glcode," + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation" + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"' AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); table.getDefaultCell().setBorderColor(java.awt.Color.lightGray); while (rset1.next()) { // value = qty * price; cnt = cnt + 1; table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase("" + cnt, pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2); table3.getDefaultCell().setBorderColor(java.awt.Color.black); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2); table3.addCell(phrase); table3.getDefaultCell().setColspan(1); // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString()); phrase = new Phrase(rset1.getObject(7).toString(), pFontHeader); table3.addCell(phrase); table3.getDefaultCell().setColspan(2); //change phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader2); table3.addCell(phrase); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2); // // table3.addCell(phrase); // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2); // table3.addCell(phrase); // // // System.out.println("Second "+docPdf.top()); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2); // // table3.addCell(phrase); // // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2); // // table3.addCell(phrase); // // // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // value = value + rset1.getDouble(6); // table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2); // // // table.addCell(phrase); // // coment = rset1.getObject(12).toString(); } // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // // table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); // table.getDefaultCell().setFixedHeight(350); // table.addCell(table3); // // table.getDefaultCell().setFixedHeight(20); // //// // // // table.getDefaultCell().setColspan(9); // table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); // phrase = new Phrase(" ", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setBorder(Rectangle.TOP); // // table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP); /* * * * table.getDefaultCell().setColspan(6); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("Prepared By :" * +Username.toUpperCase(), pFontHeader); * * table.addCell(phrase); */ // table.getDefaultCell().setColspan(3); // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("PREPARED BY.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................\n", pFontHeader); // // table.addCell(phrase); // table.getDefaultCell().setColspan(4); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Amount Voted..................................................", pFontHeader); // table.addCell(phrase); // // table.getDefaultCell().setColspan(5); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Balance.........................................................", pFontHeader); // table.addCell(phrase); // // // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Date.................................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time.................................", pFontHeader); // // table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("SIGN..........................................................", pFontHeader); //table.addCell(phrase); table.getDefaultCell().setColspan(9); //table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("", pFontHeader); table.addCell(phrase); //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader); //table.addCell(phrase); //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM); //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); // table.getDefaultCell().setColspan(3); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Approved/Not Approved.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Procurement Section.....................", pFontHeader); // // table.addCell(phrase); // // //table.getDefaultCell().setColspan(5); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date............................", pFontHeader); // // table.addCell(phrase); // // phrase = new Phrase("Time............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Inv No.......................", pFontHeader); // // table.addCell(phrase); // // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Sign....................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(2); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Date.......................................", pFontHeader); // // table.addCell(phrase); // // table.getDefaultCell().setColspan(1); // // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Time...........................", pFontHeader); // // table.addCell(phrase); /* * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new * Phrase("REMARK___________________________________", * pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setColspan(4); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("DATE * RECEIVED____________________________", * pFontHeader); table.addCell(phrase); * * table.getDefaultCell().setColspan(5); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase(" ", pFontHeader); * table.addCell(phrase); * * table.getDefaultCell().setColspan(9); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); * phrase = new Phrase(" ", pFontHeader); * * table.addCell(phrase); * table.getDefaultCell().setBorder(Rectangle.TOP); * * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("1. Original__________ Use * department", pFontHeader); * * table.addCell(phrase); * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("2. Duplicate________ * Procurement office", pFontHeader); * * table.addCell(phrase); * * * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); * phrase = new Phrase("3. Triplicate_________ Book * copy", pFontHeader); * * table.addCell(phrase); */ docPdf.add(table); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } // } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } try { Phrase phrase = new Phrase(); com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); table.getDefaultCell().setPadding(3); int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 }; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell() .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT); table.getDefaultCell().setFixedHeight(350); table.addCell(table); table.getDefaultCell().setFixedHeight(20); // table.getDefaultCell().setColspan(9); table.getDefaultCell() .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorder(Rectangle.TOP); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("PREPARED BY.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Sign.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date.................................", pFontHeader); table.addCell(phrase); phrase = new Phrase("Time.................................\n", pFontHeader); table.addCell(phrase); //down docPdf.add(table); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } // System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize()); docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_networkPDF(String file) throws DocumentException, IOException { String runmodel = PollingEngine.getCollectwebflag(); Hashtable CPU = (Hashtable) reportHash.get("CPU"); String Ping = (String) reportHash.get("Ping"); String ip = (String) reportHash.get("ip"); String newip = doip(ip);/* w w w. j av a 2 s.c om*/ Calendar colTime = (Calendar) reportHash.get("time"); Date cc = colTime.getTime(); Vector netifVector = (Vector) reportHash.get("netifVector"); Hashtable portconfigHash = (Hashtable) reportHash.get("portconfigHash"); List reportports = (List) reportHash.get("reportports"); Vector iprouterVector = (Vector) reportHash.get("iprouterVector"); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); String hostname = (String) reportHash.get("equipname"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] netIfItemch = { "", "", "", "(M)(KB/S)", "", "(KB/S)", "(KB/S)" }; String[] ipRouterItemch = { "", "", "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization", "INodeUsedSize", "INodeUtilization" }; String[] diskItemch = { "", "", "", "i-node", "i-node" }; String[] iproutertype = { "", "", "", "direct(3)", "indirect(4)" }; String[] iprouterproto = { "", "other(1)", "local(2)", "netmgmt(3)", "icmp(4)", "egp(5)", "ggp(6)", "hello(7)", "rip(8)", "is-is(9)", "es-is(10)", "ciscoIgrp(11)", "bbnSpfIgp(12)", "ospf(13)", "bgp(14)" }; // 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); BaseFont bfChinese1 = 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"// + ":" + sdf.format(cc); Paragraph context = new Paragraph(new Phrase(contextString, titleFont)); // context.setAlignment(Element.ALIGN_CENTER); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Paragraph("\n")); // Table Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black); Table aTable = new Table(4); // PdfPTable pdfPTable = new PdfPTable(aTable); // float[] widths = { 220f, 300f, 220f, 220f }; // aTable.setWidths(widths); // aTable.setWidthPercentage(100); aTable.setWidth(100); // aTable.setPadding(5); aTable.setAutoFillEmptyCells(true); Cell pc1 = new Cell(new Phrase("", contextFont)); // pc1.setRowspan(2); Cell pc2 = new Cell(new Phrase("", contextFont)); Cell pc3 = new Cell(new Phrase("", contextFont)); Cell pc4 = new Cell(new Phrase("", contextFont)); pc1.setBackgroundColor(Color.LIGHT_GRAY); pc2.setBackgroundColor(Color.LIGHT_GRAY); pc3.setBackgroundColor(Color.LIGHT_GRAY); pc4.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(pc1); aTable.addCell(pc2); aTable.addCell(pc3); aTable.addCell(pc4); // 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);// img.scalePercent(76); document.add(aTable); document.add(img); document.add(new Paragraph("\n")); // document.add(new Paragraph("\n")); // document.close(); Table aTable1 = new Table(4); aTable1.setWidth(100); // aTable1.setPadding(5); aTable1.setAutoFillEmptyCells(true); // float[] width = { 220f, 300f, 220f, 220f }; // aTable1.setWidths(width); // aTable1.setWidthPercentage(100); // aTable.addCell("3.2",Ping+"%"); pc1 = new Cell(new Phrase("CPU", contextFont)); // pc1.setRowspan(2); pc2 = new Cell(new Phrase("", contextFont)); pc3 = new Cell(new Phrase("", contextFont)); pc4 = new Cell(new Phrase("", contextFont)); pc1.setBackgroundColor(Color.LIGHT_GRAY); pc2.setBackgroundColor(Color.LIGHT_GRAY); pc3.setBackgroundColor(Color.LIGHT_GRAY); pc4.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(pc1); aTable1.addCell(pc2); aTable1.addCell(pc3); aTable1.addCell(pc4); aTable1.addCell(""); aTable1.addCell((String) CPU.get("cpu") + "%"); aTable1.addCell((String) CPU.get("cpumax")); aTable1.addCell((String) CPU.get("avgcpu")); Image img1 = Image.getInstance( ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); // img.setAbsolutePosition(0, 0); img1.setAlignment(Image.MIDDLE);// img1.scalePercent(76); document.add(aTable1); document.add(img1); document.add(new Paragraph("\n")); if (netifVector != null && netifVector.size() > 0) { Table aTable2 = new Table(8); aTable2.setWidth(100); // aTable2.setPadding(5); aTable2.setAutoFillEmptyCells(true); // float[] width2 = { 300f, 220f, 220f, 180f, 300f, 180f, 220f, 220f // }; // aTable2.setWidths(width2); // aTable2.setWidthPercentage(100); // aTable2.setHeaderRows(1); Cell ct = new Cell(new Phrase("", contextFont)); // ct.setRowspan(netifVector.size() + 1); ct.setBackgroundColor(Color.lightGray); ct.setHorizontalAlignment(Element.ALIGN_CENTER); ct.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(ct); // // allRow = allRow; Color color = new Color(204, 204, 255); for (int i = 0; i < netIfItemch.length; i++) { Cell cell = new Cell(new Paragraph(netIfItemch[i], contextFont)); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); } // for (int i = 0; i < netifVector.size(); i++) { aTable2.addCell(""); String[] strs = (String[]) netifVector.get(i); String ifname = strs[1]; String index = strs[0]; for (int j = 0; j < strs.length; j++) { if (j == 1) { String linkuse = ""; if (portconfigHash != null && portconfigHash.size() > 0) { if (portconfigHash.get(ip + ":" + index) != null) linkuse = (String) portconfigHash.get(ip + ":" + index); } Cell cell1 = new Cell(new Phrase(strs[j], contextFont)); Cell cell2 = new Cell(new Phrase(linkuse, contextFont)); cell1.setLeading(6); cell2.setLeading(6); if (i % 2 != 0) { cell1.setBackgroundColor(color); cell2.setBackgroundColor(color); } aTable2.addCell(cell1); aTable2.addCell(cell2); } else if (j > 1) { Cell cell3 = new Cell(new Phrase(strs[j].replace("KB/", ""), contextFont)); cell3.setLeading(6); if (i % 2 != 0) { cell3.setBackgroundColor(color); } aTable2.addCell(cell3); } else { Cell cell4 = new Cell(new Phrase(strs[j].replace("KB/", ""), contextFont)); cell4.setLeading(6); if (i % 2 != 0) { cell4.setBackgroundColor(color); } aTable2.addCell(cell4); } } // end } document.add(aTable2); document.add(new Paragraph("\n")); } if ("0".equals(runmodel)) { // if (iprouterVector != null && iprouterVector.size() > 0) { PdfPTable aTable3 = new PdfPTable(7); float[] width2 = { 240f, 170f, 310f, 300f, 220f, 180f, 330f }; aTable3.setWidths(width2); aTable3.setWidthPercentage(100); aTable3.setHeaderRows(1); aTable3.addCell(new Phrase("", contextFont)); // // allRow = allRow+1; for (int i = 0; i < ipRouterItemch.length; i++) { aTable3.addCell(new Phrase(ipRouterItemch[i], contextFont)); } // for (int i = 0; i < iprouterVector.size(); i++) { aTable3.addCell(" "); IpRouter iprouter = (IpRouter) iprouterVector.get(i); aTable3.addCell(iprouter.getIfindex()); aTable3.addCell(iprouter.getDest()); aTable3.addCell(iprouter.getNexthop()); aTable3.addCell(iproutertype[Integer.parseInt(iprouter.getType().longValue() + "")]); aTable3.addCell(iprouterproto[Integer.parseInt(iprouter.getProto().longValue() + "")]); aTable3.addCell(iprouter.getMask()); } document.add(aTable3); document.add(new Paragraph("\n")); } } else { // List routerList = (ArrayList) reportHash.get("routerList"); if (routerList != null) { PdfPTable aTable3 = new PdfPTable(7); float[] width2 = { 240f, 170f, 310f, 300f, 220f, 180f, 330f }; aTable3.setWidths(width2); aTable3.setWidthPercentage(100); aTable3.setHeaderRows(1); aTable3.addCell(new Phrase("", contextFont)); // // allRow = allRow+1; for (int i = 0; i < ipRouterItemch.length; i++) { aTable3.addCell(new Phrase(ipRouterItemch[i], contextFont)); } for (int i = 0; i < routerList.size(); i++) { RouterNodeTemp iprouter = (RouterNodeTemp) routerList.get(i); aTable3.addCell(" "); aTable3.addCell(iprouter.getIfindex()); aTable3.addCell(iprouter.getDest()); aTable3.addCell(iprouter.getNexthop()); aTable3.addCell(iprouter.getType()); aTable3.addCell(iprouter.getProto()); aTable3.addCell(iprouter.getMask()); } document.add(aTable3); document.add(new Paragraph("\n")); } } // doc if (reportports != null && reportports.size() > 0) { // // aTable4.addCell(""); for (int i = 0; i < reportports.size(); i++) { PdfPTable aTable4 = new PdfPTable(2); float[] width2 = { 600f, 300f }; aTable4.setWidths(width2); aTable4.setWidthPercentage(100); com.afunms.config.model.Portconfig portconfig = (com.afunms.config.model.Portconfig) reportports .get(i); Phrase phrase = new Phrase("", contextFont); Phrase phrase1 = new Phrase(portconfig.getPortindex() + "(" + portconfig.getName() + ")"); Phrase phrase2 = new Phrase("", contextFont); aTable4.addCell(new Phrase("" + portconfig.getPortindex() + "(" + portconfig.getName() + ")", contextFont)); // aTable4.addCell(new Phrase(phrase++ portconfig.getPortindex() // + "("+ portconfig.getName() +phrase2)); if (portconfig.getLinkuse() == null) portconfig.setLinkuse(""); /* * Cell cell1 = new Cell(new Phrase(":"+ * portconfig.getLinkuse(),contextFont)); */ aTable4.addCell(new Phrase(":" + portconfig.getLinkuse(), contextFont)); document.add(aTable4); // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + portconfig.getPortindex() + "ifspeed_day.png"); // img2.setAbsolutePosition(0, 0); img2.setAlignment(Image.LEFT);// // sheet,0,0,5,1,,, img2.scalePercent(67); 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) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); Image img2 = Image.getInstance(baos.toByteArray()); // img.setAbsolutePosition(0, 0); img2.setAlignment(Image.LEFT);// img2.scalePercent(67); document.add(img2); } document.close(); }
From source file:com.afunms.report.abstraction.ExcelReport1.java
/** * MODIFY HONGLI 2010-10-27/*from ww w . j av a2 s . co m*/ */ public void createReport_oraPDF(String filename) throws DocumentException, IOException { if (impReport.getTable() == null) { fileName = null; 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); // 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, contextFont1); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Paragraph("\n")); /* * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + * starttime + " " + totime); */ PdfPTable aTable = new PdfPTable(3); float[] widths = { 220f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidthPercentage(100); PdfPCell cell = null; cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable.addCell(cell); cell = new PdfPCell(new Phrase((String) maxping.get("pingnow"))); this.setCellFormat(cell, false); aTable.addCell(cell); cell = new PdfPCell(new Phrase((String) maxping.get("pingmax"))); this.setCellFormat(cell, false); aTable.addCell(cell); cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon"))); this.setCellFormat(cell, false); 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")); // HONGLI MODIFY START1 PdfPTable aTable1 = new PdfPTable(12); float[] width = { 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f }; // HONGLI MODIFY END1 aTable1.setWidths(width); aTable1.setWidthPercentage(100); aTable1.setHeaderRows(1); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("MB", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("MB", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); // HONGLI ADD START1 cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); // HONGLI ADD END1 cell = new PdfPCell(new Phrase("", titleFont)); this.setCellFormat(cell, true); aTable1.addCell(cell); // aTable1.endHeaders(); // Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v"); // HONGLI ADD START2 Hashtable dbio = (Hashtable) reportHash.get("dbio"); // HONGLI ADD END2 int row = 0; for (int i = 0; i < tableinfo_v.size(); i++) { Hashtable ht = (Hashtable) tableinfo_v.get(i); String _filename = ht.get("file_name").toString(); String tablespace = ht.get("tablespace").toString(); String size = ht.get("size_mb").toString(); String free = ht.get("free_mb").toString(); String percent = ht.get("percent_free").toString(); String status = ht.get("status").toString(); // HONGLI ADD START3 String pyr = ""; String pbr = ""; String pyw = ""; String pbw = ""; if (dbio.containsKey(_filename)) { Hashtable iodetail = (Hashtable) dbio.get(_filename); if (iodetail != null && iodetail.size() > 0) { pyr = (String) iodetail.get("pyr"); pbr = (String) iodetail.get("pbr"); pyw = (String) iodetail.get("pyw"); pbw = (String) iodetail.get("pbw"); } } // HONGLI ADD END3 aTable1.addCell(new Phrase("")); row = i + 1; String rowStr = "" + row; cell = new PdfPCell(new Phrase(rowStr)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(_filename)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(tablespace)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(size)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(free)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(percent)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); // HONGLI ADD START4 cell = new PdfPCell(new Phrase(pyr)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(pbr)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(pyw)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); cell = new PdfPCell(new Phrase(pbw)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); // HONGLI ADD END4 cell = new PdfPCell(new Phrase(status)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable1.addCell(cell); } 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.add(aTable1); document.close(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } }
From source file:com.exam.server.ConvertPDF.java
private static void createTable(Section subCatPart, ArrayList<DeviceDTO> input) throws BadElementException { // PdfPTable table = new PdfPTable(input.size()+1); PdfPTable table = new PdfPTable(6); System.out.println("size::" + input.size()); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Part2 Id")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from www . ja va2 s . c om*/ c1 = new PdfPCell(new Phrase("Id Company")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Address")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Data1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Time1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Time2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < input.size(); i++) { table.addCell("" + input.get(i).getPart2Id()); table.addCell("" + input.get(i).getIdCompany()); table.addCell(input.get(i).getAddress1()); table.addCell(input.get(i).getData1()); table.addCell(input.get(i).getTime1()); table.addCell(input.get(i).getTime2()); } subCatPart.add(table); }
From source file:com.itext.test.FirstPdf.java
private static void createTable(Section subCatPart) throws BadElementException { //PdfPTable//from w ww .j a v a2 s. com PdfPTable table = new PdfPTable(3); //PdfPTable // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); //PDFPCell PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); //PdfPCellHorizontalAlignment? c1.setHorizontalAlignment(Element.ALIGN_CENTER); //celltable table.addCell(c1); //PDFPCell c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf headers./*from w ww . j av a 2 s . co m*/ * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfHeaders(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { font = getFont(); final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; final PdfPCell headersCells = new PdfPCell(new Phrase(getHeader(), font)); headersCells.setHorizontalAlignment(Element.ALIGN_CENTER); headersCells.setColspan(headerWidth); headersCells.setUseDescender(true); headersCells.setBorder(0); pdfPTable.addCell(headersCells); for (int i = 0; i < this.model.getColumnCount(); i++) { if (this.model.isVisible(i)) { final PdfPCell cell = new PdfPCell(new Phrase(Lables.get(this.model.getActualColumnName(i)), font)); cell.setRotation(getRotationDegree()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cell); } } // Please explain pdfPTable.setHeaderRows(3); createPdfFooter(pdfPTable, font); }