Example usage for com.lowagie.text Document open

List of usage examples for com.lowagie.text Document open

Introduction

In this page you can find the example usage for com.lowagie.text Document open.

Prototype

boolean open

To view the source code for com.lowagie.text Document open.

Click Source Link

Document

Is the document open or not?

Usage

From source file:jm.Reporte.java

License:GNU General Public License

public void balanceResultados(HttpServletResponse response, ResultSet registros) {
    String datos[][] = Addons.calcularTotalesBalance(registros, 0, 0);
    Addons.ordenamientoQuicksort(datos, 0, datos.length - 1, 2);

    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 60); /*Izquierda, derecha, tope, pie */
    try {/* w w w .  ja va  2  s . c  om*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        int columnas = Addons.maxNivelCodigos(datos) + 2;
        float anchosCols[] = new float[columnas];
        anchosCols[0] = 80f;
        anchosCols[1] = 200f;
        for (int i = 2; i < columnas; i++) {
            anchosCols[i] = 65f;
        }

        PdfPTable tbl_det = new PdfPTable(anchosCols);

        int numCols = 0;
        int nivel = 0;
        int k = 2;
        double total_ingresos = 0;
        double total_gastos = 0;
        double valor = 0;

        try {
            for (int i = 1; i < datos.length; i++) {
                valor = Addons.redondear(Double.valueOf(datos[i][4]));
                if (valor != 0) {
                    nivel = Integer.parseInt(datos[i][5]);
                    int fuente = Font.NORMAL;
                    if (nivel == 1) {
                        fuente = Font.BOLD;
                        if (datos[i][3].toUpperCase().indexOf("INGRESO") >= 0) {
                            total_ingresos = Double.valueOf(datos[i][4]);
                        }
                        if (datos[i][3].toUpperCase().indexOf("GASTO") >= 0
                                || datos[i][3].toUpperCase().indexOf("EGRESO") >= 0) {
                            total_gastos = Double.valueOf(datos[i][4]);
                        }
                    }
                    tbl_det.addCell(Addons.setCeldaPDF(datos[i][2], Font.TIMES_ROMAN, 8, fuente,
                            Element.ALIGN_LEFT, 1));
                    tbl_det.addCell(Addons.setCeldaPDF(datos[i][3], Font.TIMES_ROMAN, 8, fuente,
                            Element.ALIGN_LEFT, 1));
                    k = 2;
                    numCols = columnas - 2 - nivel;
                    for (int j = 0; j < numCols; j++) {
                        tbl_det.addCell(
                                Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1));
                        k++;
                    }
                    tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(valor), Font.TIMES_ROMAN, 8, fuente,
                            Element.ALIGN_RIGHT, 1));
                    k++;
                    for (int j = k; j < columnas; j++) {
                        tbl_det.addCell(
                                Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1));
                    }
                }
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        tbl_det.addCell(Addons.setCeldaPDF("RESULTADO DEL EJERCICIO ", Font.TIMES_ROMAN, 8, Font.BOLD,
                Element.ALIGN_LEFT, 1, 3, columnas - 1));
        tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(Addons.redondear(total_ingresos - total_gastos)),
                Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_RIGHT, 1));
        document.add(tbl_det);

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

        PdfPTable tbl_firmas = new PdfPTable(2);
        tbl_firmas.addCell(
                Addons.setCeldaPDF("GERENTE", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 0));
        tbl_firmas.addCell(
                Addons.setCeldaPDF("CONTADOR", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 0));
        document.add(tbl_firmas);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void importaciones(HttpServletResponse response, ResultSet registros, DataBase objDB) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {//w  w  w.  jav  a2  s  .  c o m
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        try {
            String[] cabTabla = new String[] { "#", "Nro. FACTURA", "RAZON SOCIAL", "F. EMISION", "SUBTOTAL",
                    "DESCUENTO", "IVA", "TOTAL" };
            float[] anchoTabla = new float[] { 15f, 80f, 160f, 60f, 70f, 70f, 70f, 70f };
            ResultSet facturas = null;
            String id_dau = "-1";
            int num = 1;
            while (registros.next()) {
                /* MAESTRO */
                PdfPTable tbl_maestro = new PdfPTable(new float[] { 35f, 140f, 50f, 140f });
                id_dau = (registros.getString("id_dau") != null) ? registros.getString("id_dau") : "-1";

                tbl_maestro.addCell(Addons.setCeldaPDF("ADUANA - CONTRIBUYENTE", Font.TIMES_ROMAN, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 1, 3, 4));

                tbl_maestro.addCell(Addons.setCeldaPDF("Nmero: ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF(
                        ((registros.getString("num_dau") != null) ? registros.getString("num_dau") : ""),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF("Fecha/Hora TX: ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF(((registros.getString("fecha_tx_sql") != null)
                        ? registros.getString("fecha_tx_sql")
                        : "") + " - "
                        + ((registros.getString("hora_tx") != null) ? registros.getString("hora_tx") : ""),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));

                tbl_maestro.addCell(Addons.setCeldaPDF("Importador: ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF(
                        ((registros.getString("importador") != null) ? registros.getString("importador") : ""),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF("Direccin: ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_maestro.addCell(Addons.setCeldaPDF(
                        ((registros.getString("direccion") != null) ? registros.getString("direccion") : ""),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                document.add(tbl_maestro);

                PdfPTable tbl_valoresAduana = new PdfPTable(6);
                tbl_valoresAduana.addCell(Addons.setCeldaPDF("VALORES EN ADUANA", Font.TIMES_ROMAN, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 1, 3, 6));

                tbl_valoresAduana.addCell(
                        Addons.setCeldaPDF("Fob USD", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF("Flete USD", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF("Seguro USD", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF("Ajuste USD", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(
                        Addons.setCeldaPDF("CIF USD", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF("Valor Aduana USD", Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 1));

                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("fob") != null) ? registros.getString("fob") : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("flete") != null) ? registros.getString("flete") : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("seguro") != null) ? registros.getString("seguro") : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("ajuste") != null) ? registros.getString("ajuste") : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("cif") != null) ? registros.getString("cif") : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_valoresAduana.addCell(Addons.setCeldaPDF(
                        ((registros.getString("valor_aduana") != null) ? registros.getString("valor_aduana")
                                : "0"),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                document.add(tbl_valoresAduana);

                PdfPTable tbl_autoliquidacion = new PdfPTable(2);
                float valor_em = (registros.getString("valor_em") != null) ? registros.getFloat("valor_em") : 0;
                float der_especifico = (registros.getString("der_especifico") != null)
                        ? registros.getFloat("der_especifico")
                        : 0;
                float ice = (registros.getString("ice") != null) ? registros.getFloat("ice") : 0;
                float iva = (registros.getString("iva") != null) ? registros.getFloat("iva") : 0;
                float antidumping = (registros.getString("antidumping") != null)
                        ? registros.getFloat("antidumping")
                        : 0;
                float der_consular = (registros.getString("der_consular") != null)
                        ? registros.getFloat("der_consular")
                        : 0;
                float sobretiempo_petr = (registros.getString("sobretiempo_petr") != null)
                        ? registros.getFloat("sobretiempo_petr")
                        : 0;
                float ad_barril_crudo = (registros.getString("ad_barril_crudo") != null)
                        ? registros.getFloat("ad_barril_crudo")
                        : 0;
                float tasa_modernizacion = (registros.getString("tasa_modernizacion") != null)
                        ? registros.getFloat("tasa_modernizacion")
                        : 0;
                float tasa_control = (registros.getString("tasa_control") != null)
                        ? registros.getFloat("tasa_control")
                        : 0;
                float tasa_almacenaje = (registros.getString("tasa_almacenaje") != null)
                        ? registros.getFloat("tasa_almacenaje")
                        : 0;
                float multa = (registros.getString("multa") != null) ? registros.getFloat("multa") : 0;
                float interes = (registros.getString("interes") != null) ? registros.getFloat("interes") : 0;
                float imp_salida_divisa = (registros.getString("imp_salida_divisa") != null)
                        ? registros.getFloat("imp_salida_divisa")
                        : 0;
                float fodinfa = (registros.getString("fodinfa") != null) ? registros.getFloat("fodinfa") : 0;
                float corpei = (registros.getString("corpei") != null) ? registros.getFloat("corpei") : 0;
                float otros = (registros.getString("otros") != null) ? registros.getFloat("otros") : 0;
                float salvaguarda = (registros.getString("salvaguarda") != null)
                        ? registros.getFloat("salvaguarda")
                        : 0;
                float total_autoliquidacion = (registros.getString("total_autoliquidacion") != null)
                        ? registros.getFloat("total_autoliquidacion")
                        : 0;

                tbl_autoliquidacion.addCell(Addons.setCeldaPDF("AUTOLIQUIDACION DE TRIBUTOS", Font.TIMES_ROMAN,
                        8, Font.BOLD, Element.ALIGN_LEFT, 1, 3, 2));

                tbl_autoliquidacion.addCell(Addons.setCeldaPDF("CONCEPTO", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                tbl_autoliquidacion.addCell(Addons.setCeldaPDF("CANTIDAD A PAGAR", Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_CENTER, 1));

                if (valor_em > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("AD / VALOREM", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(valor_em), Font.TIMES_ROMAN,
                            8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (der_especifico > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("DER. ESPECIFICO", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(der_especifico),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (ice > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("IMP. CONSUMO ESPECIAL", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(ice), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (iva > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("IMP. VALOR AGREGADO", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(iva), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (antidumping > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("DERECHO ANTIDUMPING", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(antidumping),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (der_consular > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("DERECHOS CONSULARES", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(der_consular),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (sobretiempo_petr > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("SOBRETIEMPO PETROLEO", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(sobretiempo_petr),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (ad_barril_crudo > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("ADICIONAL POR BARRIL DE CRUDO",
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(ad_barril_crudo),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (tasa_modernizacion > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("TASA MODERNIZACION", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(tasa_modernizacion),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (tasa_control > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("TASA DE CONTROL", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(tasa_control),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (tasa_almacenaje > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("TASA ALMACENAJE", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(tasa_almacenaje),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (multa > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("MULTAS (ART. 89 Y 91)", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(multa), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (interes > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("INTERESES", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(interes), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (imp_salida_divisa > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("IMP. A LA SALIDA DE DIVISAS",
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(imp_salida_divisa),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (fodinfa > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("FODINFA", Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(fodinfa), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (corpei > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("CORPEI", Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(corpei), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (otros > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("OTROS", Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(otros), Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                if (salvaguarda > 0) {
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF("SALVAGUARDA", Font.TIMES_ROMAN, 8,
                            Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(salvaguarda),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                tbl_autoliquidacion.addCell(Addons.setCeldaPDF("TOTAL AUTOLIQUIDACION", Font.TIMES_ROMAN, 8,
                        Font.BOLD, Element.ALIGN_RIGHT, 1));
                tbl_autoliquidacion.addCell(Addons.setCeldaPDF(String.valueOf(total_autoliquidacion),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                document.add(tbl_autoliquidacion);

                /* DETALLE */
                PdfPTable tbl_fact = new PdfPTable(1);
                tbl_fact.addCell(
                        Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0));
                tbl_fact.addCell(Addons.setCeldaPDF("FACTURAS ADJUNTAS", Font.TIMES_ROMAN, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0));
                document.add(tbl_fact);
                document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));
                PdfPTable tbl_det = new PdfPTable(anchoTabla);
                num = 1;
                try {
                    facturas = objDB.consulta(
                            "select F.numero_factura, F.razon_social, toDateSQL(F.fecha_compra), F.subtotal, F.descuento, F.iva_12, F.total_compra "
                                    + "from vta_factura_compra as F inner join tbl_factura_importacion as FI on F.id_factura_compra=FI.id_factura_compra "
                                    + "where FI.id_dau=" + id_dau);
                    while (facturas.next()) {
                        tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8,
                                Font.NORMAL, Element.ALIGN_CENTER, 1));
                        for (int i = 1; i <= 7; i++) {
                            tbl_det.addCell(Addons.setCeldaPDF(
                                    ((facturas.getString(i) != null) ? facturas.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL,
                                    (i <= 3 ? Element.ALIGN_LEFT : Element.ALIGN_RIGHT), 1));
                        }
                        num++;
                    }
                    registros.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                document.add(tbl_det);

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

            }

            facturas.close();
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void RPLiquidacionIndividual(HttpServletResponse response, ResultSet rsRolPago, DataBase objDB,
        Sucursal objSucursal) {//from w  w  w .j  a va  2  s  .c o  m
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        String id_sucursal = "";
        String dni = "";
        String id_empleado = "";
        String empleado = "";
        String periodo = "";
        String departamento = "";
        String rol = "";
        String dias_laborados = "";
        String num_horas_50 = "";
        String num_horas_100 = "";
        String sbu = "";
        String ing_total_50 = "";
        String ing_total_100 = "";
        String total_ingreso = "";
        String egr_iess = "";
        String total_egreso = "";
        String total_pagar = "";
        try {
            boolean ban = false;
            while (rsRolPago.next()) {
                if (ban) {
                    document.newPage();
                }
                ban = true;

                id_sucursal = (rsRolPago.getString("id_sucursal") != null) ? rsRolPago.getString("id_sucursal")
                        : "";
                dni = (rsRolPago.getString("dni") != null) ? rsRolPago.getString("dni") : "";
                id_empleado = (rsRolPago.getString("id_empleado") != null) ? rsRolPago.getString("id_empleado")
                        : "";
                empleado = (rsRolPago.getString("empleado") != null) ? rsRolPago.getString("empleado") : "";
                periodo = (rsRolPago.getString("periodo_sql") != null) ? rsRolPago.getString("periodo_sql")
                        : "";
                departamento = (rsRolPago.getString("departamento") != null)
                        ? Fecha.ISOaSQL(rsRolPago.getString("departamento"))
                        : "";
                rol = (rsRolPago.getString("rol") != null) ? rsRolPago.getString("rol") : "";
                dias_laborados = (rsRolPago.getString("dias_laborados") != null)
                        ? rsRolPago.getString("dias_laborados")
                        : "";
                num_horas_50 = (rsRolPago.getString("num_horas_50") != null)
                        ? rsRolPago.getString("num_horas_50")
                        : "";
                num_horas_100 = (rsRolPago.getString("num_horas_100") != null)
                        ? rsRolPago.getString("num_horas_100")
                        : "";
                sbu = (rsRolPago.getString("sbu") != null) ? rsRolPago.getString("sbu") : "";
                ing_total_50 = (rsRolPago.getString("ing_total_50") != null)
                        ? rsRolPago.getString("ing_total_50")
                        : "";
                ing_total_100 = (rsRolPago.getString("ing_total_100") != null)
                        ? rsRolPago.getString("ing_total_100")
                        : "";
                total_ingreso = (rsRolPago.getString("total_ingreso") != null)
                        ? rsRolPago.getString("total_ingreso")
                        : "";
                egr_iess = (rsRolPago.getString("egr_iess") != null) ? rsRolPago.getString("egr_iess") : "";
                total_egreso = (rsRolPago.getString("total_egreso") != null)
                        ? rsRolPago.getString("total_egreso")
                        : "";
                total_pagar = (rsRolPago.getString("total_pagar") != null) ? rsRolPago.getString("total_pagar")
                        : "";
                int anio = Fecha.datePart("anio", periodo);
                int mes = Fecha.datePart("mes", periodo);
                String fecha_ini = anio + "-" + mes + "-01";
                String fecha_fin = anio + "-" + mes + "-" + Fecha.getUltimoDiaMes(anio, mes);

                /* MAESTRO */
                PdfPTable tbl_maestro = new PdfPTable(3);

                tbl_maestro.addCell(Addons.setCeldaPDF(this.titulo, Font.TIMES_ROMAN, 10, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 5, 3));

                tbl_maestro.addCell(Addons.setCeldaPDF("Rol de Pago: Liquidacin individual", Font.TIMES_ROMAN,
                        8, Font.NORMAL, Element.ALIGN_LEFT, 0, 3, 3));

                tbl_maestro.addCell(Addons.setCeldaPDF("Nombres: " + empleado, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0, 3, 2));
                tbl_maestro.addCell(Addons.setCeldaPDF("Perodo: " + periodo, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));

                tbl_maestro.addCell(Addons.setCeldaPDF("Sucursal: " + objSucursal.getNombre(id_sucursal),
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0));
                tbl_maestro.addCell(Addons.setCeldaPDF("Departamento: " + departamento, Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 0));
                tbl_maestro.addCell(Addons.setCeldaPDF("Cargo: " + rol, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));

                tbl_maestro.addCell(Addons.setCeldaPDF("Tiempo laborado: " + dias_laborados, Font.TIMES_ROMAN,
                        8, Font.NORMAL, Element.ALIGN_LEFT, 0));
                tbl_maestro.addCell(Addons.setCeldaPDF("H.E. 50%: " + num_horas_50, Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 0));
                tbl_maestro.addCell(Addons.setCeldaPDF("H.E. 100%: " + num_horas_100, Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 0));

                tbl_maestro.addCell(
                        Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 6, Font.NORMAL, Element.ALIGN_LEFT, 0, 1, 3));
                document.add(tbl_maestro);

                /* DETALLE */

                /* ingresos  */
                PdfPTable tbl_ingresos = new PdfPTable(new float[] { 3, 1 });
                tbl_ingresos.addCell(Addons.setCeldaPDF("INGRESOS", Font.TIMES_ROMAN, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1));
                tbl_ingresos.addCell(
                        Addons.setCeldaPDF("VALOR", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_CENTER, 1));

                tbl_ingresos.addCell(Addons.setCeldaPDF("Sueldo bsico unificado", Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl_ingresos.addCell(Addons.setCeldaPDF("+" + sbu, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));

                tbl_ingresos.addCell(Addons.setCeldaPDF("Horas extras 50%", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_ingresos.addCell(Addons.setCeldaPDF("+" + ing_total_50, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));

                tbl_ingresos.addCell(Addons.setCeldaPDF("Horas extras 100%", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_ingresos.addCell(Addons.setCeldaPDF("+" + ing_total_100, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                try {
                    ResultSet rsIngresosEmpleado = objDB.consulta(
                            "SELECT * FROM vta_rol_pago_rubro_empleado where tipo=true and anulado=false and id_empleado="
                                    + id_empleado + " and periodo between '" + fecha_ini + "' and '" + fecha_fin
                                    + "';");
                    while (rsIngresosEmpleado.next()) {
                        tbl_ingresos
                                .addCell(Addons.setCeldaPDF(
                                        ((rsIngresosEmpleado.getString("rubro") != null)
                                                ? rsIngresosEmpleado.getString("rubro")
                                                : ""),
                                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        tbl_ingresos
                                .addCell(Addons.setCeldaPDF(
                                        "+" + ((rsIngresosEmpleado.getString("valor") != null)
                                                ? rsIngresosEmpleado.getString("valor")
                                                : "0.00"),
                                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                    }
                    rsIngresosEmpleado.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                /* egresos  */
                PdfPTable tbl_egresos = new PdfPTable(new float[] { 3, 1 });
                tbl_egresos.addCell(
                        Addons.setCeldaPDF("EGRESOS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_CENTER, 1));
                tbl_egresos.addCell(
                        Addons.setCeldaPDF("VALOR", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_CENTER, 1));

                tbl_egresos.addCell(Addons.setCeldaPDF("Aporte IESS", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_egresos.addCell(Addons.setCeldaPDF("-" + egr_iess, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                try {
                    ResultSet rsIngresosEmpleado = objDB.consulta(
                            "SELECT * FROM vta_rol_pago_rubro_empleado where tipo=false and anulado=false and id_empleado="
                                    + id_empleado + " and periodo between '" + fecha_ini + "' and '" + fecha_fin
                                    + "';");
                    while (rsIngresosEmpleado.next()) {
                        tbl_egresos
                                .addCell(Addons.setCeldaPDF(
                                        ((rsIngresosEmpleado.getString("rubro") != null)
                                                ? rsIngresosEmpleado.getString("rubro")
                                                : ""),
                                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        tbl_egresos
                                .addCell(Addons.setCeldaPDF(
                                        "-" + ((rsIngresosEmpleado.getString("valor") != null)
                                                ? rsIngresosEmpleado.getString("valor")
                                                : "0.00"),
                                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                    }
                    rsIngresosEmpleado.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                PdfPTable tbl_totales = new PdfPTable(new float[] { 3, 1, 3, 1 });
                tbl_totales.addCell(Addons.setCeldaPDF("TOTAL INGRESOS", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));
                tbl_totales.addCell(Addons.setCeldaPDF("$ " + total_ingreso, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0));
                tbl_totales.addCell(Addons.setCeldaPDF("TOTAL EGRESOS", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));
                tbl_totales.addCell(Addons.setCeldaPDF("$ " + total_egreso, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0));

                tbl_totales.addCell(Addons.setCeldaPDF("VALOR A RECIBIR:     $ " + total_pagar,
                        Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0, 3, 4));

                PdfPTable tbl_det = new PdfPTable(2);
                tbl_det.addCell(Addons.setCeldaPDF(tbl_ingresos, Element.ALIGN_LEFT, 0));
                tbl_det.addCell(Addons.setCeldaPDF(tbl_egresos, Element.ALIGN_LEFT, 0));
                document.add(tbl_det);

                document.add(tbl_totales);

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

                PdfPTable tbl_firma = new PdfPTable(1);
                tbl_firma.addCell(Addons.setCeldaPDF("______________________", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));
                tbl_firma.addCell(Addons.setCeldaPDF("Recib conforme", Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));
                tbl_firma.addCell(Addons.setCeldaPDF("C.C.  " + dni, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 0));
                document.add(tbl_firma);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void RPLiquidacionResumen(HttpServletResponse response, String[] cabTabla, float[] anchoTabla,
        ResultSet registros, int sumarDesde) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {//from ww  w  .j a  v a  2  s  . c o m
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int num2 = 1;
        String aux = "";
        String columna1 = "";
        int num_sumas = cabTabla.length - sumarDesde;
        float suma_parcial[] = new float[num_sumas];
        float suma_total[] = new float[num_sumas];
        float valor[] = new float[num_sumas];
        int pos = 0;
        try {
            while (registros.next()) {
                columna1 = (registros.getString(1) != null) ? registros.getString(1) : "";
                pos = 0;
                if (aux.compareTo(columna1) != 0) {
                    if (num > 1) {
                        tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                                Element.ALIGN_RIGHT, 0, 4, sumarDesde));
                        for (int j = 0; j < suma_parcial.length - 1; j++) {
                            tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0));
                            suma_parcial[j] = 0;
                        }
                        tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                                Element.ALIGN_RIGHT, 0));
                    }
                    tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 3, numCols + 2));
                    aux = columna1;
                    num2 = 1;
                }
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 2; i <= numCols; i++) {
                    if (i < sumarDesde) {
                        tbl_det.addCell(Addons.setCeldaPDF(
                                ((registros.getString(i) != null) ? registros.getString(i) : ""),
                                Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    } else {
                        valor[pos] = (registros.getString(i) != null) ? registros.getFloat(i) : 0;
                        tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor[pos]), Font.TIMES_ROMAN, 8,
                                Font.NORMAL, Element.ALIGN_RIGHT, 1));
                        suma_parcial[pos] = Float.parseFloat(this.formatoNumero.format(suma_parcial[pos]))
                                + valor[pos];
                        suma_total[pos] = Float.parseFloat(this.formatoNumero.format(suma_total[pos]))
                                + valor[pos];
                        pos++;
                    }
                }
                tbl_det.addCell(
                        Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 9, Font.NORMAL, Element.ALIGN_RIGHT, 1));

                num++;
                num2++;
            }
            tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, sumarDesde));
            for (int j = 0; j < suma_parcial.length - 1; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_RIGHT, 0));
            }
            tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0));

            tbl_det.addCell(Addons.setCeldaPDF("TOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, sumarDesde));
            for (int j = 0; j < suma_total.length - 1; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_total[j]), Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_RIGHT, 0));
            }
            tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0));

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void correos(HttpServletResponse response, ResultSet registros) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {/* w  w w  .j a  va  2 s. c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        PdfPTable tbl_det = new PdfPTable(new float[] { 20, 80 });
        String aux = "";
        String columna1 = "";
        String columna2 = "";
        boolean uno = true;
        try {
            tbl_det.addCell(
                    Addons.setCeldaPDF("SECTOR", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_CENTER, 1));
            tbl_det.addCell(Addons.setCeldaPDF("CORREOS ELECTRONICOS", Font.TIMES_ROMAN, 8, Font.BOLD,
                    Element.ALIGN_CENTER, 1));
            while (registros.next()) {
                columna1 = (registros.getString(1) != null) ? registros.getString(1) : "";
                columna2 += ((registros.getString(2) != null) ? registros.getString(2) : "") + ", ";
                if (aux.compareTo(columna1) != 0 && !uno) {
                    tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_det.addCell(Addons.setCeldaPDF(columna2.substring(0, columna2.length() - 2),
                            Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    aux = columna1;
                    columna2 = "";
                }
                uno = false;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void activosPersonalizadosClientes(HttpServletResponse response, String[] cabTabla, float[] anchoTabla,
        ResultSet registros, DataBase objDB) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {//w  ww.  j  av  a 2s . c  om
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        try {
            while (registros.next()) {
                String persona_recibe = "";
                String num_personalizacion = (registros.getString("num_personalizacion") != null)
                        ? registros.getString("num_personalizacion")
                        : "";
                try {
                    ResultSet rs = objDB
                            .consulta("select * from tbl_activo_personalizacion where num_documento="
                                    + num_personalizacion);
                    if (rs.next()) {
                        persona_recibe = (rs.getString("persona_recibe") != null)
                                ? rs.getString("persona_recibe")
                                : "";
                        rs.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(persona_recibe), Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_LEFT, 1));

                String mac = (registros.getString("codigo_activo") != null)
                        ? registros.getString("codigo_activo")
                        : "";
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(mac), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
            }

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.seg.frmGeneraPdf.java

License:GNU General Public License

public void GenerarFactura(String ruta_xml, String dir, String _archivoNombre) throws FileNotFoundException {
    File _archivo = null;//from ww w. java 2  s . c o m
    Xml xml = new Xml(ruta_xml + ".xml");

    String numeroAutorizacion = xml.getValor("numeroAutorizacion");
    String fechaAutorizacion = xml.getValor("fechaAutorizacion");

    String doc = xml.getValor("comprobante");
    try {

        _archivo = new File(dir, _archivoNombre + "xml.xml");
        if (!_archivo.exists()) {
            //byte[] bytes = (res.getString(campoBytea)!=null) ? res.getBytes(campoBytea) : null;
            RandomAccessFile archivo = new RandomAccessFile(dir + _archivoNombre + "xml.xml", "rw");
            archivo.writeBytes(doc);
            archivo.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    //infoTributaria
    Xml xml2 = new Xml(ruta_xml + "xml.xml");
    String ambiente = xml2.getValor("ambiente");
    String tipoEmision = xml2.getValor("tipoEmision");
    String razonSocial = xml2.getValor("razonSocial");
    String nombreComercial = xml2.getValor("nombreComercial");
    String ruc = xml2.getValor("ruc");
    String claveAcceso = xml2.getValor("claveAcceso");
    String codDoc = xml2.getValor("codDoc");
    String numFac = xml2.getValor("estab") + "-" + xml2.getValor("ptoEmi") + "-" + xml2.getValor("secuencial");
    String dirMatriz = xml2.getValor("dirMatriz");

    String EMAIL = "";
    String DIRECCION = "";
    String ARCOTEL = "";

    int limiteAdi = xml2.getNumNodos("campoAdicional");
    try {
        //Campos Adicionales
        for (int i = 0; i < limiteAdi; i++) {
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("EMAIL") == 0) {
                EMAIL = xml2.getValor("campoAdicional", i);
            }
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("DIRECCION") == 0) {
                DIRECCION = xml2.getValor("campoAdicional", i);
            }
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("ARCOTEL") == 0) {
                ARCOTEL = xml2.getValor("campoAdicional", i);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (ambiente.compareTo("1") == 0) {
        ambiente = "Pruebas";
    }
    if (ambiente.compareTo("2") == 0) {
        ambiente = "Produccin";
    }
    if (tipoEmision.compareTo("1") == 0) {
        tipoEmision = "Normal";
    }
    if (tipoEmision.compareTo("2") == 0) {
        tipoEmision = "Contingencia";
    }

    if (codDoc.compareTo("01") == 0) {
        //infoFactura
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String razonSocialComprador = xml2.getValor("razonSocialComprador");
        String identificacionComprador = xml2.getValor("identificacionComprador");
        String totalSinImpuestos = xml2.getValor("totalSinImpuestos");
        String totalDescuento = xml2.getValor("totalDescuento");
        String codigoPorcentaje = xml2.getValor("codigoPorcentaje");//0% 0 >>12% 2>>mo objeto de impuesto 6>>Excento al iva 7
        String baseImponible = xml2.getValor("baseImponible"); //Depende del codigo porcentaje
        String valor = xml2.getValor("valor");// va en el Iva 12%
        String importeTotal = xml2.getValor("importeTotal");//Sumatoria de todo

        //detalles
        int limite = xml2.getNumNodos("detalle");
        String[][] array = new String[limite][6];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigoPrincipal");
            array[i][1] = xml2.getValor("descripcion");
            array[i][2] = xml2.getValor("cantidad");
            array[i][3] = xml2.getValor("precioUnitario");
            array[i][4] = xml2.getValor("descuento");
            array[i][5] = xml2.getValor("precioTotalSinImpuesto");
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("F A C T U R A ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACION", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialComprador, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionComprador, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin:    " + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 1));
            tbl_info1.addCell(Addons.setCeldaPDF("DIRECCION: " + DIRECCION, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 2));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 10f, 10f, 50f, 10f, 10f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Cod. Principal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Cant.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Descripcin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Precio Unitario", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Desc.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Total", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            for (int i = 0; i < limite; i++) {
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][0], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][1], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][5], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
            }
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            PdfPTable tbl_info_ad2 = new PdfPTable(new float[] { 70f, 30f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));

            //Titulos derecha
            if (codigoPorcentaje.compareTo("0") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 0, 5, 2));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("DESCUENTO", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalDescuento, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));
            }

            if (codigoPorcentaje.compareTo("2") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("DESCUENTO", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalDescuento, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(
                        Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));
            }

            tbl_info_ad2.addCell(Addons.setCeldaPDF("VALOR TOTAL", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_info_ad2.addCell(Addons.setCeldaPDF(Addons.redondear(importeTotal), Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));

            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad2, 0, 1));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

    //Nota de credito
    if (codDoc.compareTo("04") == 0) {
        //infoFactura
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String razonSocialComprador = xml2.getValor("razonSocialComprador");
        String identificacionComprador = xml2.getValor("identificacionComprador");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String codDocModificado = xml2.getValor("codDocModificado");
        String numDocModificado = xml2.getValor("numDocModificado");
        String fechaEmisionDocSustento = xml2.getValor("fechaEmisionDocSustento");
        String motivo = xml2.getValor("motivo");
        String totalSinImpuestos = xml2.getValor("totalSinImpuestos");

        if (codDocModificado.compareTo("01") == 0) {
            codDocModificado = "FACTURA";
        }
        if (codDocModificado.compareTo("04") == 0) {
            codDocModificado = "NOTA DE CRDITO";
        }
        if (codDocModificado.compareTo("05") == 0) {
            codDocModificado = "NOTA DE DBITO";
        }
        if (codDocModificado.compareTo("06") == 0) {
            codDocModificado = "GU?A DE REMISION";
        }
        if (codDocModificado.compareTo("07") == 0) {
            codDocModificado = "COMPROBANTE DE RETENCIN";
        }

        String codigoPorcentaje = xml2.getValor("codigoPorcentaje");//0% 0 >>12% 2>>mo objeto de impuesto 6>>Excento al iva 7
        String baseImponible = xml2.getValor("baseImponible"); //Depende del codigo porcentaje
        String valor = xml2.getValor("valor");// va en el Iva 12%

        //detalles
        int limite = xml2.getNumNodos("detalle");
        String[][] array = new String[limite][6];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigoPrincipal");
            array[i][1] = xml2.getValor("descripcion");
            array[i][2] = xml2.getValor("cantidad");
            array[i][3] = xml2.getValor("precioUnitario");
            array[i][4] = xml2.getValor("descuento");
            array[i][5] = xml2.getValor("precioTotalSinImpuesto");
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("F A C T U R A ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialComprador, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionComprador, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin:" + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 3));

            tbl_info1.addCell(Addons.setCeldaPDF(
                    "-------------------------------------------------------------------------------------------------------------",
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 0, 5, 3));
            tbl_info1.addCell(Addons.setCeldaPDF("Comprobante que se Modifica:", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(codDocModificado + ": " + numDocModificado, Font.STRIKETHRU,
                    10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha emisin (Comprobante a Modificar)", Font.STRIKETHRU,
                    10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(fechaEmisionDocSustento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info1.addCell(Addons.setCeldaPDF("Razn de Modificacin: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(
                    Addons.setCeldaPDF(motivo, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 10f, 10f, 50f, 10f, 10f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Cod. Principal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Cant.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Descripcin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Precio Unitario", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Desc.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Total", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            for (int i = 0; i < limite; i++) {
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][0], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][1], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][5], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
            }
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            PdfPTable tbl_info_ad2 = new PdfPTable(new float[] { 70f, 30f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));

            //Titulos derecha
            if (codigoPorcentaje.compareTo("0") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 0, 5, 2));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));
            }

            else {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(
                        Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));
            }

            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad2, 0, 1));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

    //Comprobante de retencion
    if (codDoc.compareTo("07") == 0) {
        //infoCompRetencion
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String tipoIdentificacionSujetoRetenido = xml2.getValor("tipoIdentificacionSujetoRetenido");
        String razonSocialSujetoRetenido = xml2.getValor("razonSocialSujetoRetenido");
        String identificacionSujetoRetenido = xml2.getValor("identificacionSujetoRetenido");
        String periodoFiscal = xml2.getValor("periodoFiscal");

        //detalles
        int limite = xml2.getNumNodos("impuesto");
        String[][] array = new String[limite][7];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigo", i);
            array[i][1] = xml2.getValor("codigoRetencion", i);
            array[i][2] = xml2.getValor("baseImponible", i);
            array[i][3] = xml2.getValor("porcentajeRetener", i);
            array[i][4] = xml2.getValor("valorRetenido", i);
            array[i][5] = xml2.getValor("codDocSustento", i);
            array[i][6] = xml2.getValor("numDocSustento", i);
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("COMPROBANTE DE RETENCIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialSujetoRetenido, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionSujetoRetenido, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin: " + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 3));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 14f, 18f, 12f, 10f, 13f, 10f, 13f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Comprobante", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Nmero", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Fecha Emisin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Ejercicio Fiscal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Base Imponible para la retencion", Font.STRIKETHRU, 8,
                    Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Impuesto", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Porcentaje de Retencin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Valor Retenido", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            Double val_ret = 0.0;

            //detalles
            for (int i = 0; i < limite; i++) {
                //Comprobante
                if (array[i][5].compareTo("01") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("FACTURA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("04") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("NOTA DE CRDITO", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("05") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("NOTA DE DBITO", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("06") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("GU?A DE REMISION", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("07") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("COMPROBANTE DE RETENCIN", Font.STRIKETHRU, 10,
                            Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                }

                //Nmero
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][6], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Fecha Emisin
                tbl_det1.addCell(Addons.setCeldaPDF(fechaEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Ejercicio Fiscal
                tbl_det1.addCell(Addons.setCeldaPDF(periodoFiscal, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Base Imponible para la retencion
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Impuesto
                if (array[i][0].compareTo("1") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("RENTA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][0].compareTo("2") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("IVA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][0].compareTo("6") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("ISD", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }

                //Porcentaje de Retencin
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Valor Retenido
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                val_ret += Double.parseDouble(array[i][4]);
            }
            tbl_det1.addCell(Addons.setCeldaPDF("Valor Retenido", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_RIGHT, 1, 5, 7));
            tbl_det1.addCell(Addons.setCeldaPDF(Addons.redondear(val_ret) + "", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 1, 5, 1));
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

}

From source file:jmbench.plots.UtilPlotPdf.java

License:Open Source License

public static void saveAsPdf(JFreeChart chart, String FILENAME, int width, int height) {
    File parent = new File(new File(FILENAME).getParent());
    if (!parent.exists()) {
        if (!parent.mkdirs())
            throw new RuntimeException("Can't make directory path");
    }//from   www . j  a va  2 s  . c  o  m

    Document document = new Document(new Rectangle(width, height));
    try {
        FileOutputStream file = new FileOutputStream(FILENAME);
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2d, r2d);
        g2d.dispose();
        cb.addTemplate(tp, 0, 0);
        document.close();
        g2d.dispose();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:jmbench.plots.UtilPlotPdf.java

License:Open Source License

public static void saveAsPdf(LegendTitle legend, String FILENAME, int width, int height) {
    Document document = new Document(new Rectangle(width, height));
    try {/*w ww  .  j  a v a  2  s  .  c o  m*/
        FileOutputStream file = new FileOutputStream(FILENAME);
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
        legend.draw(g2d, r2d);
        g2d.dispose();
        cb.addTemplate(tp, 0, 0);
        document.close();
        g2d.dispose();
    } catch (Exception e) {
        e.printStackTrace();
    }
}