Example usage for com.itextpdf.text.pdf PdfPTable PdfPTable

List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable PdfPTable.

Prototype

public PdfPTable(final PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:cis_690_report.Reporter.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    File1 = jTextField1.getText();
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File3 = chooser.getSelectedFile().getAbsolutePath();
        }// w w w.  j a  v  a  2 s. c  om
        File file = new File(File1);

        try {
            br1 = new BufferedReader(new FileReader(file));
            b1 = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {

        }
        int number_of_rows1 = 0;
        String line = "";
        String cvsSplitBy = ",";
        try {
            while ((line = br1.readLine()) != null) {

                // use comma as separator
                number_of_rows1++;
            }

        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        }

        bull1 = new String[number_of_rows1][];
        int k = 0;
        BufferedReader br2 = null;
        try {
            br2 = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br2.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                System.out.println(Bull.length);
                bull1[k] = new String[93];
                if (Bull.length < 10) {
                    for (int j = 0; j < 92; j++) {
                        bull1[k][j] = "";
                        //System.out.println(Bull[j]);
                    }
                } else {
                    for (int j = 0; j < Bull.length; j++) {
                        bull1[k][j] = Bull[j];
                        //System.out.println(Bull[j]);
                    }
                }
                k++;
            }
        } catch (IOException ex) {
        }
        Document doc = new Document();
        PdfWriter docWriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {

            //special font sizes
            Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(FontFamily.TIMES_ROMAN, 6);
            Font bfBold20 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);

            //file path

            docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3));

            //document header attributes
            doc.addAuthor("Shubh Chopra");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Shubh Chopra");
            doc.addTitle("BES");
            doc.setPageSize(PageSize.LETTER.rotate());

            //open document
            doc.open();
            //create a paragraph
            Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
            paragraph.setFont(bfBold20);
            paragraph.setAlignment(Element.ALIGN_CENTER);

            Image img = Image.getInstance("VETMED.png");

            img.scaleToFit(300f, 150f);
            doc.add(paragraph);
            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(img);
            cell.setBorder(PdfPCell.NO_BORDER);
            table1.addCell(cell);

            String temp1 = "\tOwner: " + bull1[1][78] + " " + bull1[1][79] + "\n\n\tRanch: " + bull1[1][80]
                    + "\n\n\tAddress: " + bull1[1][71] + "\n\n\tCity: " + bull1[1][73] + "\n\n\tState: "
                    + bull1[1][76] + "\tZip: " + bull1[1][77] + "\n\n\tPhone: " + bull1[1][75] + "\n\n";

            table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
            doc.add(table1);

            boolean[] checkboxs = { jCheckBox1.isSelected(), jCheckBox2.isSelected(), jCheckBox3.isSelected(),
                    jCheckBox4.isSelected(), jCheckBox5.isSelected(), jCheckBox6.isSelected(),
                    jCheckBox7.isSelected(), jCheckBox8.isSelected(), jCheckBox9.isSelected(),
                    jCheckBox10.isSelected(), jCheckBox11.isSelected(), jCheckBox12.isSelected(),
                    jCheckBox13.isSelected() };
            //specify column widths
            int temp = 0;
            for (int x = 0; x < checkboxs.length; x++) {
                if (checkboxs[x] == true) {
                    temp++;
                }
            }
            float[] columnWidths = new float[temp + 5];
            for (int x = 0; x < columnWidths.length; x++) {
                if (x < 5)
                    columnWidths[x] = 1f;
                else if (jCheckBox1.isSelected() && x == 5)
                    columnWidths[x] = 2f;
                else if (jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 7)
                    columnWidths[x] = 2f;
                else if (!jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 6)
                    columnWidths[x] = 2f;
                else if (jCheckBox4.isSelected() && x == columnWidths.length - 2)
                    columnWidths[x] = 2f;
                else if (jCheckBox5.isSelected() && x == columnWidths.length - 1)
                    columnWidths[x] = 2f;
                else
                    columnWidths[x] = 1f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            //insert column headings
            re.insertCell(table, "ID-Tag", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Tatto", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-RFID", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Brand", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Other", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox1.isSelected())
                re.insertCell(table, "Age", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox2.isSelected())
                re.insertCell(table, "Scrotal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox3.isSelected())
                re.insertCell(table, "Motility", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox6.isSelected())
                re.insertCell(table, "Normal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox7.isSelected())
                re.insertCell(table, "M2", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox8.isSelected())
                re.insertCell(table, "M3", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox9.isSelected())
                re.insertCell(table, "M4", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox10.isSelected())
                re.insertCell(table, "M5", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox11.isSelected())
                re.insertCell(table, "M6", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox12.isSelected())
                re.insertCell(table, "M7", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox13.isSelected())
                re.insertCell(table, "M8", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox4.isSelected())
                re.insertCell(table, "Comments", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox5.isSelected())
                re.insertCell(table, "Classification", Element.ALIGN_CENTER, 1, bfBold12);

            table.setHeaderRows(1);

            //insert an empty row

            //create section heading by cell merging

            //just some random data to fill 
            for (int x = 1; x < number_of_rows1; x++) {

                re.insertCell(table, bull1[x][7], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][8], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][6], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][2], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][9], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox1.isSelected())
                    re.insertCell(table, bull1[x][0], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox2.isSelected())
                    re.insertCell(table, bull1[x][70], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox3.isSelected())
                    re.insertCell(table, bull1[x][61], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox6.isSelected())
                    re.insertCell(table, bull1[x][43], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox7.isSelected())
                    re.insertCell(table, bull1[x][45], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox8.isSelected())
                    re.insertCell(table, bull1[x][47], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox9.isSelected())
                    re.insertCell(table, bull1[x][49], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox10.isSelected())
                    re.insertCell(table, bull1[x][51], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox11.isSelected())
                    re.insertCell(table, bull1[x][53], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox12.isSelected())
                    re.insertCell(table, bull1[x][55], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox13.isSelected())
                    re.insertCell(table, bull1[x][57], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox4.isSelected())
                    re.insertCell(table, "", Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox5.isSelected())
                    re.insertCell(table, bull1[x][35], Element.ALIGN_CENTER, 1, bf12);
            }
            doc.add(table);

        } catch (DocumentException dex) {
            dex.printStackTrace();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (doc != null) {
                //close the document
                doc.close();
            }
            if (docWriter != null) {
                //close the writer
                docWriter.close();
            }
        }
        // TODO add your handling code here:
    } //GEN-LAST:event_jButton1ActionPerformed
}

From source file:cl.preguntame.clases.Cabecera.java

/**
 * Esta es el metodo a llamar cuando ocurra el evento onEndPage, es en este
 * evento donde crearemos el encabeazado de la pagina con los elementos
 * indicados.//from w w  w  . j  ava  2s  .co  m
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        // Se determina el ancho y altura de la tabla 
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);

        // Borde de la celda
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);

        table.addCell(encabezado);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        table.addCell(String.format("Pagina % 01d de ", writer.getPageNumber()));

        PdfPCell cell = new PdfPCell(Image.getInstance(total));

        cell.setBorder(Rectangle.BOTTOM);

        table.addCell(cell);
        // Esta linea escribe la tabla como encabezado
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:clases.Funciones.java

private String GenerateReporte_pdf(JTable t, String title, int open) {
    Document documento = new Document(PageSize.LETTER.rotate(), 10, 10, 10, 10);
    FileOutputStream ficheroPdf;//  w  w w  .j a  v  a2 s  .  com
    File ruta = null;
    com.itextpdf.text.Image imagen = null;
    try {
        imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo));

        char rt = p.ReturnPropiedad(p.Ruta_SaveReports)
                .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1);

        if ("/".equalsIgnoreCase(String.valueOf(rt))) {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_")
                    + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_")
                    + ".pdf");
        } else {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/"
                    + ReturnNombreUsuario().replace(" ", "_") + "_"
                    + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf");
        }

        ficheroPdf = new FileOutputStream(ruta);
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
    } catch (DocumentException | IOException ex) {
        Alert("Verifique las rutas de guardado de reportes y logo.");
    }

    try {
        documento.open();

        title += "\nGENER: " + ReturnNombreUsuario();

        Paragraph Title = new Paragraph(title.toUpperCase());
        Title.setAlignment(1);
        documento.add(Title);
        imagen.setAlignment(Element.ALIGN_CENTER);
        imagen.scaleToFit(200, 100);

        String membrete = ReturnDatosFisicos(this.Datos_Nombre) + "\n";
        membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n";
        membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n";
        membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n";
        membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n";
        membrete += "FECHA Y HORA DE GENERACION: " + GetFechaAndHourActual() + "\n";

        /////////
        PdfPTable HeaderDatos = new PdfPTable(2);
        HeaderDatos.setWidthPercentage(100);

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

        PdfPCell cell = new PdfPCell(new Phrase(membrete));
        cell.setBorder(0);
        HeaderDatos.addCell(cell);
        cell = new PdfPCell(imagen);
        cell.setBorder(0);
        cell.setHorizontalAlignment(1);
        HeaderDatos.addCell(cell);

        documento.add(HeaderDatos);
        documento.add(new Paragraph("\n"));
        /////////

        PdfPTable tabla = new PdfPTable(t.getColumnCount());

        tabla.setWidthPercentage(100);

        for (int i = 0; i < t.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t.getColumnName(i));
            header.setAlignment(1);
            tabla.addCell(header);
        }

        for (int i = 0; i < t.getRowCount(); i++) {
            for (int a = 0; a < t.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla.addCell(campo);
            }
        }

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

        Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM");
        footer.setAlignment(1);
        documento.add(footer);

        documento.close();
        if (open > 0) {
            Desktop.getDesktop().open(ruta);
        }
    } catch (IOException | DocumentException ex) {
        Alert(ex.getMessage());
    }
    return ruta.getAbsolutePath();
}

From source file:clases.Funciones.java

public boolean GenerateReporte_Service(JTable t_client, JTable t_vehiculos, int open, String S_solicitad,
        String S_realizado, JTable t_productos, String Total, String Prioridad, JComboBox client,
        JComboBox vehiculos, Double km) {
    boolean r = false;

    int Folio = GenerateFolioService();

    if (AddService(client, vehiculos, S_solicitad, S_realizado, t_productos, Double.parseDouble(Total),
            "URGENTE".equals(Prioridad)) && vehiculos.getSelectedIndex() > 0) {
        UpdateKilometraje((String) ListVehiculos.get(vehiculos.getSelectedIndex()), km);

        Table_LoadClient(t_client, client);
        Table_LoadCar(t_vehiculos, vehiculos);

        Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10);
        FileOutputStream ficheroPdf;
        File ruta = null;/* w ww  . j  a  va2 s .  c o m*/
        com.itextpdf.text.Image imagen = null;
        try {
            imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo));

            char rt = p.ReturnPropiedad(p.Ruta_SaveReports)
                    .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1);

            if ("/".equalsIgnoreCase(String.valueOf(rt))) {
                ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_")
                        + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_")
                        + ".pdf");
            } else {
                ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/"
                        + ReturnNombreUsuario().replace(" ", "_") + "_"
                        + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_")
                        + ".pdf");
            }

            ficheroPdf = new FileOutputStream(ruta);
            PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        } catch (DocumentException | IOException ex) {
            Alert("Verifique las rutas de guardado de reportes y logo.");
        }

        try {
            documento.open();

            imagen.setAlignment(Element.ALIGN_CENTER);
            imagen.scaleToFit(200, 100);

            String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n";
            membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n";
            membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n";
            membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n";
            membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n";
            membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n";
            membrete += "GENERADO: " + GetFechaAndHourActual() + "\n";

            PdfPTable HeaderDatos = new PdfPTable(2);
            HeaderDatos.setWidthPercentage(100);

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

            PdfPCell cell = new PdfPCell(new Phrase(membrete));
            cell.setBorder(0);
            HeaderDatos.addCell(cell);
            cell = new PdfPCell(imagen);
            cell.setBorder(0);
            cell.setHorizontalAlignment(1);
            cell.setVerticalAlignment(1);
            HeaderDatos.addCell(cell);

            documento.add(HeaderDatos);
            documento.add(new Paragraph("\n"));
            /////////

            //Tabla_Clientes
            String Client_header = "CLIENTE";
            Paragraph Title = new Paragraph(Client_header.toUpperCase());
            Title.setAlignment(1);
            documento.add(Title);
            documento.add(new Paragraph(" "));

            PdfPTable tabla = new PdfPTable(t_client.getColumnCount());

            tabla.setWidthPercentage(100);

            for (int i = 0; i < t_client.getColumnCount(); i++) {
                Paragraph header = new Paragraph(t_client.getColumnName(i));
                header.setAlignment(1);
                tabla.addCell(header);
            }

            for (int i = 0; i < t_client.getRowCount(); i++) {
                for (int a = 0; a < t_client.getColumnCount(); a++) {

                    Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a)));
                    campo.setAlignment(1);
                    tabla.addCell(campo);
                }
            }

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

            //Tabla_Vehiculos
            String Vehiculos_header = "VEHICULO";

            Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase());
            Title1.setAlignment(1);
            documento.add(Title1);
            documento.add(new Paragraph(" "));

            PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount());

            tabla_vehiculos.setWidthPercentage(100);

            for (int i = 0; i < t_vehiculos.getColumnCount(); i++) {
                Paragraph header = new Paragraph(t_vehiculos.getColumnName(i));
                header.setAlignment(1);
                tabla_vehiculos.addCell(header);
            }

            for (int i = 0; i < t_vehiculos.getRowCount(); i++) {
                for (int a = 0; a < t_vehiculos.getColumnCount(); a++) {

                    Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a)));
                    campo.setAlignment(1);
                    tabla_vehiculos.addCell(campo);
                }
            }

            documento.add(tabla_vehiculos);
            documento.add(new Paragraph("SERVICIO SOLICITADO: " + S_solicitad.toUpperCase()));
            documento.add(new Paragraph("SERVICIO REALIZADO: " + S_realizado.toUpperCase()));
            documento.add(new Paragraph("PRIORIDAD: " + Prioridad));

            //Tabla de servicios y productos
            String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS";

            Paragraph Title2 = new Paragraph(Service_header.toUpperCase());
            Title2.setAlignment(1);
            documento.add(Title2);
            documento.add(new Paragraph(" "));

            PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount());

            tabla_PRODUCTS.setWidthPercentage(100);

            for (int i = 0; i < t_productos.getColumnCount(); i++) {
                Paragraph header = new Paragraph(t_productos.getColumnName(i));
                header.setAlignment(1);
                tabla_PRODUCTS.addCell(header);
            }

            for (int i = 0; i < t_productos.getRowCount(); i++) {
                for (int a = 0; a < t_productos.getColumnCount(); a++) {

                    Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a)));
                    campo.setAlignment(1);
                    tabla_PRODUCTS.addCell(campo);
                }
            }

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

            documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + Total));
            documento.add(new Paragraph(
                    "FECHA Y HORA DE ENTREGA: ____________________________________________________"));
            documento.add(new Paragraph(
                    "NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________"));
            documento.add(new Paragraph(
                    "CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________"));
            documento.add(new Paragraph(
                    "PROXIMO SERVICIO: ___________________________________________________________"));

            Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM");
            footer.setAlignment(1);
            documento.add(footer);

            documento.close();
            r = true;
            if (open > 0) {
                Desktop.getDesktop().open(ruta);
            }
        } catch (IOException | DocumentException ex) {
            Alert(ex.getMessage());
        }
    } else {
        Alert("VERIFIQUE SU INFORMACION");
    }
    return r;
}

From source file:clases.Funciones.java

public void ReGenerateReporte_Service(JTable t) {
    int id = 0, id_cliente = 0;
    double total = 0;
    String id_vehiculo = "", s_solicitado = "", s_realizado = "", productos = "";
    boolean p_urgente = false;

    try {/*from   w  w w . j  a v  a 2  s  . c o  m*/
        coneccion = new Conexion();
        try (ResultSet rs = coneccion.Consulta(
                "SELECT id, id_cliente, id_vehiculo, s_solicitado, s_realizado, productos, total, p_urgente FROM services where id = "
                        + Integer.parseInt((String) t.getValueAt(t.getSelectedRow(), 0)) + " ")) {

            if (rs.next()) {
                id = rs.getInt(1);
                id_cliente = rs.getInt(2);
                id_vehiculo = rs.getString(3);
                s_solicitado = rs.getString(4);
                s_realizado = rs.getString(5);
                productos = rs.getString(6);
                total = rs.getDouble(7);
                p_urgente = rs.getBoolean(8);
            }

        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
        Alert(ex.getMessage());
    }

    int Folio = id;

    JTable t_client = new JTable();
    JTable t_vehiculos = new JTable();

    Table_LoadClient(t_client, id_cliente);
    Table_LoadCar(t_vehiculos, id_vehiculo);

    Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10);
    FileOutputStream ficheroPdf;
    File ruta = null;
    com.itextpdf.text.Image imagen = null;
    try {
        imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo));

        char rt = p.ReturnPropiedad(p.Ruta_SaveReports)
                .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1);

        if ("/".equalsIgnoreCase(String.valueOf(rt))) {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_")
                    + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_")
                    + ".pdf");
        } else {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/"
                    + ReturnNombreUsuario().replace(" ", "_") + "_"
                    + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf");
        }

        ficheroPdf = new FileOutputStream(ruta);
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
    } catch (DocumentException | IOException ex) {
        Alert("Verifique las rutas de guardado de reportes y logo.");
    }

    try {
        documento.open();

        imagen.setAlignment(Element.ALIGN_CENTER);
        imagen.scaleToFit(200, 100);

        String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n";
        membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n";
        membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n";
        membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n";
        membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n";
        membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n";
        membrete += "GENERADO: " + GetFechaAndHourActual() + "\n";

        PdfPTable HeaderDatos = new PdfPTable(2);
        HeaderDatos.setWidthPercentage(100);

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

        PdfPCell cell = new PdfPCell(new Phrase(membrete));
        cell.setBorder(0);
        HeaderDatos.addCell(cell);
        cell = new PdfPCell(imagen);
        cell.setBorder(0);
        cell.setHorizontalAlignment(1);
        cell.setVerticalAlignment(1);
        HeaderDatos.addCell(cell);

        documento.add(HeaderDatos);
        documento.add(new Paragraph("\n"));
        /////////

        //Tabla_Clientes
        String Client_header = "CLIENTE";
        Paragraph Title = new Paragraph(Client_header.toUpperCase());
        Title.setAlignment(1);
        documento.add(Title);
        documento.add(new Paragraph(" "));

        PdfPTable tabla = new PdfPTable(t_client.getColumnCount());

        tabla.setWidthPercentage(100);

        for (int i = 0; i < t_client.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_client.getColumnName(i));
            header.setAlignment(1);
            tabla.addCell(header);
        }

        for (int i = 0; i < t_client.getRowCount(); i++) {
            for (int a = 0; a < t_client.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla.addCell(campo);
            }
        }

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

        //Tabla_Vehiculos
        String Vehiculos_header = "VEHICULO";

        Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase());
        Title1.setAlignment(1);
        documento.add(Title1);
        documento.add(new Paragraph(" "));

        PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount());

        tabla_vehiculos.setWidthPercentage(100);

        for (int i = 0; i < t_vehiculos.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_vehiculos.getColumnName(i));
            header.setAlignment(1);
            tabla_vehiculos.addCell(header);
        }

        for (int i = 0; i < t_vehiculos.getRowCount(); i++) {
            for (int a = 0; a < t_vehiculos.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla_vehiculos.addCell(campo);
            }
        }

        documento.add(tabla_vehiculos);
        documento.add(new Paragraph("SERVICIO SOLICITADO: " + s_solicitado.toUpperCase()));
        documento.add(new Paragraph("SERVICIO REALIZADO: " + s_realizado.toUpperCase()));
        String var = "";
        if (p_urgente) {
            var = "URGENTE";
        } else {
            var = "PROGRAMAR";
        }
        documento.add(new Paragraph("PRIORIDAD: " + var));

        //Tabla de servicios y productos
        String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS";

        Paragraph Title2 = new Paragraph(Service_header.toUpperCase());
        Title2.setAlignment(1);
        documento.add(Title2);
        documento.add(new Paragraph(" "));

        JTable t_productos = new JTable();

        Table_LoadProductsServicio(t_productos);

        String[] result = productos.replace("+", ",").split(",");

        if (result.length >= 1) {
            for (String r : result) {
                if (!r.equalsIgnoreCase("") || !r.isEmpty()) {
                    if (ExistProduct(r)) {
                        Table_AddProductsServicio(t_productos, r);
                    }
                }
            }
        }

        PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount());

        tabla_PRODUCTS.setWidthPercentage(100);

        for (int i = 0; i < t_productos.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_productos.getColumnName(i));
            header.setAlignment(1);
            tabla_PRODUCTS.addCell(header);
        }

        for (int i = 0; i < t_productos.getRowCount(); i++) {
            for (int a = 0; a < t_productos.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla_PRODUCTS.addCell(campo);
            }
        }

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

        documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + total));
        documento.add(
                new Paragraph("FECHA Y HORA DE ENTREGA: ____________________________________________________"));
        documento.add(
                new Paragraph("NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________"));
        documento.add(
                new Paragraph("CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________"));
        documento.add(
                new Paragraph("PROXIMO SERVICIO: ___________________________________________________________"));

        Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM");
        footer.setAlignment(1);
        documento.add(footer);

        documento.close();
        Desktop.getDesktop().open(ruta);
    } catch (IOException | DocumentException ex) {
        Alert(ex.getMessage());
    } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
        Alert(ex.getMessage());
    }
}

