Example usage for com.itextpdf.text Document add

List of usage examples for com.itextpdf.text Document add

Introduction

In this page you can find the example usage for com.itextpdf.text Document add.

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:appArriendos.frmReservaEquipo.java

private void btnExportarApdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarApdfActionPerformed
    // TODO add your handling code here:
    try {//  ww  w. ja  va 2s  .co  m
        Connection miConexion = (Connection) Conexion.GetConnection();
        Statement statement = (Statement) miConexion.createStatement();
        String folio = txtFolio.getText();
        ResultSet rs = statement
                .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' ");
        int rows = 0;
        if (rs.next()) {
            rows = rs.getInt("num");
        }

        if (rows > 0) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Documento Pdf", "pdf");
            chooser.setFileFilter(filter);
            chooser.setDialogTitle("Guardar archivo");
            chooser.setMultiSelectionEnabled(false);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {

                String file = chooser.getSelectedFile().toString().concat(".pdf");
                FileOutputStream archivo = new FileOutputStream(file);
                Document documento = new Document();
                PdfWriter.getInstance(documento, archivo);
                documento.open();

                documento.add(new Paragraph("DOCUMENTO RESERVA", new Font(Font.FontFamily.HELVETICA, 20)));
                documento.add(new Paragraph(""));
                documento.add(new Paragraph(""));
                documento.add(new Paragraph("Nmero de folio : " + folio));
                documento.add(new Paragraph(""));
                rs = statement.executeQuery("SELECT * FROM tb_reserva WHERE num ='" + folio + "' ");
                while (rs.next()) {
                    documento.add(new Paragraph("Pedido Para Dia : " + rs.getString("fecha") + " A Las : "
                            + rs.getString("hora") + "  Horas"));
                    documento.add(
                            new Paragraph("Devolucion De Pedido Para El Dia : " + rs.getString("fecha_entrega")
                                    + " A Las : " + rs.getString("hora_entrega") + "  Horas"));
                    documento.add(new Paragraph("Solicit : " + rs.getString("rut")));
                    documento.add(new Paragraph("Fue Atendido Por : " + rs.getString("cod_admin")));
                    documento.add(new Paragraph("Sera Instalado Por : " + rs.getString("cod_instalador")));

                    int estado = rs.getInt("estado");
                    switch (estado) {
                    case 1:
                        documento.add(new Paragraph("ESTADO : EMITIDO"));
                        break;
                    case 2:
                        documento.add(new Paragraph("ESTADO : ANULADO"));
                        break;
                    case 3:
                        documento.add(new Paragraph("ESTADO : EJECUTADO"));
                        break;
                    }

                    documento.add(new Paragraph("OBSERVACION : " + rs.getString("observacion"),
                            new Font(Font.FontFamily.HELVETICA, 14)));
                }

                PdfPTable table = new PdfPTable(3);

                rs = statement.executeQuery("SELECT * FROM tb_reserva_detalle WHERE folio ='" + folio + "' ");

                table.addCell("LINEA");
                table.addCell("CODIGO");
                table.addCell("DESCRIPCION");
                while (rs.next()) {
                    table.addCell(rs.getString("num"));
                    table.addCell(rs.getString("codigo"));
                    table.addCell(rs.getString("descripcion"));

                }

                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento
                        .add(new Paragraph(" Equipos Solicitados : ", new Font(Font.FontFamily.HELVETICA, 14)));
                documento.add(new Paragraph(" "));
                documento.add(table);

                documento.close();
            } // fin saveshowdialog                    
        } else {
            JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema");
        }

    } // fin trycatch
    catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage());
    }

}

