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

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

Introduction

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

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

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;//from w  w w . 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 {/*  ww  w  .  j av  a  2 s  . com*/
        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  va 2  s.c  om*/
        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 www  .j  a v  a  2s . com

    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);/*from w w  w.j a  v a  2 s  . co  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);/*from   ww w .  j  a  v  a 2  s .  c  o m*/

    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 www  . j  a v  a2s  .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);

}

From source file:classes.PdfFiles.java

private static void createTable(Document document, java.util.List<Product> selling_list) {

    /*Create table*/
    PdfPTable table = new PdfPTable(4);

    /*Create price*/
    Double price = 0.0;//from www  .  ja  v  a  2s  . c  o m

    /*Add cells*/
    PdfPCell c1 = new PdfPCell(new Phrase("Nazwa"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Cena"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("VAT"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Ilosc"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    /*Add cells for each product*/
    for (Product p : selling_list) {
        table.addCell(p.getName());
        table.addCell(Double.toString(p.getRetail_price()));
        table.addCell(Double.toString(p.getVat()));
        table.addCell(Integer.toString(p.getQuantity()));
    }

    Function f = new Function();

    /*Get price*/
    price = f.getPriceFromProductList(selling_list);
    try {
        /*Add table*/
        Paragraph p = new Paragraph();
        p.add(table);
        addEmptyLine(p, 2);
        Paragraph p2 = new Paragraph(Double.toString(price) + " PLN");
        p2.setAlignment(Element.ALIGN_RIGHT);
        p.add(p2);
        document.add(p);
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error genrating Invoice");
        Logger.getLogger(PdfFiles.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:client.welcome0.java

private void insertCell(PdfPTable table, String text, int align, int colspan, com.itextpdf.text.Font font) {

    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    //set the cell alignment
    cell.setHorizontalAlignment(align);/*from w  w  w. java 2  s . c o  m*/
    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);
    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);

}

From source file:client.welcome1.java

/**
 * insert single cells to the PDF file ad fills them with text 
 * @param table//from   w  w w .  j a va2 s  .c o m
 * @param text
 * @param align
 * @param colspan
 * @param font 
 */
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) {

    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    //set the cell alignment
    cell.setHorizontalAlignment(align);
    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);
    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);

}