From source file:clases.Funciones.java

public void ReGenerateReporte_Service(int id_service) {
    int id = 0, id_cliente = 0;
    double total = 0;
    String id_vehiculo = "", s_solicitado = "", s_realizado = "", productos = "";
    boolean p_urgente = false;

    try {// w w w  .ja  va2s.  co m
        coneccion = new Conexion();
        try (ResultSet rs = coneccion.Consulta(
                "SELECT id, id_cliente, id_vehiculo, s_solicitado, s_realizado, productos, total, p_urgente FROM services where id = "
                        + id_service + " ")) {

            if (rs.next()) {
                id = rs.getInt(1);
                id_cliente = rs.getInt(2);
                id_vehiculo = rs.getString(3);
                s_solicitado = rs.getString(4);
                s_realizado = rs.getString(5);
                productos = rs.getString(6);
                total = rs.getDouble(7);
                p_urgente = rs.getBoolean(8);
            }

        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
        Alert(ex.getMessage());
    }

    int Folio = id;

    JTable t_client = new JTable();
    JTable t_vehiculos = new JTable();

    Table_LoadClient(t_client, id_cliente);
    Table_LoadCar(t_vehiculos, id_vehiculo);

    Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10);
    FileOutputStream ficheroPdf;
    File ruta = null;
    com.itextpdf.text.Image imagen = null;
    try {
        imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo));

        char rt = p.ReturnPropiedad(p.Ruta_SaveReports)
                .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1);

        if ("/".equalsIgnoreCase(String.valueOf(rt))) {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_")
                    + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_")
                    + ".pdf");
        } else {
            ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/"
                    + ReturnNombreUsuario().replace(" ", "_") + "_"
                    + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf");
        }

        ficheroPdf = new FileOutputStream(ruta);
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
    } catch (DocumentException | IOException ex) {
        Alert("Verifique las rutas de guardado de reportes y logo.");
    }

    try {
        documento.open();

        imagen.setAlignment(Element.ALIGN_CENTER);
        imagen.scaleToFit(200, 100);

        String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n";
        membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n";
        membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n";
        membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n";
        membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n";
        membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n";
        membrete += "GENERADO: " + GetFechaAndHourActual() + "\n";

        PdfPTable HeaderDatos = new PdfPTable(2);
        HeaderDatos.setWidthPercentage(100);

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

        PdfPCell cell = new PdfPCell(new Phrase(membrete));
        cell.setBorder(0);
        HeaderDatos.addCell(cell);
        cell = new PdfPCell(imagen);
        cell.setBorder(0);
        cell.setHorizontalAlignment(1);
        cell.setVerticalAlignment(1);
        HeaderDatos.addCell(cell);

        documento.add(HeaderDatos);
        documento.add(new Paragraph("\n"));
        /////////

        //Tabla_Clientes
        String Client_header = "CLIENTE";
        Paragraph Title = new Paragraph(Client_header.toUpperCase());
        Title.setAlignment(1);
        documento.add(Title);
        documento.add(new Paragraph(" "));

        PdfPTable tabla = new PdfPTable(t_client.getColumnCount());

        tabla.setWidthPercentage(100);

        for (int i = 0; i < t_client.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_client.getColumnName(i));
            header.setAlignment(1);
            tabla.addCell(header);
        }

        for (int i = 0; i < t_client.getRowCount(); i++) {
            for (int a = 0; a < t_client.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla.addCell(campo);
            }
        }

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

        //Tabla_Vehiculos
        String Vehiculos_header = "VEHICULO";

        Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase());
        Title1.setAlignment(1);
        documento.add(Title1);
        documento.add(new Paragraph(" "));

        PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount());

        tabla_vehiculos.setWidthPercentage(100);

        for (int i = 0; i < t_vehiculos.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_vehiculos.getColumnName(i));
            header.setAlignment(1);
            tabla_vehiculos.addCell(header);
        }

        for (int i = 0; i < t_vehiculos.getRowCount(); i++) {
            for (int a = 0; a < t_vehiculos.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla_vehiculos.addCell(campo);
            }
        }

        documento.add(tabla_vehiculos);
        documento.add(new Paragraph("SERVICIO SOLICITADO: " + s_solicitado.toUpperCase()));
        documento.add(new Paragraph("SERVICIO REALIZADO: " + s_realizado.toUpperCase()));
        String var = "";
        if (p_urgente) {
            var = "URGENTE";
        } else {
            var = "PROGRAMAR";
        }
        documento.add(new Paragraph("PRIORIDAD: " + var));

        //Tabla de servicios y productos
        String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS";

        Paragraph Title2 = new Paragraph(Service_header.toUpperCase());
        Title2.setAlignment(1);
        documento.add(Title2);
        documento.add(new Paragraph(" "));

        JTable t_productos = new JTable();

        Table_LoadProductsServicio(t_productos);

        String[] result = productos.replace("+", ",").split(",");

        if (result.length >= 1) {
            for (String r : result) {
                if (!r.equalsIgnoreCase("") || !r.isEmpty()) {
                    if (ExistProduct(r)) {
                        Table_AddProductsServicio(t_productos, r);
                    }
                }
            }
        }

        PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount());

        tabla_PRODUCTS.setWidthPercentage(100);

        for (int i = 0; i < t_productos.getColumnCount(); i++) {
            Paragraph header = new Paragraph(t_productos.getColumnName(i));
            header.setAlignment(1);
            tabla_PRODUCTS.addCell(header);
        }

        for (int i = 0; i < t_productos.getRowCount(); i++) {
            for (int a = 0; a < t_productos.getColumnCount(); a++) {

                Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a)));
                campo.setAlignment(1);
                tabla_PRODUCTS.addCell(campo);
            }
        }

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

        documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + total));
        documento.add(
                new Paragraph("FECHA Y HORA DE ENTREGA: ____________________________________________________"));
        documento.add(
                new Paragraph("NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________"));
        documento.add(
                new Paragraph("CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________"));
        documento.add(
                new Paragraph("PROXIMO SERVICIO: ___________________________________________________________"));

        Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM");
        footer.setAlignment(1);
        documento.add(footer);

        documento.close();
        Desktop.getDesktop().open(ruta);
    } catch (IOException | DocumentException ex) {
        Alert(ex.getMessage());
    } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
        Alert(ex.getMessage());
    }
}