From source file:appArriendos.frmVistaInstalador.java

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
    // TODO add your handling code here:

    try {/*from w w w  .j a  v a2 s.c  o m*/
        Connection miConexion = (Connection) Conexion.GetConnection();
        Statement statement = (Statement) miConexion.createStatement();
        String folio = txtFolio.getText();
        ResultSet rs = statement
                .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' ");
        int rows = 0;
        if (rs.next()) {
            rows = rs.getInt("num");
        }

        if (rows > 0) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Documento Pdf", "pdf");
            chooser.setFileFilter(filter);
            chooser.setDialogTitle("Guardar archivo");
            chooser.setMultiSelectionEnabled(false);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {

                String file = chooser.getSelectedFile().toString().concat(".pdf");
                FileOutputStream archivo = new FileOutputStream(file);
                Document documento = new Document();
                PdfWriter pdfw = PdfWriter.getInstance(documento, archivo);
                documento.open();

                PdfContentByte cb = pdfw.getDirectContent();

                Barcode39 codeEAN = new Barcode39();
                codeEAN.setCodeType(Barcode.UPCA);
                //                 codeEAN.setCode(folio);
                codeEAN.setCode(folio);
                documento.add(codeEAN.createImageWithBarcode(cb, null, null));
                documento.add(new Paragraph("DOCUMENTO INSTALACIN", new Font(Font.FontFamily.HELVETICA, 16)));
                documento.add(new Paragraph(" "));

                documento.add(new Paragraph(" "));
                rs = statement.executeQuery("SELECT * FROM tb_reserva WHERE num ='" + folio + "' ");

                while (rs.next()) {

                    documento.add(new Paragraph("Nmero de folio : " + folio));
                    documento.add(new Paragraph("Pedido Para Dia : " + rs.getString("fecha") + " A Las : "
                            + rs.getString("hora") + "  Horas"));
                    documento.add(
                            new Paragraph("Devolucion De Pedido Para El Dia : " + rs.getString("fecha_entrega")
                                    + " A Las : " + rs.getString("hora_entrega") + "  Horas"));
                    documento.add(new Paragraph("Solicit : " + rs.getString("rut")));
                    documento.add(new Paragraph("Fue Atendido Por : " + rs.getString("cod_admin")));
                    documento.add(new Paragraph("Sera Instalado Por : " + rs.getString("cod_instalador")));

                    int estado = rs.getInt("estado");
                    switch (estado) {
                    case 1:
                        documento.add(new Paragraph("ESTADO : EMITIDO"));
                        break;
                    case 2:
                        documento.add(new Paragraph("ESTADO : ANULADO"));
                        break;
                    case 3:
                        documento.add(new Paragraph("ESTADO : EJECUTADO"));
                        break;
                    }

                    documento.add(new Paragraph("OBSERVACION : " + rs.getString("observacion"),
                            new Font(Font.FontFamily.HELVETICA, 14)));
                }

                PdfPTable table = new PdfPTable(3);

                rs = statement.executeQuery("SELECT * FROM tb_reserva_detalle WHERE folio ='" + folio + "' ");

                table.addCell("LINEA");
                table.addCell("CODIGO");
                table.addCell("DESCRIPCION");
                while (rs.next()) {
                    table.addCell(rs.getString("num"));
                    table.addCell(rs.getString("codigo"));
                    table.addCell(rs.getString("descripcion"));

                }

                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento
                        .add(new Paragraph(" Equipos Solicitados : ", new Font(Font.FontFamily.HELVETICA, 14)));
                documento.add(new Paragraph(" "));
                documento.add(table);
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph("Informacin sobre los prestamos : "));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(
                        "Despues de la firma del presente comprobante, el Cliente se responsabiliza por los equipos entregados por el Instalador. ",
                        new Font(Font.FontFamily.HELVETICA, 8)));
                documento.add(new Paragraph(
                        "Es Responzabilidad del Instalador retirar los equipos en la fecha acordada.",
                        new Font(Font.FontFamily.HELVETICA, 8)));
                documento.add(new Paragraph(
                        "En caso de ocurrir robo, deterioro, o perdida de los equipos entregados. El Ministerio Publico iniciara los sumarios correspondeientes segun la gravedad del incidente.",
                        new Font(Font.FontFamily.HELVETICA, 8)));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph("Recib Conforme"));

                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph("Firma Cliente : _____________________________________"));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento.add(new Paragraph("Firma Instalador : __________________________________"));

                documento.close();
            } // fin saveshowdialog
        } else {
            JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema");
        }

    } // fin trycatch
    catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage());
    }

}

From source file:appArriendos.frmVistaReserva.java

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
    // TODO add your handling code here:

    try {// w  ww  . jav a2 s .c om
        Connection miConexion = (Connection) Conexion.GetConnection();
        Statement statement = (Statement) miConexion.createStatement();
        String folio = txtFolio.getText();
        ResultSet rs = statement
                .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' ");
        int rows = 0;
        if (rs.next()) {
            rows = rs.getInt("num");
        }

        if (rows > 0) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Documento Pdf", "pdf");
            chooser.setFileFilter(filter);
            chooser.setDialogTitle("Guardar archivo");
            chooser.setMultiSelectionEnabled(false);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {

                String file = chooser.getSelectedFile().toString().concat(".pdf");
                FileOutputStream archivo = new FileOutputStream(file);
                Document documento = new Document();
                PdfWriter pdfw = PdfWriter.getInstance(documento, archivo);
                documento.open();
                PdfContentByte cb = pdfw.getDirectContent();

                Barcode39 codeEAN = new Barcode39();
                codeEAN.setCodeType(Barcode.UPCA);
                codeEAN.setCode(folio);
                documento.add(codeEAN.createImageWithBarcode(cb, null, null));
                documento.add(new Paragraph("DOCUMENTO RESERVA", new Font(Font.FontFamily.HELVETICA, 16)));

                documento.add(new Paragraph(""));

                documento.add(new Paragraph("Nmero de folio : " + folio));
                documento.add(new Paragraph(""));
                rs = statement.executeQuery("SELECT * FROM tb_reserva WHERE num ='" + folio + "' ");
                while (rs.next()) {
                    documento.add(new Paragraph("Nmero de folio : " + folio));
                    documento.add(new Paragraph("Pedido Para Dia : " + rs.getString("fecha") + " A Las : "
                            + rs.getString("hora") + "  Horas"));
                    documento.add(
                            new Paragraph("Devolucion De Pedido Para El Dia : " + rs.getString("fecha_entrega")
                                    + " A Las : " + rs.getString("hora_entrega") + "  Horas"));
                    documento.add(new Paragraph("Solicit : " + rs.getString("rut")));
                    documento.add(new Paragraph("Fue Atendido Por : " + rs.getString("cod_admin")));
                    documento.add(new Paragraph("Sera Instalado Por : " + rs.getString("cod_instalador")));

                    int estado = rs.getInt("estado");
                    switch (estado) {
                    case 1:
                        documento.add(new Paragraph("EMITIDO"));
                        break;
                    case 2:
                        documento.add(new Paragraph("ANULADO"));
                        break;
                    case 3:
                        documento.add(new Paragraph("EJECUTADO"));
                        break;
                    }
                }

                PdfPTable table = new PdfPTable(3);

                rs = statement.executeQuery("SELECT * FROM tb_reserva_detalle WHERE folio ='" + folio + "' ");

                table.addCell("LINEA");
                table.addCell("CODIGO");
                table.addCell("DESCRIPCION");
                while (rs.next()) {
                    table.addCell(rs.getString("num"));
                    table.addCell(rs.getString("codigo"));
                    table.addCell(rs.getString("descripcion"));

                }

                documento.add(new Paragraph(" "));
                documento.add(new Paragraph(" "));
                documento.add(table);

                documento.close();
            } // fin saveshowdialog                    
        } else {
            JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema");
        }

    } // fin trycatch
    catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage());
    }

}

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();//  w w  w  . j  a  v a 2  s  .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 {//from  ww w.j a  v a2s .c  o 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:ara.Confirmsec.java

public void myfunction() throws IOException, DocumentException {
    String a = preres.getText();/*  ww w  .j  a v  a  2 s . com*/
    File file = new File(DEST);
    file.getParentFile().mkdirs();
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(DEST));
    document.open();
    Image image = Image.getInstance("logo.jpg");
    document.add(image);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font small = FontFactory.getFont(FontFactory.HELVETICA, 5, Font.BOLD);
    String date = new Date().toString();
    Paragraph paragraph1 = new Paragraph(date);
    Paragraph paragraph2 = new Paragraph("To Whom it May Concern", chapterFont);
    paragraph2.setAlignment(Element.ALIGN_CENTER);
    paragraph1.setAlignment(Element.ALIGN_RIGHT);
    paragraph2.setSpacingBefore(20f);
    paragraph2.setSpacingAfter(10f);
    Paragraph paragraph3 = new Paragraph(a, paragraphFont);
    paragraph3.setSpacingAfter(20f);
    Paragraph paragraph4 = new Paragraph("Registrar");
    paragraph4.setAlignment(Element.ALIGN_RIGHT);
    paragraph4.setSpacingAfter(100f);
    Paragraph paragraph5 = new Paragraph(
            "This is a digitally signed document. Use Ref No. " + c + " to verify.", small);
    document.add(paragraph1);
    document.add(paragraph2);
    document.add(paragraph3);
    document.add(paragraph4);
    document.add(paragraph5);
    document.close();
    JOptionPane.showMessageDialog(null, "Document Generated.");
}

From source file:at.jps.sanction.core.io.file.PDFFileOutputWorker.java

License:Open Source License

@Override
public void handleMessage(final AnalysisResult message) {

    super.handleMessage(message);

    try {/* w w w  . j a  v  a  2s .  com*/

        logger.info("write Message: " + message.getMessage().getId());

        final Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(getFilename()));
        document.open();

        final Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD);
        final Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL);

        Chunk chunk = new Chunk("Message", chapterFont);
        Chapter chapter = new Chapter(new Paragraph(chunk), 1);
        chapter.setNumberDepth(0);
        chapter.add(new Paragraph(message.getMessage().toString(), paragraphFont));
        document.add(chapter);

        getWriter().write(message.getMessage().toString());

        if (message.getHitList() != null) {

            chapter.add(new Paragraph("Hits", paragraphFont));

            for (final HitResult hit : message.getHitList()) {
                final PdfPTable table = new PdfPTable(2);

                table.addCell("Description");
                table.addCell(hit.getHitDescripton());
                table.addCell("Field");
                table.addCell(hit.getHitDescripton());
                table.addCell("Absolute Value");
                table.addCell(hit.getAbsolutHit() + "");
                table.addCell("Relative Value");
                table.addCell(hit.getRelativeHit() + "");
                table.addCell("Phrase Value");
                table.addCell(hit.getPhraseHit() + "");
                table.addCell("HitType");
                table.addCell(hit.getHitType());

                document.add(table);
            }
        } else {
            final String exception = message.getException();
            if (exception != null) {
                chunk = new Chunk("Error:", chapterFont);
                chapter = new Chapter(new Paragraph(chunk), 1);
                chapter.add(new Paragraph(message.getException().toString(), paragraphFont));
                document.add(chapter);
            }
        }
        document.close();
    } catch (final Exception e) {
        logger.error("Error writing to file:" + getFilename());
        logger.debug("Exception: ", e);
    }
}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

