List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:sipl.recursos.GenerarPDFtipomaterial.java
private static void createTable(Section subCatPart) throws BadElementException { ArrayList<Tipo_material> Tipos = tipDAO.getTipo_material(); PdfPTable table = new PdfPTable(5); PdfPCell c1 = new PdfPCell(new Phrase("Cat.")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//w w w .j a v a 2 s .c o m c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Descripcin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Disponibilidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (Tipos.isEmpty()) { table.addCell("No hay Tipos de Material"); } else { int cont = 0; for (int i = 0; i < Tipos.size(); i++) { table.addCell("" + Tipos.get(i).getId()); table.addCell("" + Tipos.get(i).getNombre()); table.addCell("" + Tipos.get(i).getDescripcion()); table.addCell("" + Tipos.get(i).getCantidad()); table.addCell("" + Tipos.get(i).getDisponibilidad()); cont += Tipos.get(i).getCantidad(); } table.addCell(""); table.addCell(""); table.addCell("Total Materiales"); table.addCell("" + cont); table.addCell(""); } subCatPart.add(table); }
From source file:sistemafacturacionlibros.VentanaCheckout.java
private PdfPTable createTable() throws BadElementException { PdfPTable table = new PdfPTable(7); try {//from ww w .j a va2 s .c o m String sql = "select L.ID, " + "L.Titulo, L.Autor, " + "L.Editora, L.Edicion, " + "C.Precio, C.Cantidad " + "from Libros as L " + "inner join Carrito as C " + "on C.IDLibro = L.ID"; PreparedStatement pst = c.prepareStatement(sql); ResultSet rs = pst.executeQuery(); ResultSetMetaData rsMd = rs.getMetaData(); // int numeroColumnas = rsMd.getColumnCount(); // DefaultTableModel modelo = (DefaultTableModel) chk_table.getModel(); // modelo.setRowCount(0); PdfPCell c1 = new PdfPCell(new Phrase("IDLibro")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Ttulo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Autor")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); c1 = new PdfPCell(new Phrase("Editora")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); c1 = new PdfPCell(new Phrase("Edicin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); c1 = new PdfPCell(new Phrase("Precio")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); while (rs.next()) { table.addCell(rs.getString("ID")); table.addCell(rs.getString("Titulo")); table.addCell(rs.getString("Autor")); table.addCell(rs.getString("Editora")); table.addCell(rs.getString("Edicion")); table.addCell(rs.getString("Cantidad")); table.addCell(rs.getString("Precio")); } pst.close(); rs.close(); } catch (Exception e) { System.out.println("RefreshCarrito" + e.getMessage()); } return table; }
From source file:sqlsentinel.report.PDFGenerator.java
License:Open Source License
private static void createTable(Document document) throws BadElementException, DocumentException { float[] colsWidth = { 2f, 1f }; // Code 1 PdfPTable table = new PdfPTable(colsWidth); table.setWidthPercentage(100);//from w w w . j av a2s .com // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Url")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("type of vulnerability")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < urlVuln.size(); i++) { table.addCell((String) urlVuln.elementAt(i)); table.addCell((String) vulnType.elementAt(i)); } document.add(table); //url crawled table Paragraph preface = new Paragraph(); addEmptyLine(preface, 2); preface.add(new Paragraph("Url Crawled:", catFont)); addEmptyLine(preface, 1); document.add(preface); PdfPTable table2 = new PdfPTable(1); table2.setWidthPercentage(100); table2.setHeaderRows(1); for (int j = 0; j < urlCrawled.size(); j++) table2.addCell((String) urlCrawled.elementAt(j)); document.add(table2); }
From source file:Tables.Printer.java
public void genTrans(TableView gentab, TableColumn name, TableColumn desc, TableColumn amt, TableColumn date, long total, String incOrExp) { try {/*w ww. j ava 2s.com*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\general transactions\\GenTransRec" + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 1.5f, 2f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, "General " + incOrExp + " Transaction Table"); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Transaction Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Description of Transaction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < gentab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, desc.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amt.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, date.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 2, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 3, bfBold12); insertCell(table, "", Element.ALIGN_RIGHT, 4, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); iOException.printStackTrace(); } } catch (Exception sd) { sd.printStackTrace(); Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void overdraft(TableView ovTab, TableColumn name, TableColumn amtIssued, TableColumn monthlyDeduction, TableColumn dateIssued, TableColumn startDeduction, TableColumn expDate, TableColumn payStatus, TableColumn expStatus, long totIssue, long totDeduction) { try {/* ww w . jav a 2 s .com*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\Overdraft\\GenTransRec" + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 3f, 3f, 2f, 1.5f, 1.5f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, "Staff Overdraft Reports"); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Issued", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Monthly Deduction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Start Deduction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Expiry Date", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Pay Status", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Expiry Status", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < ovTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amtIssued.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, monthlyDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, dateIssued.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); insertCell(table, startDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, expDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, payStatus.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, expStatus.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(totIssue), Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, String.valueOf(totDeduction), Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (DocumentException | FileNotFoundException sd) { Action showError = Dialogs .create().title("Printer Error").masthead("Errro In Printing File").message(sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void supCust_DebtIssue(TableView supIssTab, TableColumn name, TableColumn amtOwed, long total, String title, String fileName) { try {/*from w w w.j a va 2s . c o m*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\default" + app + ".pdf"; if (fileName == "SupplierDebt") { file = "\\Documents\\NjieAB_receipts\\supplier\\debt " + app + ".pdf"; } else if (fileName == "CustumerDebt") { file = "\\Documents\\NjieAB_receipts\\custumer\\debt " + app + ".pdf"; } System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings if (fileName == "SupplierDebt") { insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "CustumerDebt") { insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amtOwed.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 2, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void staffBalanceSalary(TableView supIssTab, TableColumn name, TableColumn branch, TableColumn amountLeft, long total) { String fileName = "StaffBalSalaryt"; String title = "Staff Balance Salary"; try {//from w ww . j a v a2 s. c o m // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\staff\\bal " + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 4f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Branch ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Salary Left", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, branch.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amountLeft.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void salarySuspension(TableView supIssTab, TableColumn name, TableColumn amount, TableColumn reason, TableColumn susDate, TableColumn status, long total) { String title = "Salary Suspension"; try {//from w ww. ja v a 2 s.c om // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\staff\\suspension " + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(PageSize.A4, 10, 10, 5, 10); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 6f, 3f, 8f, 3f, 2f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Reason", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Status", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amount.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, reason.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, susDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, status.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void staffSalaryPayments(TableView supIssTab, TableColumn name, TableColumn monthlySalary, TableColumn salaryPaid, TableColumn payDate, long total) { String fileName = "staffPayment"; String title = "Staff Payment History"; try {/*from w ww .j a va 2 s . c o m*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\staff\\pay " + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 6f, 4f, 4f, 4f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Monthly Salary ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Salary Paid", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Payment Date", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, monthlySalary.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, salaryPaid.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, payDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void supCust_PayDebt(TableView supPayTab, TableColumn name, TableColumn debtPayment, TableColumn paymtDate, long total, String title, String fileName) { try {//from w w w . j a v a 2s. com // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\default" + app + ".pdf"; if (fileName == "SupplierDebtPayment") { file = "\\Documents\\NjieAB_receipts\\supplier\\pay " + app + ".pdf"; } else if (fileName == "CustumerDebtPayment") { file = "\\Documents\\NjieAB_receipts\\custumer\\pay " + app + ".pdf"; } else if (fileName == "StaffBalSalaryt") { file = "\\Documents\\NjieAB_receipts\\staff\\balance " + app + ".pdf"; } System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 3f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings if (fileName == "SupplierDebtPayment") { insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "CustumerDebtPayment") { insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "StaffBalSalaryt") { insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Branch", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Balance Amount", Element.ALIGN_MIDDLE, 1, bfBold12); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supPayTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, debtPayment.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, paymtDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 2, bfBold12); insertCell(table, "", Element.ALIGN_RIGHT, 3, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }