List of usage examples for com.itextpdf.text FontFactory getFont
public static Font getFont(final String fontname, final float size, final int style, final BaseColor color)
Font
-object. From source file:EmployeeInfo.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String value1 = txt_empID.getText(); String value2 = txt_firstName.getText(); String value3 = txt_lastName.getText(); String value4 = txt_age.getText(); try {//ww w.j a v a 2s . com Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf")); document.open(); //add barcode PdfContentByte CB = writer.getDirectContent(); BarcodeEAN codEAN = new BarcodeEAN(); codEAN.setCode("1234567891023"); //this value must be 13 digits Paragraph para = new Paragraph(); document.add(new Paragraph("Barcode UDCA")); codEAN.setCodeType(BarcodeEAN.UPCA); codEAN.setCode("1098765432112"); document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK)); document.add(para); Image image = Image.getInstance("images/Cherry.png"); document.add(new Paragraph("Image")); document.add(image); // write tile with style document.add(new Paragraph("Hello World", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); // write date document.add(new Paragraph(new Date().toString())); document.add(new Paragraph("--------------------------------------------")); PdfPTable table = new PdfPTable(2);// 2 columns // set title , column sapn, aliignment,background color PdfPCell cell = new PdfPCell(new Paragraph("Title")); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); // PdfPTable table = new PdfPTable(x); should add multiple of x table.addCell("EmployeeID"); table.addCell(value1); table.addCell("Name"); table.addCell(value2); table.addCell("Last Name"); table.addCell(value3); table.addCell("Age"); table.addCell(value4); document.add(table); List list = new List(true, 20); list.add("First Item"); list.add("Second Item"); list.add("Third Item"); list.add("Fourth Item"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Report saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:imprimer.java
public void openPDF() { Document document = new Document(PageSize.A4); try {/* ww w .ja v a2 s . c om*/ PdfWriter.getInstance(document, new FileOutputStream("imprimer test.pdf")); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Attestation de travail", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 3; i++) { document.add(new Paragraph(" ")); } Paragraph p = new Paragraph(text, FontFactory.getFont(FontFactory.TIMES, 16, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p); Paragraph time = new Paragraph(" Fait Ouarzazate le : " + tdnow, FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY)); Paragraph a = new Paragraph(""); Paragraph si = new Paragraph(" Signature:", FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY)); time.setAlignment(Paragraph.ALIGN_CENTER); si.setAlignment(Paragraph.ALIGN_CENTER); document.add(time); document.add(si); document.add(a); document.close(); System.out.println("date2"); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("imprimer test.pdf")); } else { System.out.println("Open is not supported"); } System.out.println("date"); } catch (Exception ex) { System.out.println("qsdqs"); } }
From source file:imprimer.java
public void attestation_travail_prof() { Document document = new Document(PageSize.A4); try {//from ww w .jav a 2 s .c o m PdfWriter.getInstance(document, new FileOutputStream("Attestation de travail Professeur.pdf")); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Attestation de travail", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 3; i++) { document.add(new Paragraph(" ")); } Paragraph p = new Paragraph(text3, FontFactory.getFont(FontFactory.TIMES, 16, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p); Paragraph time = new Paragraph(" Fait Ouarzazate le : " + tdnow, FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY)); Paragraph a = new Paragraph(""); Paragraph si = new Paragraph(" Signature:", FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY)); time.setAlignment(Paragraph.ALIGN_CENTER); si.setAlignment(Paragraph.ALIGN_CENTER); document.add(time); document.add(si); document.add(a); document.close(); System.out.println("date2"); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("Attestation de travail Professeur.pdf")); } else { System.out.println("Open is not supported"); } System.out.println("date"); } catch (Exception ex) { System.out.println("qsdqs"); } }
From source file:imprimer.java
public void conje() { Document document = new Document(PageSize.A4); try {//from w w w . j a v a2s .c o m PdfWriter.getInstance(document, new FileOutputStream("conjee.pdf")); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Dcision de cong", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } Paragraph p = new Paragraph(text2, FontFactory.getFont(FontFactory.TIMES, 14, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p); Paragraph p3 = new Paragraph("DECIDE :", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); p3.setAlignment(Paragraph.ALIGN_CENTER); document.add(p3); Paragraph p4 = new Paragraph("ARTICLE I Un cong dun .", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p4); Paragraph p5 = new Paragraph( " Est accord : \n" + " C.I.N : \n" + " GRADE : \n" + " Pour la priode : ", FontFactory.getFont(FontFactory.TIMES, 15, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p5); Paragraph p6 = new Paragraph("ARTICLE II", FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p6); Paragraph p7 = new Paragraph( "Lintress(e) est autoris quitter le territoire national durant la priode indique ci-dessus", FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p7); Paragraph p8 = new Paragraph("ARTICLE III", FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p8); Paragraph p9 = new Paragraph( "Lintress(e) est tenu daviser le service du personnel de sa reprise de travail aprs expiration du cong sus-vis.", FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p9); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } Paragraph time = new Paragraph( " Cachet et signature Fait Ouarzazate le :" + tdnow + "\n" + "\n", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); Paragraph si = new Paragraph("Signature du demandeur", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); time.setAlignment(Paragraph.ALIGN_LEFT); si.setAlignment(Paragraph.ALIGN_RIGHT); document.add(time); document.add(si); document.close(); System.out.println("date2"); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("conjee.pdf")); } else { System.out.println("Open is not supported"); } System.out.println("date"); } catch (Exception ex) { System.out.println("qsdqs"); } }
From source file:imprimer.java
public void conje_exp() { Document document = new Document(PageSize.A4); try {// ww w. j a v a 2s . c om PdfWriter.getInstance(document, new FileOutputStream("conjee_exp.pdf")); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Dcision de cong", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } Paragraph p = new Paragraph(text2, FontFactory.getFont(FontFactory.TIMES, 14, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p); Paragraph p3 = new Paragraph("DECIDE :", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); p3.setAlignment(Paragraph.ALIGN_CENTER); document.add(p3); Paragraph p4 = new Paragraph("ARTICLE I", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p4); Paragraph p5 = new Paragraph( " Un cong Exceptionnel dune dure de jours\n" + " Est accord : \n" + " C.I.N : \n" + " GRADE : \n" + " Pour la priode : ", FontFactory.getFont(FontFactory.TIMES, 15, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p5); Paragraph p6 = new Paragraph("ARTICLE II", FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p6); Paragraph p7 = new Paragraph( "Lintress(e) est autoris quitter le territoire national durant la priode indique ci-dessus", FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p7); Paragraph p8 = new Paragraph("ARTICLE III", FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY)); document.add(p8); Paragraph p9 = new Paragraph( "Lintress(e) est tenu daviser le service du personnel de sa reprise de travail aprs expiration du cong sus-vis.", FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY)); document.add(p9); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } Paragraph time = new Paragraph( " Cachet et signature Fait Ouarzazate le :" + tdnow + "\n" + "\n", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); Paragraph si = new Paragraph("Signature du demandeur", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY)); time.setAlignment(Paragraph.ALIGN_LEFT); si.setAlignment(Paragraph.ALIGN_RIGHT); document.add(time); document.add(si); document.close(); System.out.println("date2"); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("conjee_exp.pdf")); } else { System.out.println("Open is not supported"); } System.out.println("date"); } catch (Exception ex) { System.out.println("qsdqs"); } }
From source file:imprimer.java
public void quitter_territoire() { Document document = new Document(PageSize.A4); try {//from ww w . jav a 2s . com PdfWriter.getInstance(document, new FileOutputStream("quitter territoire.pdf")); document.open(); imagee(document); document.open(); imagee(document); SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy"); java.util.Date now = new java.util.Date(); String tdnow = td.format(now); Paragraph pa = new Paragraph("Autorisation de quitter le territoire", FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY)); pa.setAlignment(Paragraph.ALIGN_CENTER); document.add(pa); for (int i = 0; i < 4; i++) { document.add(new Paragraph(" ")); } // cell = new PdfPCell(new Phrase("Fusion de 2 cellules de la premire colonne")); // cell.setRowspan(2); // table.addCell(cell); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(); //contenu du tableau. table.addCell("\nNom:\n\n"); table.addCell("\n\n"); table.addCell("\nPrenom:\n\n"); table.addCell("\n\n"); table.addCell("\nGRADE :\n\n"); table.addCell("\n\n"); table.addCell("\nADRESSE PERSONNELLE :\n\n"); table.addCell("\n\n"); table.addCell("\nAFFECTATION :\n\n"); table.addCell("\n\n"); cell = new PdfPCell( new Phrase("\nJai lhonneur de solliciter une autorisation dabsence.\n\n")); cell.setColspan(2); table.addCell(cell); table.addCell("\nDU:\n\n"); table.addCell("\n\n"); table.addCell("\nAU:\n\n"); table.addCell("\n\n"); table.addCell("\nMOTIF :\n\n"); table.addCell("\n\n"); table.addCell("\nAVIS DU CHEF \nDETABLISSEMENT:\n\n"); table.addCell("\n\nFAVORABLE.def\n\n"); cell = new PdfPCell(new Phrase("\nFait Ouarzazate le :" + tdnow + "\n\n")); cell.setColspan(2); table.addCell(cell); table.addCell("Signature du demandeur\n\n\n\n\n\n\n\n\n"); table.addCell("Cachet et signature\n\n\n\n\n\n\n\n"); document.add(table); document.close(); Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("quitter territoire.pdf")); } else { System.out.println("Open is not supported"); } } catch (Exception ex) { System.out.print("catch"); } }
From source file:ApplicationClasses.Reservation.ReservationInvoice.java
public void generatePDFinvoice(ReservationCustomer cus) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 0); String date2 = dateFormat.format(c.getTime()); Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(this.invoiceNo + ".pdf")); doc.open();//from ww w . j a v a 2s . c o m doc.add(new Paragraph("CREATE TOURS PVT LTD", FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD, BaseColor.RED))); Paragraph p = new Paragraph(); p.add("Reservation Invoice"); p.add("\n INVOICE DATE : " + date2); p.setAlignment(Paragraph.ALIGN_CENTER); doc.add(p); doc.add(new Paragraph(cus.getCustomerName())); doc.add(new Paragraph( "-------------------------------------------------------------------------------------------------------------------------------")); //doc.add(new Paragraph("Deposit : " + this.deposit.toString() + "\t Resvation Start Date : " + this.reservationEndDate + "\t Reservation End Date : "+this.reservationEndDate )); PdfPTable table = new PdfPTable(4); table.addCell("No"); table.addCell("Description"); table.addCell("VehicalRegNo"); table.addCell("Price"); for (int i = 0; i < invoiceDataArray.size(); i++) { Integer no = i + 1; table.addCell(no.toString()); table.addCell(invoiceDataArray.get(i).getDescription()); table.addCell(invoiceDataArray.get(i).getRegNo()); table.addCell(invoiceDataArray.get(i).getPrice().toString()); } doc.add(table); doc.add(new Paragraph("Total Cost :" + this.totalPrice.toString())); doc.add(new Paragraph("Deposit : " + this.deposit.toString())); doc.add(new Paragraph("Resvation Start Date : " + this.reservationStartDate)); doc.add(new Paragraph("Reservation End Date : " + this.reservationEndDate)); doc.close(); }
From source file:AppPackage.printPDF.java
public void printNow(String id, String name, String dateRange, String underLate, String workedHours, String totalHours, String dateNow, String fDate, String lDate, String type, String empTypeRate, int lastRId, double salary) { this.id = id; this.name = name; this.dateRange = dateRange; this.underLate = underLate; this.workedHours = workedHours; this.totalHours = totalHours; this.dateNow = dateNow; this.fDate = fDate; this.lDate = lDate; this.type = type; this.empTypeRate = empTypeRate; this.lastRId = lastRId; this.salary = salary; try {// w w w . j av a 2s . com Document document = new Document(); Connection conn = null; Statement st = null; conn = dbC.getConnection(); st = conn.createStatement(); String query = "SELECT * FROM schedule WHERE empId ='" + id + "'"; ResultSet rs = st.executeQuery(query); PdfWriter.getInstance(document, new FileOutputStream("reports/Report-" + reportCount + "." + lastRId + "-" + id + ".pdf")); document.open(); document.setPageSize(PageSize.LETTER); document.setMargins(0f, 0f, 0f, 0f); Image image = Image.getInstance("Resources/DTRHeaderTwo.png"); document.add(image); PdfPTable ICTable = new PdfPTable(5); ICTable.setWidthPercentage(100); ICTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell ICTableCell; Phrase ICBlank = new Phrase(); Phrase ICharge = new Phrase(); Phrase ICBlanko = new Phrase(); Phrase ICBlankx = new Phrase(); Phrase IChargex = new Phrase(); ICBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlank); ICharge.add(new Chunk("_____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(ICharge); ICBlanko.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlanko); ICBlankx.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlankx); IChargex.add(new Chunk("____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(IChargex); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); PdfPTable dateRecTable = new PdfPTable(5); dateRecTable.setWidthPercentage(100); dateRecTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell dateRecTableCell; Phrase dRDate = new Phrase(); Phrase dRNo = new Phrase(); Phrase dRBlank = new Phrase(); Phrase dRDatex = new Phrase(); Phrase dRNox = new Phrase(); dRDate.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDate); dRNo.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNo); dRBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRBlank); dRDatex.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDatex); dRNox.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNox); PdfPTable InfoTable = new PdfPTable(5); InfoTable.setWidthPercentage(100); InfoTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell InfoTableCell; Phrase infoId = new Phrase(); Phrase infoType = new Phrase(); Phrase infoBlank = new Phrase(); Phrase infoIdx = new Phrase(); Phrase infoTypex = new Phrase(); infoId.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoId); infoType.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoType); infoBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoBlank); infoIdx.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoIdx); infoTypex.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoTypex); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); PdfPTable SchedTable = new PdfPTable(17); SchedTable.setWidthPercentage(100); SchedTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell SchedTableCell; Phrase phraseDayS = new Phrase(); Phrase phraseAMTotal = new Phrase(); Phrase phraseAMStart = new Phrase(); Phrase phraseAMEnd = new Phrase(); Phrase phrasePMTotal = new Phrase(); Phrase phrasePMStart = new Phrase(); Phrase phrasePMEnd = new Phrase(); Phrase phraseTotalTime = new Phrase(); Phrase phraseBlankS = new Phrase(); Phrase phraseDaySx = new Phrase(); Phrase phraseAMTotalx = new Phrase(); Phrase phraseAMStartx = new Phrase(); Phrase phraseAMEndx = new Phrase(); Phrase phrasePMTotalx = new Phrase(); Phrase phrasePMStartx = new Phrase(); Phrase phrasePMEndx = new Phrase(); Phrase phraseTotalTimex = new Phrase(); phraseDayS.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDayS); phraseAMStart.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStart); phraseAMEnd.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEnd); phraseAMTotal.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotal); phrasePMStart.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStart); phrasePMEnd.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEnd); phrasePMTotal.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotal); phraseTotalTime.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTime); phraseBlankS.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseBlankS); phraseDaySx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDaySx); phraseAMStartx.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStartx); phraseAMEndx.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEndx); phraseAMTotalx.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotalx); phrasePMStartx.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStartx); phrasePMEndx.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEndx); phrasePMTotalx.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotalx); phraseTotalTimex.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTimex); while (rs.next()) { SimpleDateFormat readingFormat = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat outputFormat = new SimpleDateFormat("hh:mm a"); String dayxxx = rs.getString("day"); String amStartxx = rs.getString("amStart"); String amEndxx = rs.getString("amEnd"); String pmStartxx = rs.getString("pmStart"); String pmEndxx = rs.getString("pmEnd"); String amTotalxx = rs.getString("amTotal"); String pmTotalxx = rs.getString("pmTotal"); String totalHoursxx = rs.getString("totalTime"); String blank = " "; String amStart = null; String amEnd = null; String amTotal = null; String pmStart = null; String pmEnd = null; String pmTotal = null; String totalHoursx = null; Date dayx = new SimpleDateFormat("EEEE").parse(dayxxx); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String day = sdfxxx.format(dayx); System.out.println(day + " day"); try { Date amStartTxx = readingFormat.parse(amStartxx); amStart = outputFormat.format(amStartTxx); if (amStart.equals("12:00 AM")) { amStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amEndTx = readingFormat.parse(amEndxx); amEnd = outputFormat.format(amEndTx); if (amEnd.equals("12:00 AM")) { amEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amTotalTx = readingFormat.parse(amTotalxx); amTotal = outputFormat.format(amTotalTx); if (amTotal.equals("12:00 AM")) { amTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmStartTxx = readingFormat.parse(pmStartxx); pmStart = outputFormat.format(pmStartTxx); if (pmStart.equals("12:00 AM")) { pmStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmEndTxx = readingFormat.parse(pmEndxx); pmEnd = outputFormat.format(pmEndTxx); if (pmEnd.equals("12:00 AM")) { pmEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmTotalTxx = readingFormat.parse(pmTotalxx); pmTotal = outputFormat.format(pmTotalTxx); if (pmTotal.equals("12:00 AM")) { pmTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date totalHoursxT = readingFormat.parse(totalHoursxx); totalHoursx = outputFormat.format(totalHoursxT); if (totalHoursx.equals("12:00 AM")) { totalHoursx = "00:00"; } } catch (Exception e) { e.printStackTrace(); } System.out.println(day); System.out.println(amStart); System.out.println(amEnd); System.out.println(amTotal); System.out.println(pmStart); System.out.println(pmEnd); System.out.println(pmTotal); System.out.println(totalHoursx); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(blank)); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); } PdfPTable DTRTable = new PdfPTable(17); DTRTable.setWidthPercentage(100); DTRTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell DTRTableCell; Phrase phraseDay = new Phrase(); Phrase phraseDate = new Phrase(); Phrase phraseAMIn = new Phrase(); Phrase phraseAMOut = new Phrase(); Phrase phrasePMIn = new Phrase(); Phrase phrasePMOut = new Phrase(); Phrase phraseHours = new Phrase(); Phrase phraseUTL = new Phrase(); Phrase phraseBlank = new Phrase(); Phrase phraseDayx = new Phrase(); Phrase phraseDatex = new Phrase(); Phrase phraseAMInx = new Phrase(); Phrase phraseAMOutx = new Phrase(); Phrase phrasePMInx = new Phrase(); Phrase phrasePMOutx = new Phrase(); Phrase phraseHoursx = new Phrase(); Phrase phraseUTLx = new Phrase(); phraseDay.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDay); phraseDate.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDate); phraseAMIn.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMIn); phraseAMOut.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOut); phrasePMIn.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMIn); phrasePMOut.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOut); phraseHours.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHours); phraseUTL.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTL); phraseBlank.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseBlank); phraseDayx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDayx); phraseDatex.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDatex); phraseAMInx.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMInx); phraseAMOutx.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOutx); phrasePMInx.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMInx); phrasePMOutx.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOutx); phraseHoursx.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHoursx); phraseUTLx.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTLx); try { Connection connx = null; Statement stx = null; connx = dbC.getConnection(); stx = connx.createStatement(); String queryx = "SELECT timeinout.day, timeinout.date, schedule.totalTime, schedule.amTotal, " + "schedule.amStart, timeinout.amTimeIn, schedule.amEnd, timeinout.amTimeOut, " + "schedule.pmTotal, schedule.pmStart, timeinout.pmTimeIn, schedule.pmEnd, " + "timeinout.pmTimeOut FROM timeinout LEFT JOIN " + "(schedule) ON (schedule.empId = timeinout.empId AND timeinout.day = schedule.day) WHERE " + "timeinout.empId ='" + id + "' AND schedule.empId = '" + id + "' AND date(`Date`) >= '" + fDate + "' " + "AND date(`Date`) <= '" + lDate + "'"; ResultSet rsx = stx.executeQuery(queryx); while (rsx.next()) { String day = rsx.getString("timeinout.day"); String date = rsx.getString("timeinout.date"); String amStartDB = rsx.getString("schedule.amStart"); String amIn = rsx.getString("timeinout.amTimeIn"); String amEndDB = rsx.getString("schedule.amEnd"); String amOut = rsx.getString("timeinout.amTimeOut"); String pmStartDB = rsx.getString("schedule.pmStart"); String pmIn = rsx.getString("timeinout.pmTimeIn"); String pmEndDB = rsx.getString("schedule.pmEnd"); String pmOut = rsx.getString("timeinout.pmTimeOut"); String totTime = rsx.getString("schedule.totalTime"); String wHours; String blank = " "; String dayx = rsx.getString("timeinout.day"); String datex = rsx.getString("timeinout.date"); // String amStartDBx = rsx.getString("schedule.amStart"); // String amInx = rsx.getString("timeinout.amTimeIn"); // String amEndDBx = rsx.getString("schedule.amEnd"); // String amOutx = rsx.getString("timeinout.amTimeOut"); // String pmStartDBx = rsx.getString("schedule.pmStart"); // String pmInx = rsx.getString("timeinout.pmTimeIn"); // String pmEndDBx = rsx.getString("schedule.pmEnd"); String pmOutx = rsx.getString("timeinout.pmTimeOut"); String totalAM = rsx.getString("schedule.amTotal"); String totalPM = rsx.getString("schedule.pmTotal"); String totTimex = rsx.getString("schedule.totalTime"); String wHoursx; parser.setTimeZone(TimeZone.getTimeZone("UTC")); if (!amEndDB.equals("00:00:00") && !amOut.equals("00:00:00")) { Start = parser.parse(amEndDB); In = parser.parse(amOut); if (Start.after(In)) { amOutDiff = tDiff.timeDiff(amOut, amEndDB); amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } else { amOutDiff = "00:00:00"; } } else { amOutDiff = totalAM; amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } Start = parser.parse(amStartDB); In = parser.parse(amIn); if (Start.after(In)) { amInDiff = "00:00:00"; } else if (amOutDiff.equals(totalAM)) { amInDiff = "00:00:00"; } else { amInDiff = tDiff.timeDiff(amStartDB, amIn); amInDiffT = parser.parse(amInDiff); amInDiffTotal += amInDiffT.getTime(); } if (!pmEndDB.equals("00:00:00") && !pmOut.equals("00:00:00")) { Start = parser.parse(pmEndDB); In = parser.parse(pmOut); if (Start.after(In)) { pmOutDiff = tDiff.timeDiff(pmOut, pmEndDB); pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } else { pmOutDiff = "00:00:00"; } } else { pmOutDiff = totalPM; pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } Start = parser.parse(pmStartDB); In = parser.parse(pmIn); if (Start.after(In)) { pmInDiff = "00:00:00"; } else if (pmOutDiff.equals(totalPM)) { pmInDiff = "00:00:00"; } else { pmInDiff = tDiff.timeDiff(pmStartDB, pmIn); pmInDiffT = parser.parse(pmInDiff); pmInDiffTotal += pmInDiffT.getTime(); } Date totH = parser.parse(totTimex); long totHTotal = 0; totHTotal += totH.getTime(); Date amInDiffx = parser.parse(amInDiff); Date amOutDiffx = parser.parse(amOutDiff); Date pmInDiffx = parser.parse(pmInDiff); Date pmOutDiffx = parser.parse(pmOutDiff); long workedHoursxxx = amInDiffx.getTime() + amOutDiffx.getTime() + pmInDiffx.getTime() + pmOutDiffx.getTime(); long hoursx = workedHoursxxx / 3600000; long minutesx = (workedHoursxxx % 3600000) / 60000; wHours = String.format("%02d:%02d", hoursx, minutesx); wHoursx = String.format("%02d:%02d", hoursx, minutesx); Date dayxxx = new SimpleDateFormat("EEEE").parse(day); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String newDayxx = sdfxxx.format(dayxxx); System.out.println(newDayxx); DTRTableCell = new PdfPCell( new Phrase(newDayxx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexx = new SimpleDateFormat("yyyy-MM-dd").parse(date); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy"); String newDate = sdf.format(datexx); System.out.println(newDate); DTRTableCell = new PdfPCell( new Phrase(newDate, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOut); DTRTableCell = new PdfPCell( new Phrase(pmOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTime); DTRTableCell = new PdfPCell( new Phrase(totTime, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHours); DTRTableCell = new PdfPCell( new Phrase(wHours, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(blank); DTRTableCell = new PdfPCell(new Phrase(blank)); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date dayxx = new SimpleDateFormat("EEEE").parse(dayx); SimpleDateFormat sdfxx = new SimpleDateFormat("EEE"); String newDayx = sdfxx.format(dayxx); System.out.println(newDayx); DTRTableCell = new PdfPCell( new Phrase(newDayx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexxx = new SimpleDateFormat("yyyy-MM-dd").parse(datex); SimpleDateFormat sdfx = new SimpleDateFormat("dd-MM-yy"); String newDatex = sdfx.format(datexxx); System.out.println(newDatex); DTRTableCell = new PdfPCell( new Phrase(newDatex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOutx); DTRTableCell = new PdfPCell( new Phrase(pmOutx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTimex); DTRTableCell = new PdfPCell( new Phrase(totTimex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHoursx); DTRTableCell = new PdfPCell( new Phrase(wHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } document.add(dateRecTable); document.add(InfoTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Schedule Schedule\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(SchedTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Dailty Time Record Dailty Time Record\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(DTRTable); document.add(ICTable); try { conn = dbC.getConnection(); PreparedStatement stmtx = conn.prepareStatement("INSERT INTO released" + "(empId, firstDate, lastDate, totalHours, lateUnderTime, workedHours, fileName, salary) VALUES (?,?,?,?,?,?,?,?)"); stmtx.setString(1, id); stmtx.setString(2, fDate); stmtx.setString(3, lDate); stmtx.setString(4, totalHours); stmtx.setString(5, workedHours); stmtx.setString(6, totalHours); stmtx.setString(7, "Report-" + reportCount + "." + lastRId + "-" + id + ".pdf"); stmtx.setString(8, salary + ""); stmtx.executeUpdate(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) conn.close(); } catch (SQLException se) { } // do nothing try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try document.close(); } catch (DocumentException | IOException | SQLException e) { JOptionPane.showMessageDialog(null, e); } catch (ParseException ex) { Logger.getLogger(printPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:bemyguest.controller.ValidationResevation.java
@FXML private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException { Resrevation e = tab_reservation.getSelectionModel().getSelectedItem(); if (e == null) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Warning Dialog"); alert.setHeaderText(null);//from w ww .ja v a2 s .co m alert.setContentText("selectionner un demande de reservation a traiter svp!"); alert.showAndWait(); LoadData(); setCellTable(); } else { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Confiramtion"); alert.setHeaderText(null); alert.setContentText("vous etes sur d'accepter cette demande de reservation"); Optional<ButtonType> answer = alert.showAndWait(); if (answer.get() == ButtonType.OK) { ResevationDAO dao = new ResevationDAO(); if (dao.ajouter_Reservation(e)) { LoadData(); setCellTable(); alert.setTitle("Success Dialog"); alert.setHeaderText(null); alert.setContentText("Demandes accepter avec success"); alert.showAndWait(); try { Document d = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf")); d.open(); d.add(new Paragraph("BeMyGuest Facture :", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); d.add(new Paragraph(new Date().toString())); d.add(new Paragraph( "-------------------------------------------------------------------------------------------------------------")); d.add(new Paragraph(" ")); d.add(new Paragraph(" ")); PdfPTable pdt = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.RED); pdt.addCell(cell); pdt.addCell(new Paragraph("Nom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prenom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Debut:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Fin:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre chambre:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre personne:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prix:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getNom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateDebut().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateFin().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(e.getDateDebut().toString()); int nb = e.getPropriete().getNbrChambre(); float pr = e.getPropriete().getPrix(); int nbp = e.getPropriete().getNbrVoyageur(); pdt.addCell(new Paragraph(Integer.toString(nb), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Integer.toString(nbp), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Float.toString(pr), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(Float.toString(pr)); d.add(pdt); d.close(); } catch (Exception b) { JOptionPane.showMessageDialog(null, b); } } else { alert.setTitle("Error Dialog"); alert.setHeaderText(null); alert.setContentText("Cette Propriete Reserver pendant cette date "); alert.showAndWait(); LoadData(); setCellTable(); } } else { LoadData(); setCellTable(); } } }
From source file:Boss.BOss.java
private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked if (evt.getClickCount() == 2) { try {//from ww w . java2 s. com connect = new Connection(); Statement st = connect.con.createStatement(); String SQL = "SELECT * FROM request where idrequest =" + getSelectedrequest1(); ResultSet rq = st.executeQuery(SQL); rq.next(); /*****************************/ String type = ""; if (parseInt(rq.getString("id_type")) == 1) { type = "Instalation"; } if (parseInt(rq.getString("id_type")) == 2) { type = "Transfer"; } if (parseInt(rq.getString("id_type")) == 3) { type = "Maintenamce"; } /**************************/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("report.pdf")); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph("Request : \n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY))); paragraph.add("ID Request :"); paragraph.add(rq.getString("idRequest") + ""); paragraph.add("\nRequest type :"); paragraph.add(type); paragraph.add("\nClient name :"); paragraph.add(rq.getString("clientName")); paragraph.add("\nPhone number :"); paragraph.add(rq.getString("TELCLIENT")); paragraph.add("\nAddress 1 :"); paragraph.add(rq.getString("address1")); paragraph.add("\nAddress 2 :"); paragraph.add(rq.getString("address2")); paragraph.add("\nTeam :"); paragraph.add(rq.getString("IDTEAM") + "\n"); /***********************/ String sql = "Select * from report where IDREQUEST = '" + getSelectedrequest1() + "' "; ResultSet rs = st.executeQuery(sql); rs.next(); /**********************/ paragraph.add(new Paragraph("Report : \n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY))); paragraph.add(rs.getString("REPORT") + "\n"); Paragraph date = new Paragraph(rs.getString("REPORTDATE").toString().substring(0, 10)); date.setAlignment(Element.ALIGN_RIGHT); Paragraph title = new Paragraph("Report\n", FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.BLACK)); title.setAlignment(Element.ALIGN_CENTER); document.add(date); document.add(title); document.add(paragraph); document.close(); /* Open Pdf */ Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("report.pdf")); } else { System.out.println("Open is not supported"); } } catch (SQLException | ClassNotFoundException | DocumentException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex); } } }