@RequestMapping(value = "/individualpdf", method = RequestMethod.GET)
public String individualpdf(@RequestParam(value = "formId", required = true) String formId,
        @RequestParam(value = "entryId", required = true) String entryId, ModelMap model,
        HttpServletResponse response) throws IOException {

    byte[] fileContent = formDao.getTemplateContent(formId);
    Form form = formDao.getFormWithFields(formId);
    form.setEntryId(entryId);// w  w  w . j av  a2  s.  c  om

    form = formDao.getEntry(form);
    String report = "";

    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    if (fileContent != null) {
        report = new String(fileContent, "UTF8");

        for (Field field : form.getFields()) {
            if (fieldTypeIsNotOfFileOrNoteOrSection(field)) {
                report = report.replaceAll("#" + field.getColName() + ":label#", field.getLabel());
                report = report.replaceAll("#" + field.getColName() + ":value#", field.getStrVal());
            }
        }
    }

    else {
        // step 2
        try {
            response.reset();
            response.setContentType("application/pdf");
            response.setHeader("Content-disposition", "inline; filename=test.pdf");

            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            response.setHeader("Pragma", "No-cache");

            PdfWriter writer = PdfWriter.getInstance(document, baos);
            // step 3
            document.open();

            PdfPCell space;
            space = new PdfPCell();
            space.setBorder(Rectangle.NO_BORDER);
            space.setColspan(2);
            space.setFixedHeight(8);

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell;

            report += "<table cellspacing='0' cellpadding='0' style='border:1px solid #aaa;width:98%;'>";

            for (Field field : form.getFields()) {
                if (fieldTypeIsNotOfFileOrNoteOrSection(field)) {

                    report += field.getLabel();

                    report += field.getStrVal();

                    table.setWidths(new int[] { 1, 2 });
                    table.addCell(field.getLabel());
                    //cell = new PdfPCell();
                    //cell.setCellEvent(new TextFields(1));
                    table.addCell(field.getStrVal());

                }
            }

            document.add(table);
            document.close();
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
            out.flush();

        }

        catch (Exception ex) {
            System.out.println("Could not print reasone::" + ex.toString());

        }

    }

    return null;

}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

