List of usage examples for com.itextpdf.text Document addCreationDate
public boolean addCreationDate()
From source file:Sales.SalesController.java
@FXML private void PrintReciept(MouseEvent event) { try {//from w w w . j av a 2 s . co m Image im = Image.getInstance("khamals.png"); FileOutputStream sa = new FileOutputStream("Reciept.pdf"); im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); im.setBackgroundColor(BaseColor.PINK); Document doc = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(doc, sa); PdfPTable table = new PdfPTable(6); String sh = " Date and Time Of Sale : " + Calendar.getInstance().getTime().toGMTString() + "\n\n"; String header = " KHAMALS \n" + " DESIGNER AND SHOWROOM EXPERT \n " + " MOLYKO BUEA LAST FLOOR ECKO BANK BUILDING\n "; String metda = " INVOICE NUMBER :" + this.RecieptId.getText() + " \n " + " SALES PERSON ID :" + this.CashierName.getText() + " \n CUSTOMER NAME :" + this.CustomerName.getText() + "\n\n"; PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); doc.add(im); doc.add(cell); System.out.println(doc.leftMargin()); doc.add(new Paragraph(header)); doc.add(new Paragraph(sh)); doc.add(new Paragraph(metda)); table.addCell("S/N"); table.addCell("PRODUCT NAME"); table.addCell("DESCRIPTION"); table.addCell("QUANTITY"); table.addCell("UNIT PRICE"); table.addCell("TOTAL PRICE"); table.setTotalWidth(1000000); for (int i = 0; i < Cart.getItems().size(); i++) { table.addCell(this.idex.getCellData(i).toString()); table.addCell(this.p.getCellData(i).toString()); table.addCell(this.dsc.getCellData(i).toString()); table.addCell(this.qt.getCellData(i).toString()); table.addCell(this.p.getCellData(i).toString()); table.addCell(this.tp.getCellData(i).toString()); } String footer = " \n Total Amount: " + tot.getText() + "" + " SIGNATURES \n" + "\nCUSTOMER SALES PERSON "; doc.add(table); doc.add(new Paragraph(footer)); doc.addCreationDate(); doc.addAuthor(this.CashierName.getText()); doc.close(); Desktop.getDesktop().open(new File("Reciept.pdf")); } catch (Exception sd) { System.out.println("Error Message :" + sd.getMessage()); } finally { } }
From source file:Servlets.ReportsServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. j ava 2s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Paragraph pp; Paragraph palaglapgh, signParagraph, dateParagrapgh; Chunk chk; Paragraph underText; Chunk chuk1; Chunk chuk2; Paragraph regionText; String x; ResultSet dir; Paragraph regionTexts; String repLot; repLot = request.getParameter("report"); String repNum = request.getParameter("ITLot"); Paragraph newDate; response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); switch (repLot) { default: break; case "IT Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(20f, 20f, 10f, 10f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .25f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "TR Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); //doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .1f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "RP Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFreplants(repNum); try { if (dir.next()) { x = dir.getString(22); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(RPreport(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "Rehab Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(5f, 5f, 3f, 3f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum, bfBold12); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!! try { if (dir.next()) { x = dir.getString(21); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); //Copied CODES break; } } catch (DocumentException ex) { Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:staff.cashier.CashierController.java
@FXML private void onClickGetPayment(ActionEvent e) throws SQLException, IOException, ClassNotFoundException, DocumentException, DecoderException { PendingBill currBill = cashierView.getSelectionModel().getSelectedItem(); System.out.println(currBill.getCusName() + " " + currBill.getOrderID() + " " + currBill.getBill()); int orderid = currBill.getOrderID(); int bill_status = 1; Statement st = conn.createStatement(); Statement st1 = conn.createStatement(); Statement st2 = conn.createStatement(); // set bill status 1 in order_info table. String query = "update order_info set bill_paid='" + bill_status + "' where order_id='" + currBill.getOrderID() + "'"; st.executeUpdate(query);//from w ww . ja v a 2s.c o m // set cus_id=0 in corrosponding table. String query1 = "select * from order_info where order_id='" + currBill.getOrderID() + "'"; ResultSet rs = st1.executeQuery(query1); rs.next(); BigInteger cus_id = new BigInteger(Long.toString(rs.getLong("c_id"))); BigInteger new_cid = BigInteger.ZERO; String query2 = "update table_info set c_id='" + new_cid + "',order_taken=0 where c_id='" + cus_id + "'"; st2.executeUpdate(query2); //deleting the row ObservableList<PendingBill> billSelected, allBill; allBill = cashierView.getItems(); allBill.remove((currBill)); //Inserting into `bill` schema int counter = 0; //fetching the bill_id of the last order query = "select * from bill"; rs = st.executeQuery(query); while (rs.next()) { counter = rs.getInt("bill_id"); } counter++; String query3 = "insert into bill values(" + counter + "," + currBill.bill + ")"; st.executeUpdate(query3); //Updating the bill_generation schema String query4 = "insert into bill_generation values(" + currBill.orderID + ",'" + caid + "'," + counter + ")"; st.executeUpdate(query4); //GENERATING THE BILL IN PDF FORM String query5 = "select * from order_info where order_id=" + orderid + " "; ResultSet rs1 = st.executeQuery(query5); rs1.next(); String itemList = rs1.getString("list"); int tis = rs1.getInt("table_id"); float cc = rs1.getFloat("cost"); //String itemDetails=rs1.getString("item_qty"); int coupon = rs1.getInt("coupon_id"); float disc_p = 0; //FETCHING THE DISCOUNT PERCENT CORRESPONDING TO THAT COUPON if (coupon != 0) { Statement st4 = conn.createStatement(); String q4 = "select discount_percent from coupon where coupon_id=" + coupon; ResultSet rs4 = st4.executeQuery(q4); rs4.next(); disc_p = rs4.getFloat("discount_percent"); } //FETCHING CUSTOMER NAME String query6 = "select * from customer where c_id=" + cus_id + ""; ResultSet rs2 = st.executeQuery(query6); rs2.next(); String cusname = rs2.getString("c_name"); String email = rs2.getString("c_email"); String itemsInfo = ""; /*----------------DESERIALIZATION ByteArrayInputStream in = new ByteArrayInputStream(Hex.decodeHex(itemList.toCharArray())); String[] aa= (String[]) (new ObjectInputStream(in).readObject()); //System.out.println(Arrays.toString(); try{ for (String aa1 : aa) { if(aa1!=null){ int i; String tmp=""; for( i=0;i<(aa1.length()-1);i++) { tmp+=aa1.charAt(i); } int qty=Integer.parseInt(""+aa1.charAt(i)); itemsInfo+="Item name: "+tmp+" Qty:"+qty+"\n\n"; } } } catch(Exception ee){} -----------------------------------------*/ //EXTRACTING INFORMATION ABOUT ORDERED ITEMS String tmp = ""; for (int i = 0; i < (itemList.length() - 1); i++) { if (itemList.charAt(i + 1) == '-') { int qty = Integer.parseInt("" + itemList.charAt(i)); Statement st3 = conn.createStatement(); String q3 = "Select price from menu where d_name='" + tmp + "'"; ResultSet rs3 = st3.executeQuery(q3); rs3.next(); float p = rs3.getFloat("price"); itemsInfo += "Item name:" + tmp + " Qty:" + qty + " Price:+" + p + " Total:" + (qty * p) + "\n\n"; tmp = ""; i++; } else tmp += itemList.charAt(i); } itemsInfo += "Total Cost :" + cc + "\n\n"; if (coupon != 0) { float tprice = cc - ((disc_p * cc) / 100); itemsInfo += "You have been given a discount of " + disc_p + "%\n\nFinal Cost : Rs." + tprice + "\n\n"; } System.out.println("Item info:" + itemsInfo); //WRITING TO PDF Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("Order" + orderid + ".pdf")); doc.open(); doc.addTitle("CENTRICO RESTAURANT"); doc.addCreationDate(); doc.addSubject("BILL"); //System.out.println(itemDetails); doc.add(new Paragraph(" CENTRICO RESTAURANT\n\nORDER ID : " + orderid + "\n\nTABLE ID : " + tis + "\n\nCUSTOMER NAME : " + cusname + "\n\nEMAIL ID : " + email + "\n\n" + itemsInfo + "\n\n")); doc.close(); writer.close(); //SENDING THE BILL IN MAIL TO THE CUSTOMER GmailQuickstart a = new GmailQuickstart(); a.setCusemail(email); a.setCusmessage("Thankyou so much " + cusname + " for coming here.Please visit us again :) \n Please find your bill attached below\n"); a.setCussubject("Bill for order number " + orderid); a.setFileName("Order" + orderid + ".pdf"); Thread t = new Thread(a); t.start(); //alert Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information dialog"); alert.setHeaderText(null); alert.setContentText(" Payment has Received Successfully"); alert.showAndWait(); }
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 w w .jav a 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\\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 {/*from w ww .j a v a 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\\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 {//w w w. ja va 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 == "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 w w .j a v a2s . 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 {// w w w . j a v a2s . 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\\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 .jav a2s . 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 va2s . co 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 == "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 { } }