From source file:Clases.NuevoPdf.java

private static void tableDatosEncabezado(Paragraph[] arregloParrafos, Document document)
        throws BadElementException, IOException {
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(99);/*from w w w  .j av  a 2s .c  om*/

    PdfPCell c1 = new PdfPCell(new Phrase());
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(0);
    addLogo(c1, "LOGO.png");
    table.addCell(c1);

    PdfPCell c2 = new PdfPCell();
    for (int i = 0; i < arregloParrafos.length; i++) {
        c2.addElement(arregloParrafos[i]);
    }
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setBorder(0);
    table.addCell(c2);
    float[] columnWidths = new float[] { 25f, 75f };
    try {
        table.setWidths(columnWidths);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    Paragraph p = new Paragraph();
    p.add(table);
    try {
        document.add(p);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:Clases.NuevoPdf.java

private static void addTableClienteYFactura(Document doc) throws DocumentException {
    PdfPTable encabezados = new PdfPTable(2);
    encabezados.setWidthPercentage(99);/* w w w.  j a  v  a 2 s.c  o m*/

    PdfPCell c1 = new PdfPCell(new Phrase("CLIENTE", normalWhite));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.RED);
    c1.setBorder(0);
    encabezados.addCell(c1);

    PdfPCell c2 = new PdfPCell(new Phrase("FOLIO FISCAL", normalWhite));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setBackgroundColor(BaseColor.RED);
    c2.setBorder(0);
    encabezados.addCell(c2);

    PdfPTable datos = new PdfPTable(2);
    datos.setWidthPercentage(99);

    Paragraph rfc = new Paragraph("N de Folio: " + Variables.idFactura, medium);
    Paragraph rfc2 = new Paragraph(Variables.RFC, medium);
    Paragraph nombre = new Paragraph(Variables.NombreCliente, medium);
    Paragraph direccion = new Paragraph(Variables.delegacion, medium);
    Paragraph ciudad = new Paragraph(Variables.municipio + " " + Variables.Estado + " MEXICO", medium);
    Paragraph cp = new Paragraph("CP: " + Variables.codpostal, medium);

    Paragraph[] datosCliente = { rfc, rfc2, nombre, direccion, ciudad, cp };

    PdfPCell c3 = new PdfPCell();
    for (int i = 0; i < datosCliente.length; i++) {
        c3.addElement(datosCliente[i]);
    }
    datos.addCell(c3);

    float[] columnWidths = new float[] { 60f, 40f };
    try {
        encabezados.setWidths(columnWidths);
        datos.setWidths(columnWidths);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    Paragraph folioFactura = new Paragraph("CS434-BYOR3343-GVLR03-034", smallBold);
    Paragraph csd = new Paragraph("No de serie del certificado CSD", smallBold);
    Paragraph codigo = new Paragraph("03490941023923", smallBold);
    Paragraph fecha = new Paragraph("Fecha y hora de emisin", smallBold);
    Paragraph datosfecha = new Paragraph(Variables.FechaSistema, smallBold);
    folioFactura.setAlignment(Element.ALIGN_CENTER);
    csd.setAlignment(Element.ALIGN_CENTER);
    codigo.setAlignment(Element.ALIGN_CENTER);
    fecha.setAlignment(Element.ALIGN_CENTER);
    datosfecha.setAlignment(Element.ALIGN_CENTER);

    Paragraph[] datosFactura = { folioFactura, csd, codigo, fecha, datosfecha };
    PdfPCell c4 = new PdfPCell();
    for (int i = 0; i < datosFactura.length; i++) {
        c4.addElement(datosFactura[i]);
    }
    datos.addCell(c4);

    Paragraph p = new Paragraph();
    p.add(encabezados);
    p.add(datos);
    doc.add(p);

}

From source file:Clases.NuevoPdf.java

private static void addTableProducts(Document doc) throws DocumentException {
    PdfPTable table = new PdfPTable(6);
    table.setWidthPercentage(99);// w w  w.jav  a2s  . com

    PdfPCell c1 = new PdfPCell(new Phrase("CLAVE", normalWhite));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.RED);
    c1.setBorder(0);
    table.addCell(c1);

    PdfPCell c2 = new PdfPCell(new Phrase("CANTIDAD", normalWhite));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setBackgroundColor(BaseColor.RED);
    c2.setBorder(0);
    table.addCell(c2);

    PdfPCell c3 = new PdfPCell(new Phrase("UM", normalWhite));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    c3.setBackgroundColor(BaseColor.RED);
    c3.setBorder(0);
    table.addCell(c3);

    PdfPCell c4 = new PdfPCell(new Phrase("DESCRIPCION", normalWhite));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    c4.setBackgroundColor(BaseColor.RED);
    c4.setBorder(0);
    table.addCell(c4);

    PdfPCell c5 = new PdfPCell(new Phrase("PRECIO UNITARIO", normalWhite));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    c5.setBackgroundColor(BaseColor.RED);
    c5.setBorder(0);
    table.addCell(c5);

    PdfPCell c6 = new PdfPCell(new Phrase("IMPORTE", normalWhite));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    c6.setBackgroundColor(BaseColor.RED);
    c6.setBorder(0);
    table.addCell(c6);

    float[] columnWidths = new float[] { 15f, 15f, 10f, 30f, 15f, 15f };
    try {
        table.setWidths(columnWidths);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    for (int i = 0; i < Variables.claves.size(); i++) {
        table.addCell(new Phrase(String.valueOf(Variables.claves.get(i)), normal));
        table.addCell(new Phrase(String.valueOf(Variables.cantidades.get(i)), normal));
        table.addCell(new Phrase(String.valueOf(Variables.ums.get(i)), normal));
        table.addCell(new Phrase(String.valueOf(Variables.descripciones.get(i)), normal));
        table.addCell(new Phrase(String.valueOf(Variables.preciosunitarios.get(i)), normal));
        table.addCell(new Phrase(String.valueOf(Variables.importes.get(i)), normal));

    }

    /*table.addCell(new Phrase("R0-510055-TIM",normal));
    table.addCell(new Phrase("2.0",normal));
    table.addCell(new Phrase("PIEZAS",normal));
    table.addCell(new Phrase("BALERO DOBLE",normal));
    table.addCell(new Phrase("$336.47",normal));
    table.addCell(new Phrase("$672.94",normal));*/

    Paragraph p = new Paragraph();
    p.add(table);
    doc.add(p);

}

From source file:Clases.NuevoPdf.java

private static void addTableTotales(Document doc) throws DocumentException, IOException {
    Paragraph totalEnLetras = new Paragraph("SON : SEISCIENTOS SETENTA Y TRES PESOS 52/100 M.N");
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(99);//from ww w  .j  a v a 2  s.  c  o  m

    PdfPCell c1 = new PdfPCell();
    Paragraph comentariotitulo = new Paragraph("Comentario", smallBold);
    Paragraph comentario = new Paragraph(Variables.Comentario, small);
    Paragraph cv = new Paragraph("Condicion de venta: CONTADO", smallBold);
    Paragraph fp = new Paragraph("Forma de pago: UNA SOLA EXHIBICION", smallBold);
    Paragraph mp = new Paragraph("Metodo de pago: EFECTIVO", smallBold);
    Paragraph[] formasPago = { comentariotitulo, comentario, cv, fp, mp };
    for (int i = 0; i < formasPago.length; i++) {
        c1.addElement(formasPago[i]);
    }
    c1.setBorder(0);
    table.addCell(c1);

    PdfPCell c2 = new PdfPCell();
    Paragraph s = new Paragraph("Suma:", small);
    Paragraph d = new Paragraph("Descuento:", small);
    Paragraph st = new Paragraph("Subtotal:", small);
    Paragraph iv = new Paragraph("IVA: 16%:", small);
    Paragraph t = new Paragraph("Total:", smallBold);

    Paragraph[] tags = { s, d, st, iv, t };
    for (int i = 0; i < tags.length; i++) {
        c2.addElement(tags[i]);
    }
    c2.setBorder(0);
    table.addCell(c2);

    PdfPCell c3 = new PdfPCell();
    Paragraph ns = new Paragraph("$" + String.valueOf(Variables.suma), small);
    Paragraph nd = new Paragraph("$" + String.valueOf(Variables.descuento), small);
    Paragraph nst = new Paragraph("$" + String.valueOf(Variables.subtotal), small);
    Paragraph niv = new Paragraph("$" + String.valueOf(Variables.iva), small);
    Paragraph nt = new Paragraph("$" + String.valueOf(Variables.total), smallBold);

    Paragraph[] totales = { ns, nd, nst, niv, nt };
    for (int i = 0; i < totales.length; i++) {
        c3.addElement(totales[i]);
    }
    c3.setBorder(0);
    table.addCell(c3);

    float[] columnWidths = new float[] { 66f, 17f, 17f };
    try {
        table.setWidths(columnWidths);

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    Paragraph p = new Paragraph();
    Paragraph espaciador = new Paragraph("");
    Paragraph sellodigital1 = new Paragraph("Sello digital del CFDI", smallBold);
    Paragraph sellodigital2 = new Paragraph(
            "fk0fok0f94kf09fk049fk340fk42f034kf04fk340fi43kf034fk340fk34f034kf034fk340fk340fk34f0o34kf034ofk340fo3k4f03kg35ihjlofkajflakjfl4kfj3l2kfj2f03jgoerkgjsfvns,vmernv034fv349fi2jf034ijf20gfijdqdkqejfoej",
            small);

    Paragraph sellodigital3 = new Paragraph("Sello del SAT", smallBold);
    Paragraph sellodigital4 = new Paragraph(
            "cmdvkdovewwdqwCWEFRWRVIW3903r930frvDGHERGWRBRVEGRWGWRddkfjdkfrjgkwvnsdlkcmasx,sqpsqlkcwproigkrofik24203940e2932d,swlsk qms12dikd39kdw0oc,wrjbnwepobvkjqevo24f0rwkvwri0bj35ob iwemvlw,amsc,meovkjw0bn0234or0fj",
            small);

    Paragraph sellodigital5 = new Paragraph("No de serie del complemento de  certificacion del SAT:",
            smallBold);
    Paragraph sellodigital6 = new Paragraph("00000100000002133560001", smallBold);

    Paragraph sellodigital7 = new Paragraph("Fecha y hora de certificacion:", smallBold);
    Paragraph sellodigital8 = new Paragraph(Variables.FechaFactura, small);

    Paragraph sellodigital9 = new Paragraph("Expedido en:", smallBold);
    Paragraph sellodigital10 = new Paragraph("CANCUN, QUINTANA ROO", small);
    Paragraph sellodigital11 = new Paragraph("ESTE DOCUMENTO ES UNA REPRESENTACION IMPRESA DE UN CFDI ",
            smallBold);

    Paragraph[] parrafosSellos = { sellodigital1, sellodigital2, sellodigital3, sellodigital4 };

    PdfPTable datosSAT = new PdfPTable(2);
    datosSAT.setWidthPercentage(99);

    PdfPCell cS1 = new PdfPCell(new Phrase());
    cS1.setHorizontalAlignment(Element.ALIGN_CENTER);
    cS1.setBorder(0);
    addLogo(cS1, "qr.jpg");
    datosSAT.addCell(cS1);

    PdfPCell cS2 = new PdfPCell();
    for (int i = 0; i < parrafosSellos.length; i++) {
        cS2.addElement(parrafosSellos[i]);
    }
    cS2.setBorder(0);
    datosSAT.addCell(cS2);
    float[] columnWidths2 = new float[] { 20f, 80f };
    try {
        datosSAT.setWidths(columnWidths2);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    p.add(table);
    p.add(espaciador);
    p.add(espaciador);
    p.add(datosSAT);
    p.add(sellodigital5);
    p.add(sellodigital6);
    p.add(sellodigital7);
    p.add(sellodigital8);
    p.add(sellodigital9);
    p.add(sellodigital10);
    p.add(sellodigital11);

    doc.add(p);

}