@RequestMapping(value = "/pdfExport", method = RequestMethod.GET)
public String pdfExport(@RequestParam(value = "formId", required = true) String formId,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "colName", required = false) String colName,
        @RequestParam(value = "colVal", required = false) String colVal,
        @RequestParam(value = "sortCol", required = false) String sortCol,
        @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model,
        HttpServletResponse response, HttpServletRequest request) throws IOException {

    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // step 2/*from www  .jav a  2s  .com*/
    try {
        response.reset();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline; filename=test.pdf");

        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Pragma", "No-cache");

        PdfWriter writer = PdfWriter.getInstance(document, baos);
        // step 3
        document.open();

        Form form = null;
        //System.out.println("The form id is 1:"+formId);
        if (formId != null) {
            form = formDao.getFormWithFields(formId);
        }

        if (form != null) {
            if (form.getStatus() != 2) {//2-active, 3-deactive
                model.put("doneMessage", "msg.access.denied");
                model.put("doneMsgType", "failed");

                return "redirect:done.htm";
            }
            initForm(form);
        }

        List<Field> fieldList = form.getFields();

        if (fieldList.isEmpty()) {
            System.out.println("The list size is zero");
        }

        PdfPCell space;
        space = new PdfPCell();
        space.setBorder(Rectangle.NO_BORDER);
        space.setColspan(2);
        space.setFixedHeight(8);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell;

        //PdfPCell cell;                
        table.setWidths(new int[] { 1, 2 });

        int i = 0;
        for (Field f : fieldList) {
            if ("text".equals(f.getType())) {

                table.addCell(f.getLabel());
                cell = new PdfPCell();
                cell.setCellEvent(new TextFields(1, i));
                table.addCell(cell);

            } else if ("textarea".equals(f.getType())) {
                table.addCell(f.getLabel());
                cell = new PdfPCell();
                cell.setCellEvent(new TextFields(1, i));
                cell.setFixedHeight(60);
                table.addCell(cell);

            } else if ("select".equals(f.getType())) {
                table.addCell(f.getType());
                cell = new PdfPCell();
                cell.setCellEvent(new ChoiceFields(3, f.getList().toArray()));
                table.addCell(cell);
                //table.addCell(space);
                System.out.println("ajsdhd");
            }
            i++;
        }

        /*
          for(Field f : fieldList)
          {  
                
        if( "radio".equals(f.getType()) )
        {    
            System.out.println("List "+f.getList()+"  Oppt"+f.getOptions()+ "    df"+f.getColName());
                    
            writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf"));
                 
            //writer.addJavaScript(Utilities.readFileToString(""));
            // add the radio buttons
            PdfContentByte canvas = writer.getDirectContent();
            Font font = new Font(FontFamily.HELVETICA, 14);
            Rectangle rect;
            PdfFormField field;
            PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
            radiogroup.setFieldName("language");
            RadioCheckField radio;
            for (int i = 0; i < 2; i++) 
            {
                rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40);
                radio = new RadioCheckField(writer, rect, null, f.getLabel());
                radio.setBorderColor(GrayColor.GRAYBLACK);
                radio.setBackgroundColor(GrayColor.GRAYWHITE);
                radio.setCheckType(RadioCheckField.TYPE_CIRCLE);
                field = radio.getRadioField();
                radiogroup.addKid(field);
                        
                writer.addAnnotation(field);
                       
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(f.getLabel(), font), 70, 790 - i * 40, 0);
            }
            //table.addCell(f.getLabel());
            //cell = new PdfPCell();
                    
            //document.add(radiogroup);
            //writer.addAnnotation(radiogroup);
                    
                
        }
                
          }       */

        // Add submit button   
        PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(400, 700, 370, 670),
                "submitPOST");
        //submitBtn.setBackgroundColor(Color.GRAY);
        submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
        submitBtn.setText("Submit");
        submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
        PdfFormField submitField = submitBtn.getField();
        submitField.setAction(
                PdfAction.createSubmitForm("http://localhost:8084/GovForm-07-02/formBuilder/pdfresponse.htm",
                        null, PdfAction.SUBMIT_HTML_FORMAT));

        writer.addAnnotation(submitField);

        document.add(table);

        System.out.println("Pdf creation successful");

        document.close();

        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception ex) {
        System.out.println("Could not print reasone::" + ex.toString());

    }

    //////////////////////////////////////// email part////////////////////////////  
    //email functionalities
    // Recipient's email ID needs to be mentioned.
    String to = "tanviranik@gmail.com";

    // Sender's email ID needs to be mentioned
    String from = "tanvir_cse@yahoo.com";

    // Assuming you are sending email from localhost
    String host = "localhost";

    // Get system properties
    Properties properties = System.getProperties();

    // Setup mail server
    properties.setProperty("mail.smtp.host", host);

    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);

    try {
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(session);

        // Set From: header field of the header.
        message.setFrom(new InternetAddress(from));

        // Set To: header field of the header.
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

        // Set Subject: header field
        message.setSubject("This is the Subject Line!");

        // Now set the actual message
        message.setText("This is actual message");

        // Send message
        Transport.send(message);
        System.out.println("Sent message successfully....");
    } catch (MessagingException mex) {
        mex.printStackTrace();
    }
    //////////////////////////////////////// email part////////////////////////////

    return null;

}

From source file:be.kcbj.placemat.Placemat.java

License:Open Source License

private void createPdf(File file, List<Sponsor> sponsors) throws IOException, DocumentException {
    System.out.println("Generating PDF file " + file.getAbsolutePath());
    Layout layout = new Layout(sponsors);
    System.out.println("Layout = " + layout);

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.setPageSize(PageSize.A4.rotate());
    document.setMargins(PADDING_DOC, PADDING_DOC, PADDING_DOC, PADDING_DOC);
    document.open();//from   ww w  . j a va2s  .c  o  m

    PdfPTable table = new PdfPTable(layout.getColumnCount());
    table.setWidthPercentage(100);
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);
    for (int i = 0; i < sponsors.size(); i++) {
        table.addCell(generateCell(sponsors.get(i), layout.getCellHeight()));
    }
    for (int i = 0; i < layout.getEmptyCellCount(); i++) {
        table.addCell(generateCell(new Sponsor(), layout.getCellHeight()));
    }
    document.add(table);

    document.close();
}