List of usage examples for com.itextpdf.text.pdf PdfPCell PdfPCell
public PdfPCell(PdfPCell cell)
PdfPCell
. From source file:adams.flow.transformer.pdfproclet.SpreadSheet.java
License:Open Source License
/** * The actual processing of the document. * * @param generator the context/*from w w w .j av a 2 s.c o m*/ * @param sheet the spreadsheet to add * @return true if successfully added * @throws Exception if something goes wrong */ protected boolean doProcess(PDFGenerator generator, adams.data.spreadsheet.SpreadSheet sheet) throws Exception { boolean result; Row row; Cell cell; int i; PdfPTable table; PdfPCell pdfCell; String pattern; DecimalFormat format; Paragraph para; Paragraph paraComments; ColumnText ct; pattern = "#0"; for (i = 0; i < m_NumDecimals; i++) { if (i == 0) pattern += "."; pattern += "0"; } format = new DecimalFormat(pattern); result = (sheet != null); if (!result) return false; // comments paraComments = null; if (m_AddComments) paraComments = new Paragraph(Utils.flatten(sheet.getComments(), "\n"), m_FontComments.toFont(m_ColorComments)); // table // 1. header table = new PdfPTable(sheet.getColumnCount()); row = sheet.getHeaderRow(); for (String key : sheet.getHeaderRow().cellKeys()) { cell = row.getCell(key); para = new Paragraph(cell.toString(), m_FontTableHeader.toFont(m_ColorTableHeader)); pdfCell = new PdfPCell(para); pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(pdfCell); } // 2. data for (i = 0; i < sheet.getRowCount(); i++) { row = sheet.getRow(i); for (String key : sheet.getHeaderRow().cellKeys()) { cell = row.getCell(key); if ((cell == null) || cell.isMissing()) { pdfCell = new PdfPCell(new Paragraph("")); } else if (cell.isNumeric()) { pdfCell = new PdfPCell(new Paragraph(format.format(cell.toDouble()), m_FontNumericContent.toFont(m_ColorNumericContent))); pdfCell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { pdfCell = new PdfPCell( new Paragraph(cell.toString(), m_FontGeneralContent.toFont(m_ColorGeneralContent))); pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT); } table.addCell(pdfCell); } } if (m_UseAbsolutePosition) { ct = addColumnTextAt(generator, m_X, m_Y); if (paraComments != null) { ct.addElement(paraComments); ct.addElement(new Paragraph("\n")); } ct.addElement(new Paragraph("\n")); ct.addElement(table); ct.go(); generator.getState().contentAdded(); } else { if (paraComments != null) { result = addElement(generator, paraComments); if (result) result = addElement(generator, new Paragraph("\n")); } if (result) result = addElement(generator, new Paragraph("\n")); if (result) result = addElement(generator, table); } return result; }
From source file:alessandrafx.MarcoVentanaController.java
@FXML private void generarReporteMenusal(MouseEvent event) { try {/*ww w.j av a 2s. c om*/ FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("Reporte.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); SistemaAleMC sistema = new SistemaAleMC(); Double balanceMonetario = 0.0; //Para salidas de dinero ArrayList<Capital> capitales = sistema.getRegistrosCapitalTipo('S'); cell = new PdfPCell(new Phrase("Gastos y pagos realizados")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de salidas de dinero Double totalEgreso = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario -= Double.valueOf(capital.getMonto()); totalEgreso -= Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE EGRESOS")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalEgreso.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de mensualidades capitales = sistema.getRegistrosCapitalTipo('M'); cell = new PdfPCell(new Phrase("Pagos de mensualidad recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de mensualidades de los alumnos Double totalIngresoMen = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoMen += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE MENSUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoMen.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Para Pago de anualidades capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Pagos de anualidades recibidos")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega los registros de pago de anualidades de los alumnos Double totalIngresoAnu = 0.0; if (capitales.isEmpty()) { cell = new PdfPCell(new Phrase(" --- ")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(" --- ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } for (Capital capital : capitales) { cell = new PdfPCell(new Phrase(capital.getMotivo().toString())); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(capital.getMonto().toString())); balanceMonetario += Double.valueOf(capital.getMonto()); totalIngresoAnu += Double.valueOf(capital.getMonto()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } cell = new PdfPCell(new Phrase("TOTAL DE ANUALIDADES")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalIngresoAnu.toString())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //PARA EL BALANCE MONETARIO capitales = sistema.getRegistrosCapitalTipo('A'); cell = new PdfPCell(new Phrase("Total")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega la celda del total monetario if (balanceMonetario == (Double) 0.0) { cell = new PdfPCell(new Phrase("No hubieron movimientos este mes")); } else { cell = new PdfPCell(new Phrase(balanceMonetario.toString())); } cell.setColspan(3); cell.setBackgroundColor(BaseColor.WHITE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Corre a ver tu PDF!"); alerta.setHeaderText(null); alerta.setContentText("El PDF ha sido generado, puedes revisarlo"); alerta.showAndWait(); } catch (Exception e) { Alert alerta = new Alert(Alert.AlertType.INFORMATION); alerta.setTitle("Lo sentimos"); alerta.setHeaderText(null); alerta.setContentText("La ubicacin seleccionada no es vlida y por tanto, no se generar el PDF"); alerta.showAndWait(); } }
From source file:alessandrafx.VentanaEgresoController.java
private void generarReportePagoColaborador(int pagoColaborador, int pagoSugerido) throws DatoFaltante { try {/*from ww w . j a v a 2 s . c om*/ FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaNueva.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el pago IDEAL cell = new PdfPCell(new Phrase("Pago sugerido recibido")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase("Pago sugerido")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el pago realizado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(pagoColaborador))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
From source file:alessandrafx.VentanaEgresoController.java
private void generarReporteOtroGasto(int cantidad, String motivo) throws DatoFaltante { try {// w w w .jav a 2s .c o m FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaHecha.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el monto pagado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(cantidad))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el motivo del pago cell = new PdfPCell(new Phrase("Motivo: \n" + motivo)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(3); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
From source file:alessandrafx.VentanaIngresoController.java
public void generarReportePago(String pagoSugerido, String pagoRealizado) throws DatoFaltante { try {//from w w w .j a v a2 s . c o m FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName("facturaNueva.pdf"); File file = fileChooser.showSaveDialog(null); file.getParentFile().mkdir(); Document document = new Document(); try { try { PdfWriter.getInstance(document, new FileOutputStream(file)); } catch (FileNotFoundException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date())); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); //Agrega el pago IDEAL cell = new PdfPCell(new Phrase("Pago sugerido recibido")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(pagoSugerido)); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); //Agrega el pago realizado cell = new PdfPCell(new Phrase("Pago realizado")); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(pagoRealizado))); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex); } document.close(); } catch (Exception e) { throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida"); } }
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 {//from w w w . j av a 2 s . co m 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:basiclayout.ReportFrame.java
public ReportFrame(DefaultTableModel subtotal_model, String st1_date, String e1_date) throws DocumentException, IOException { this();/* w ww. j a va2 s . c om*/ report_model = (DefaultTableModel) reportTable.getModel(); reportTable.setRowSelectionAllowed(true); reportTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); document = new Document(); try { initialize_connection(); PdfWriter.getInstance((com.itextpdf.text.Document) document, new FileOutputStream("C:\\Users\\jaina_000\\Desktop\\test.pdf")); document.open(); table = new PdfPTable(5); table.setWidthPercentage(300 / 3f); table.setWidths(new int[] { 3, 3, 3, 3, 3 }); PdfPCell cell; cell = new PdfPCell(new Phrase("Category")); table.addCell(cell); cell = new PdfPCell(new Phrase("Title")); table.addCell(cell); cell = new PdfPCell(new Phrase("Date")); table.addCell(cell); cell = new PdfPCell(new Phrase("Amount")); table.addCell(cell); cell = new PdfPCell(new Phrase("Details")); table.addCell(cell); cell.setRowspan(5); final_total = 0; for (int i = 0; i < subtotal_model.getRowCount(); i++) { String subt_cat = subtotal_model.getValueAt(i, 0).toString(); resultset1 = statement1 .executeQuery("Select * from " + tableC + " WHERE CategoryName='" + subt_cat + "'"); resultset1.next(); resultset2 = statement2 .executeQuery("Select * from " + tableE + " WHERE CategoryId= '" + resultset1.getString(1) + "' " + "AND (Date BETWEEN '" + st1_date + "' AND '" + e1_date + "')"); sub_amt = 0; System.out.print("\n\nCategory: " + resultset1.getString(2)); rep_row[0] = resultset1.getString(2); for (int z = 1; z < 5; z++) { rep_row[z] = null; } report_model.addRow(rep_row); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); cell.setRowspan(5); while (resultset2.next()) { rep_row[0] = null; System.out.print("\nTitle : " + resultset2.getString(5)); // Title rep_row[1] = resultset2.getString(5); System.out.print("\tDate : " + resultset2.getString(2)); // Date rep_row[2] = resultset2.getString(2); System.out.print("\tAmount: " + Math.abs(Integer.parseInt(resultset2.getString(4)))); rep_row[3] = Math.abs(Integer.parseInt(resultset2.getString(4))); System.out.print("\tDescription : " + resultset2.getString(6)); // Description rep_row[4] = resultset2.getString(6); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); sub_amt += Integer.parseInt(resultset2.getString(4)); report_model.addRow(rep_row); cell.setRowspan(5); } final_total += sub_amt; for (int z = 0; z < 5; z++) { rep_row[z] = null; } rep_row[2] = "Subtotal"; rep_row[3] = Math.abs(sub_amt); System.out.println("\nCategory Subtotal : " + Math.abs(sub_amt)); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); report_model.addRow(rep_row); cell.setRowspan(5); } for (int z = 0; z < 5; z++) { rep_row[z] = null; } report_model.addRow(rep_row); report_model.addRow(rep_row); System.out.print("\n\nFinal total: " + Math.abs(final_total)); rep_row[2] = "Final Total"; rep_row[3] = Math.abs(final_total); if (final_total < 0) { System.out.println(" (Expense)"); rep_row[4] = "(Expense)"; } else { System.out.println(" (Income)"); rep_row[4] = "(Income)"; } table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); report_model.addRow(rep_row); cell.setRowspan(5); } catch (ClassNotFoundException | SQLException e) { } catch (FileNotFoundException ex) { Logger.getLogger(ReportFrame.class.getName()).log(Level.SEVERE, null, ex); } finally { close_connection(); } }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
protected void printActiveDiagnosis(SessionContainerWO sessionContainerWO) { try {/* w ww. j a v a 2 s.c o m*/ Vector activeProblems = Problem.getActiveProblems(patient.personid); if (activeProblems.size() > 0) { doc.add(new Paragraph(" ")); table = new PdfPTable(1); table.setWidthPercentage(100); // title cell = new PdfPCell(new Paragraph(getTran("web.occup", "medwan.common.problemlist").toUpperCase(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(1); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); // run thru diagnoses Problem activeProblem; String value; for (int n = 0; n < activeProblems.size(); n++) { activeProblem = (Problem) activeProblems.elementAt(n); value = MedwanQuery.getInstance().getCodeTran( activeProblem.getCodeType() + "code" + activeProblem.getCode(), sPrintLanguage); cell = new PdfPCell(new Paragraph( value + " (" + getTran("Web", "since") + " " + dateFormat.format(activeProblem.getBegin()) + ")", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); cell.setColspan(1); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); } doc.add(table); } } catch (Exception e) { e.printStackTrace(); } }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
protected void printWarnings(SessionContainerWO sessionContainerWO) { try {/*from w w w. j a v a 2 s. c o m*/ if (sessionContainerWO.getHealthRecordVO() != null) { Collection alerts = MedwanQuery.getInstance().getTransactionsByType( sessionContainerWO.getHealthRecordVO(), IConstants.TRANSACTION_TYPE_ALERT); sessionContainerWO.setAlerts(alerts); if (sessionContainerWO.getActiveAlerts().size() > 0) { doc.add(new Paragraph(" ")); table = new PdfPTable(4); table.setWidthPercentage(100); // title cell = new PdfPCell(new Paragraph(getTran("curative", "warning.status.title").toUpperCase(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(4); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); // list alerts Collection activeAlerts = sessionContainerWO.getActiveAlerts(); Iterator alertsIter = activeAlerts.iterator(); TransactionVO transactionVO; String sLabel, sComment; ItemVO itemVO; while (alertsIter.hasNext()) { transactionVO = (TransactionVO) alertsIter.next(); // label sLabel = ""; itemVO = transactionVO.getItem(IConstants_PREFIX + "ITEM_TYPE_ALERTS_LABEL"); if (itemVO != null) { sLabel = checkString(itemVO.getValue()); } cell = new PdfPCell(new Paragraph(sLabel, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); cell.setColspan(1); cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); // comment sComment = ""; itemVO = transactionVO.getItem(IConstants_PREFIX + "ITEM_TYPE_ALERTS_DESCRIPTION"); if (itemVO != null) { sComment = checkString(itemVO.getValue()); } cell = new PdfPCell(new Paragraph(sComment, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); cell.setColspan(4); cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); } doc.add(table); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
protected void printMedication(SessionContainerWO sessionContainerWO) { try {// www .j a va2 s. co m doc.add(new Paragraph(" ")); table = new PdfPTable(2); table.setWidthPercentage(100); // main title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.status.title").toUpperCase(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); Vector chronicMedications = ChronicMedication.find(patient.personid, "", "", "", "OC_CHRONICMED_BEGIN", "ASC"), activePrescriptions = Prescription.getActivePrescriptions(patient.personid); //*** CHRONIC MEDICATION ****************************************** if (chronicMedications.size() > 0) { PdfPTable medicationTable = new PdfPTable(2); // sub title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.chronic"), FontFactory.getFont( FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); cell.setBackgroundColor(BGCOLOR_LIGHT); medicationTable.addCell(cell); // run thru medications String sPrescrRule, sProductUnit, timeUnitTran; ChronicMedication medication; for (int n = 0; n < chronicMedications.size(); n++) { medication = (ChronicMedication) chronicMedications.elementAt(n); sPrescrRule = getTran("web.prescriptions", "prescriptionrule"); sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#", medication.getUnitsPerTimeUnit() + ""); // productunits if (medication.getUnitsPerTimeUnit() == 1) { sProductUnit = getTran("product.unit", medication.getProduct().getUnit()); } else { sProductUnit = getTran("product.units", medication.getProduct().getUnit()); } sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase()); // timeunits if (medication.getTimeUnitCount() == 1) { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", ""); timeUnitTran = getTran("prescription.timeunit", medication.getTimeUnit()); } else { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", medication.getTimeUnitCount() + ""); timeUnitTran = getTran("prescription.timeunits", medication.getTimeUnit()); } sPrescrRule = sPrescrRule.replaceAll("#timeunit#", timeUnitTran.replaceAll(" ", " ").toLowerCase()); // product name cell = new PdfPCell(new Paragraph(medication.getProduct().getName(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); cell.setColspan(1); cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); // prescription rule cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(1); cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); } // add cells to make up with the chronic medications if (chronicMedications.size() < activePrescriptions.size()) { int missingCellCount = activePrescriptions.size() - chronicMedications.size(); for (int i = 0; i < missingCellCount; i++) { cell = new PdfPCell(); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); medicationTable.addCell(cell); } } // add chronicmedicationtables to medicationtable cell = new PdfPCell(medicationTable); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setPadding(3); table.addCell(cell); } //*** PRESCRIPTIONS *********************************************** if (activePrescriptions.size() > 0) { PdfPTable medicationTable = new PdfPTable(2); // sub title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.prescription"), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); cell.setBackgroundColor(BGCOLOR_LIGHT); medicationTable.addCell(cell); // run thru medications String sPrescrRule, sProductUnit, timeUnitTran; Prescription prescription; int n; for (n = 0; n < activePrescriptions.size(); n++) { prescription = (Prescription) activePrescriptions.elementAt(n); sPrescrRule = getTran("web.prescriptions", "prescriptionrule"); sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#", prescription.getUnitsPerTimeUnit() + ""); // productunits if (prescription.getUnitsPerTimeUnit() == 1) { sProductUnit = getTran("product.unit", prescription.getProduct().getUnit()); } else { sProductUnit = getTran("product.units", prescription.getProduct().getUnit()); } sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase()); // timeunits if (prescription.getTimeUnitCount() == 1) { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", ""); timeUnitTran = getTran("prescription.timeunit", prescription.getTimeUnit()); } else { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", prescription.getTimeUnitCount() + ""); timeUnitTran = getTran("prescription.timeunits", prescription.getTimeUnit()); } sPrescrRule = sPrescrRule.replaceAll("#timeunit#", timeUnitTran.toLowerCase()); // product name cell = new PdfPCell(new Paragraph(prescription.getProduct().getName(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); cell.setColspan(1); cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); // prescription rule cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(1); cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); } // add cells to make up with the active prescriptions if (activePrescriptions.size() < chronicMedications.size()) { int missingCellCount = chronicMedications.size() - activePrescriptions.size(); for (int i = 0; i < missingCellCount; i++) { cell = new PdfPCell(); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); medicationTable.addCell(cell); } } // add presciptionssstable to medicationtable cell = new PdfPCell(medicationTable); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setPadding(3); table.addCell(cell); doc.add(table); } } catch (Exception e) { e.printStackTrace(); } }