Example usage for com.itextpdf.text Element ALIGN_CENTER

List of usage examples for com.itextpdf.text Element ALIGN_CENTER

Introduction

In this page you can find the example usage for com.itextpdf.text Element ALIGN_CENTER.

Prototype

int ALIGN_CENTER

To view the source code for com.itextpdf.text Element ALIGN_CENTER.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:cimav.restrh.services.JustificacionREST.java

@GET
@Path("pdficar")
@Produces("application/pdf")
public Response pdficar(@DefaultValue("0") @QueryParam("id") Integer id_param) {
    Justificacion justi = (Justificacion) JustificacionREST.this.find(id_param);

    String diasCorresponde = "corresponde a " + justi.getNumDiasPlazo() + " das";
    if (justi.getNumDiasPlazo() == 1) {
        diasCorresponde = "corresponde a un da";
    }//from  www  . j a  v a 2 s  . c  om

    // <editor-fold defaultstate="collapsed" desc="Constantes de texto">            
    HashMap<String, String> mapa = new HashMap();
    mapa.put("texto1_I",
            "No existan bienes o servicios alternativos o sustitutos tcnicamente razonables, o bien, que en el "
                    + "mercado slo existe un posible oferente, o se trate de una persona que posee la titularidad o el "
                    + "licenciamiento exclusivo de patentes, derechos de autor, u otros derechos exclusivos, o por "
                    + "tratarse de obras de arte.");
    mapa.put("texto1_III",
            "Existan circunstancias que puedan provocar prdidas o costos adicionales importantes, "
                    + "cuantificados y justificados.");
    mapa.put("texto1_XIV",
            "Se trate de los servicios prestados por una persona fsica a que se refiere la fraccin "
                    + "VII del artculo 3 de esta Ley, siempre que stos sean realizados por ella misma sin "
                    + "requerir de la utilizacin de ms de un especialista o tcnico.");
    mapa.put("texto1_XV",
            "Se trate de servicios de mantenimiento de bienes en los que no sea posible precisar "
                    + "su alcance, establecer las cantidades de trabajo o determinar las especificaciones "
                    + "correspondientes.");
    mapa.put("texto1_XVII",
            "Se trate de equipos especializados, sustancias y materiales de origen qumico, fsico "
                    + "qumico o bioqumico para ser utilizadas en actividades experimentales requeridas "
                    + "en proyectos de investigacin cientfica y desarrollo tecnolgico, siempre que dichos "
                    + "proyectos se encuentren autorizados por quien determine el titular de la dependencia "
                    + "o el rgano de gobierno de la entidad.");
    mapa.put("plazo_0", "El plazo en que se requiere el suministro de los " + justi.getBienServicioTxt()
            + ", corresponde al periodo del " + justi.getFechaInicio().getDayOfMonth() + " de "
            + justi.getFechaInicio().getMonth().getDisplayName(TextStyle.FULL, new Locale("es", "ES")) + " de "
            + justi.getFechaInicio().getYear() + " y hasta el " + justi.getFechaTermino().getDayOfMonth()
            + " de " + justi.getFechaTermino().getMonth().getDisplayName(TextStyle.FULL, new Locale("es", "ES"))
            + " de " + justi.getFechaTermino().getYear() + ". Las condiciones en las que se "
            + "entregarn los " + justi.getBienServicioTxt() + " son las siguientes:\n\n "
            + justi.getCondicionesPago());
    mapa.put("plazo_1", "La fecha en que se requiere el suministro de los " + justi.getBienServicioTxt()
            + ", corresponde al da " + justi.getFechaTermino().getDayOfMonth() + " de "
            + justi.getFechaTermino().getMonth().getDisplayName(TextStyle.FULL, new Locale("es", "ES")) + " de "
            + justi.getFechaTermino().getYear() + ". Las condiciones en las que se " + "entregarn los "
            + justi.getBienServicioTxt() + " son las siguientes:\n\n " + justi.getCondicionesPago());
    mapa.put("plazo_2",
            "El plazo en que se requiere el suministro de los " + justi.getBienServicioTxt() + ", "
                    + diasCorresponde + " despus de la elaboracin de este documento."
                    + " Las condiciones en las que se " + "entregarn los " + justi.getBienServicioTxt()
                    + " son las siguientes:\n\n " + justi.getCondicionesPago());
    mapa.put("nota_1",
            "Asimismo se hace constar mediante el sello y firma del responsable del rea de "
                    + "Almacn, la No Existencia de Bienes o Nivel de Inventario que demuestra que se "
                    + "cumpli con lo establecido en el artculo 27 del RLAASP.");
    mapa.put("transparencia_unico",
            "Para la integracin del procedimiento de contratacin por adjudicacin directa, los servidores "
                    + "pblicos de las reas requirentes han tenido acceso de manera oportuna, clara y completa de "
                    + "las caractersticas requeridas de los " + justi.getBienServicioTxt()
                    + " con el fin de demostrar que es " + "el nico proveedor que proporciona los "
                    + justi.getBienServicioTxt() + " que se pretenden contratar, en "
                    + "el entendido que para garantizar la transparencia del procedimiento de contratacin, la "
                    + "informacin respectiva ser incorporada al Sistema de Compras Gubernamentales "
                    + "(CompraNet), en los trminos de las disposiciones legales aplicables, "
                    + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                    + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                    + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                    + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                    + "de 2012.");
    mapa.put("transparencia_no_unico",
            "Todas las personas que han presentado cotizacin para la integracin del procedimiento de "
                    + "contratacin por adjudicacin directa, han tenido acceso de manera oportuna, clara y completa "
                    + "de las caractersticas requeridas de los " + justi.getBienServicioTxt()
                    + ", en el entendido que para "
                    + "garantizar la transparencia del procedimiento de contratacin, la informacin respectiva ser "
                    + "incorporada al Sistema de Compras Gubernamentales (CompraNet), en los trminos de las "
                    + "disposiciones legales aplicables. "
                    + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                    + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                    + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                    + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                    + "de 2012.");

    // </editor-fold>
    StreamingOutput streamingOutput = new StreamingOutput() {
        public void write(OutputStream outputStream) throws IOException, WebApplicationException {

            try {
                String masIva = "";
                if (justi.getIva() != 0) {
                    masIva = " ms IVA";
                }
                String datosBanco = "";
                if (justi.getDatosBanco() != null) {
                    datosBanco = ", datos bancarios: " + justi.getDatosBanco();
                }

                //Create Document instance.
                Document document = new Document();
                PdfWriter.getInstance(document, outputStream);

                document.addAuthor("Generador adquisiciones | " + justi.getEmpleado().getCuentaCimav());
                String fileName1 = (justi.getRequisicion() + "-" + justi.getEmpleado().getCuentaCimav())
                        .replace(" ", "").replace(",", "");
                document.addTitle("Justificacin: " + fileName1);
                document.addSubject("Justificacin de Requisicin");

                document.open();

                Paragraph parrafo = new Paragraph("Centro de Investigacin en Materiales Avanzados S. C.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "JUSTIFICACIN PARA ACREDITAR Y FUNDAR PROCEDIMIENTOS DE "
                                + "CONTRATACIN POR ADJUDICACIN DIRECTA, COMO EXCEPCIN AL DE "
                                + "LICITACIN PBLICA EN EL SUPUESTO DEL ARTICULO 41 FRACCION "
                                + justi.getRomano() + " DE LA "
                                + "LEY DE ADQUISICIONES, ARRENDAMIENTOS Y SERVICIOS DEL SECTOR " + "PBLICO.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph("COMIT DE ADQUISICIONES, ARRENDAMIENTOS Y SERVICIOS");
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                parrafo.setIndentationLeft(80);
                parrafo.setIndentationRight(80);
                document.add(parrafo);

                parrafo = new Paragraph("P R E S E N T E:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setIndentationLeft(30);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph("Oficio nmero: ",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setIndentationLeft(300);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED_ALL);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);

                Chunk frase = new Chunk(justi.getRequisicion() + "\n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "Asunto: Se emite justificacin por la que se "
                                + "acredita y funda la contratacin por adjudicacin directa que se indica.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(
                        "En cumplimiento a lo establecido en el segundo prrafo del artculo 40 de la Ley de "
                                + "Adquisiciones, Arrendamientos y Servicios del Sector Pblico, as como en el artculo 71 del "
                                + "Reglamento de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico, y con el "
                                + "carcter de Titular del ?rea Requirente, por este conducto hago constar el acreditamiento del o "
                                + "de los criterios, razones, fundamentos y motivos para no llevar a cabo el procedimiento de "
                                + "licitacin pblica y celebrar la contratacin a travs del procedimiento de adjudicacin directa en "
                                + "los trminos establecidos en el artculo 41 Fraccin " + justi.getRomano()
                                + " de la Ley de Adquisiciones, "
                                + "Arrendamientos y Servicios del Sector Pblico",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.add(frase);

                /*
                frase = new Chunk("Las dependencias y "
                    + "entidades, bajo su responsabilidad, podrn contratar adquisiciones, arrendamientos y "
                    + "servicios, sin sujetarse al procedimiento de licitacin pblica, a travs de los "
                    + "procedimientos de invitacin a cuando menos tres personas o de adjudicacin directa, "
                    + "cuando:\n" + mapa.get("texto1_" + justi.getRomano()),
                    new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.add(frase); */
                document.add(parrafo);

                parrafo = new Paragraph("Para tal efecto presento la siguiente informacin:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(60);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph("I.- DESCRIPCIN DE LOS " + justi.getBienServicioTxt().toUpperCase(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingAfter(10);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "El/Los " + justi.getBienServicioTxt()
                                + " que se pretende contratar, son los siguientes:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                parrafo = new Paragraph(justi.getDescripcion(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setSpacingBefore(20);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "II.- PLAZOS Y CONDICIONES DEL SUMINISTRO DE LOS "
                                + justi.getBienServicioTxt().toUpperCase(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph(mapa.get("plazo_" + justi.getPlazo()),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setSpacingBefore(20);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                parrafo = new Paragraph("III.- RESULTADO DE LA INVESTIGACIN DE MERCADO",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "La Investigacin de Mercado fue realizada en los trminos de los artculos 28, 29 y 30 del "
                                + "Reglamento de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico, en "
                                + "forma conjunta por el ?rea Requirente y el ?rea Contratante, en la cual se verific previo al "
                                + "inicio del procedimiento de contratacin, la existencia de oferta, en la cantidad, calidad y "
                                + "oportunidad requeridas; la existencia de proveedores a nivel nacional o internacional con "
                                + "posibilidad de cumplir con las necesidades de la contratacin, conocer el precio prevaleciente al "
                                + "momento de llevar a cabo la Investigacin de mercado as como en la informacin disponible "
                                + "en el Sistema informtico denominado COMPRANET:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setSpacingBefore(20);
                parrafo.setSpacingAfter(20);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                PdfPTable table = new PdfPTable(2); // 3 columns.

                table.setWidths(new int[] { 100, 50 });

                if (justi.getEsUnico()) {

                    PdfPCell cell1 = new PdfPCell(
                            new Paragraph("PROVEEDOR", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    PdfPCell cell2 = new PdfPCell(new Paragraph("IMPORTE SIN IVA",
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    cell1.setBorder(PdfPCell.NO_BORDER);
                    cell2.setBorder(PdfPCell.NO_BORDER);
                    cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(cell1);
                    table.addCell(cell2);

                    cell1 = new PdfPCell(new Paragraph(justi.getProveedorUno().toUpperCase(),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getMontoUno(), justi),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell1.setBorder(PdfPCell.NO_BORDER);
                    cell2.setBorder(PdfPCell.NO_BORDER);
                    cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(cell1);
                    table.addCell(cell2);
                    document.add(table);

                    /* Si es nico, no lleva motivo de seleccin
                    parrafo = new Paragraph(justi.getMotivoSeleccion().toUpperCase(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                    parrafo.setSpacingBefore(20);
                    parrafo.setLeading(15);
                    parrafo.setIndentationLeft(30);
                    document.add(parrafo);
                    */

                    parrafo = new Paragraph(
                            "Concluyendo que en conjunto es la nica oferta en cuanto a obtener las mejores condiciones, calidad, "
                                    + "precio, oportunidad y financiamiento, por ser el nico proveedor que proporcione los "
                                    + justi.getBienServicioTxt() + " que se pretende contratar la de "
                                    + justi.getProveedorUno().toUpperCase() + ". La referida "
                                    + "Investigacin de Mercado se acompaa a la presente justificacin para determinar que el "
                                    + "procedimiento de contratacin por adjudicacin directa es el idneo.",
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                    parrafo.setSpacingBefore(20);
                    parrafo.setLeading(15);
                    parrafo.setIndentationLeft(30);
                    document.add(parrafo);

                } else {
                    PdfPCell cell1 = new PdfPCell(
                            new Paragraph("PROVEEDOR", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    PdfPCell cell2 = new PdfPCell(new Paragraph("IMPORTE SIN IVA",
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    cell1.setBorder(PdfPCell.NO_BORDER);
                    cell2.setBorder(PdfPCell.NO_BORDER);
                    cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(cell1);
                    table.addCell(cell2);

                    cell1 = new PdfPCell(new Paragraph(justi.getProveedorUno().toUpperCase(),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getMontoUno(), justi),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                    cell1.setBorder(PdfPCell.NO_BORDER);
                    cell2.setBorder(PdfPCell.NO_BORDER);
                    cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(cell1);
                    table.addCell(cell2);

                    cell1 = new PdfPCell(new Paragraph(justi.getProveedorDos().toUpperCase(),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getMontoDos(), justi),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell1.setBorder(PdfPCell.NO_BORDER);
                    cell2.setBorder(PdfPCell.NO_BORDER);
                    cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(cell1);
                    table.addCell(cell2);

                    if (justi.getProveedorTres() != null && justi.getProveedorTres().trim().length() > 0) {
                        cell1 = new PdfPCell(new Paragraph(justi.getProveedorTres().toUpperCase(),
                                new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                        cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getMontoTres(), justi),
                                new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        cell1.setBorder(PdfPCell.NO_BORDER);
                        cell2.setBorder(PdfPCell.NO_BORDER);
                        table.addCell(cell1);
                        table.addCell(cell2);
                    }

                    document.add(table);

                    parrafo = new Paragraph("Motivo de la seleccin: " + justi.getMotivoSeleccion(),
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                    parrafo.setIndentationLeft(30);
                    document.add(parrafo);

                    parrafo = new Paragraph(
                            "Siendo la oferta que en conjunto presenta las mejores condiciones en cuanto a calidad, precio, oportunidad  "
                                    + "y financiamiento, la de " + justi.getProveedorUno().toUpperCase() + ". "
                                    + "La referida Investigacin de Mercado se acompaa a la presente justificacin para determinar  "
                                    + "que el procedimiento de contratacin por adjudicacin directa es el idneo.",
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setSpacingBefore(20);
                    parrafo.setLeading(15);
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                    parrafo.setIndentationLeft(30);
                    document.add(parrafo);
                }

                parrafo = new Paragraph("IV.- PROCEDIMIENTO DE CONTRATACIN PROPUESTO",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(
                        "El procedimiento de contratacin propuesto es el de adjudicacin directa, en virtud de que en el "
                                + "presente caso la adjudicacin se llevara a cabo conforme la fraccin "
                                + justi.getRomano() + " del artculo 41 el cual "
                                + "menciona que este tipo de adjudicacin se puede llevar a cabo siempre y cuando: \n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.add(frase);

                frase = new Chunk(mapa.get("texto1_" + justi.getRomano()),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.add(frase);

                frase = new Chunk(" Actualizndose el supuesto de excepcin a la licitacin pblica "
                        + "establecido en la fraccin " + justi.getRomano()
                        + " del artculo 41 de la Ley de Adquisiciones, Arrendamientos y "
                        + "Servicios del Sector Pblico, en relacin con lo establecido en el artculo 72 de su Reglamento.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("IV.1.     MOTIVACIN Y FUNDAMENTACIN LEGAL:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingBefore(20);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(60);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk("A)", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);

                frase = new Chunk("  MOTIVOS: ", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);

                frase = new Chunk("La contratacin de los " + justi.getBienServicioTxt()
                        + " objeto de la presente justificacin "
                        + "es necesaria para satisfacer los requerimientos del proyecto identificado por: "
                        + justi.getProyecto() + ".  " + justi.getRazonCompra() + "." + " \nPor lo anterior, la "
                        + "contratacin propuesta se adeca al supuesto de excepcin establecido en la Ley "
                        + "de Adquisiciones, Arrendamientos y Servicios del Sector Pblico en su artculo 41, "
                        + "fraccin " + justi.getRomano()
                        + "; adems de que se renen los requisitos previstos en el artculo 72 del "
                        + "Reglamento de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector "
                        + "Pblico, tal y como se desprende de la informacin presentada en esta justificacin, "
                        + "as como de la Investigacin de Mercado; "
                        + "por lo que resulta procedente la contratacin bajo el procedimiento de adjudicacin "
                        + "directa previsto en el artculo 26, fraccin III de la Ley antes mencionada.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(60);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk("B)", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);

                frase = new Chunk("  FUNDAMENTOS: ", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);

                frase = new Chunk("La contratacin se encuentra debidamente fundada en el artculo "
                        + "134 de la Constitucin Poltica de los Estados Unidos Mexicanos; en los artculos 26 "
                        + "fraccin III, 40 y 41 fraccin " + justi.getRomano()
                        + " de la Ley de Adquisiciones, Arrendamientos y "
                        + "Servicios del Sector Pblico; as como en los artculos 71 y 72 del Reglamento de la "
                        + "Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("V.- MONTO ESTIMADO Y FORMA DE PAGO PROPUESTO:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph("V.1.      MONTO ESTIMADO:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingBefore(20);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                DecimalFormat decimalFormat = new DecimalFormat("0.00");
                parrafo = new Paragraph("El monto estimado de la contratacin es la cantidad de "
                        + montoFormatComas(justi.getSubTotal(), justi) + " ("
                        + new Numero_a_Letra().Convertir(decimalFormat.format(justi.getSubTotal()), true) + " "
                        + /*codigoDivisa(justi)*/ justi.getMoneda().getCode() + ")" + masIva + ", mismo que "
                        + "result el ms conveniente de acuerdo con la Investigacin de Mercado"
                        + ", mediante la cual se verific previo al inicio del procedimiento "
                        + "de contratacin, la existencia de oferta de los " + justi.getBienServicioTxt()
                        + " en la cantidad, "
                        + "calidad y oportunidad requeridos en los trminos del artculo 28 del Reglamento de la Ley de "
                        + "Adquisiciones, Arrendamientos y Servicios del Sector Pblico.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                table = new PdfPTable(3); // 3 columns.

                table.setWidths(new int[] { 30, 10, 10 });
                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("Subtotal:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getSubTotal(), justi),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell0 = new PdfPCell(
                        new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.NO_BORDER);
                table.addCell(cell0);
                cell1.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cell1);
                table.addCell(cell2);
                cell1 = new PdfPCell(
                        new Paragraph("Iva:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getIva(), justi),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.NO_BORDER);
                table.addCell(cell0);
                cell1.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cell1);
                table.addCell(cell2);
                cell1 = new PdfPCell(
                        new Paragraph("Total:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell2 = new PdfPCell(new Paragraph(montoFormatComas(justi.getImporte(), justi),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell0 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.NO_BORDER);
                table.addCell(cell0);
                cell1.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cell1);
                table.addCell(cell2);
                document.add(table);

                parrafo = new Paragraph("V.1.      FORMA DE PAGO PROPUESTA:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setSpacingBefore(20);
                parrafo.setIndentationLeft(30);
                document.add(parrafo);

                parrafo = new Paragraph("El monto total ser pagado en " + justi.getNumPagos() + " pago/s de "
                        + montoFormatComas(justi.getSubTotal() / justi.getNumPagos(), justi) + " ("
                        + new Numero_a_Letra().Convertir(
                                decimalFormat.format(justi.getSubTotal() / (justi.getNumPagos())).toString(),
                                true)
                        + " " + /*codigoDivisa(justi)*/ justi.getMoneda().getCode() + ")" + masIva
                        + ". Los pagos se realizarn previa verificacin de la entrega y calidad de los "
                        + justi.getBienServicioTxt()
                        + " as como previo envo en formatos .pdf y .xml del Comprobante Fiscal "
                        + "Digital por Internet (CFDI) correspondiente que rena los requisitos fiscales respectivos. Los "
                        + "pagos se efectuarn mediante " + justi.getFormaPago(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph("VI.- PERSONA PROPUESTA PARA LA ADJUDICACIN DIRECTA:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "Por lo anteriormente expuesto y fundado, se propone a "
                                + justi.getProveedorUno().toUpperCase() + ", con domicilio ubicado en "
                                + justi.getDomicilio() + ", Registro Federal de Contribuyentes: "
                                + justi.getRfc() + ", correo electrnico: " + justi.getCorreo()
                                + " y nmero telefnico " + justi.getTelefono() + datosBanco,
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "VII.- ACREDITAMIENTO DEL O LOS CRITERIOS EN LOS QUE SE FUNDA Y MOTIVA LA "
                                + "SELECCIN DEL PROCEDIMIENTO DE EXCEPCIN A LA LICITACIN PBLICA:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "El procedimiento de contratacin por adjudicacin directa es el idneo, al actualizarse el "
                                + "supuesto de excepcin al procedimiento de licitacin pblica previsto en el artculo 41, fraccin "
                                + justi.getRomano()
                                + " de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico, aunado a que se "
                                + "corrobor la capacidad y experiencia de la persona propuesta, quien por ser proveedor nico "
                                + "present las mejores condiciones en cuanto a precio, calidad, financiamiento, oportunidad y "
                                + "dems circunstancias pertinentes a efecto de asegurar a esta Entidad las mejores condiciones "
                                + "para su contratacin, tal y como se acredita con la informacin presentada en esta justificacin, "
                                + "as como con la Investigacin de Mercado.\n\n"
                                + "El acreditamiento del o los criterios en los que se funda la excepcin de licitacin pblica, son "
                                + "los siguientes:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(" -  Economa\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "Con la Investigacin de Mercado se establecieron precios y dems condiciones de calidad, "
                                + "financiamiento y oportunidad, respecto de los " + justi.getBienServicioTxt()
                                + " requeridos, con lo cual "
                                + "se asegura cumplir con los principios del artculo 134 de la Constitucin Poltica de los Estados "
                                + "Unidos Mexicanos y de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico, "
                                + "en cuanto a precio, calidad, financiamiento, oportunidad y dems circunstancias pertinentes, por "
                                + "lo que el procedimiento de adjudicacin directa permite en contraposicin al procedimiento de "
                                + "licitacin pblica, obtener con mayor oportunidad los "
                                + justi.getBienServicioTxt() + " requeridos al "
                                + "menor costo econmico para el CIMAV, S.C. segn lo detallado en la investigacin de mercado "
                                + "que se realiz, generando ahorro de recursos por estar proponiendo la adjudicacin al "
                                + "proveedor nico cuya propuesta se considera aceptable en cuanto a su solvencia. "
                                + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                                + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                                + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                                + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                                + "de 2012.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(" -  Eficacia\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "Con el procedimiento de contratacin por adjudicacin directa, se lograr obtener con "
                                + "oportunidad los " + justi.getBienServicioTxt()
                                + " atendiendo a las caractersticas requeridas en "
                                + "contraposicin con el procedimiento de licitacin pblica, dado que se reducen tiempos y se "
                                + "generan economas; aunado a que la persona propuesta cuenta con experiencia y capacidad "
                                + "para satisfacer las necesidades requeridas, adems de que es el nico que ofrece las mejores "
                                + "condiciones disponibles en cuanto a precio, calidad y oportunidad, con lo que se lograra el "
                                + "cumplimiento de los objetivos y resultados deseados en el tiempo requerido, situacin que se "
                                + "puede demostrar en base a la investigacin de mercado. "
                                + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                                + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                                + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                                + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                                + "de 2012.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(" -  Eficiencia\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "Con el procedimiento de adjudicacin directa, a diferencia del procedimiento de licitacin "
                                + "pblica, se logra el uso racional de recursos con los que cuenta la Entidad para realizar la "
                                + "contratacin, obteniendo las mejores condiciones de precio, calidad y oportunidad, evitando la "
                                + "prdida de tiempo y recursos al Estado, lo cual se demuestra con la investigacin de mercado "
                                + "que se realiz, quedando evidencia de su resultado ya que los recursos disponibles con los que "
                                + "cuenta el CIMAV se aplican conforme a los lineamientos de racionalidad y austeridad "
                                + "presupuestaria. "
                                + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                                + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                                + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                                + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                                + "de 2012.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(" -  Imparcialidad\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "El tipo de adjudicacin que se propone, se llev a cabo sin prejuicios ni situaciones que "
                                + "pudieran afectar la imparcialidad, y sin que medie algn inters personal de los servidores "
                                + "pblicos involucrados en la contratacin o de cualquier otra ndole que pudiera otorgar "
                                + "condiciones ventajosas a alguna persona, en relacin con los dems ni limitar la libre "
                                + "participacin, esto debido a que es proveedor nico, dicha situacin queda demostrada "
                                + "conforme al resultado que se da con base a la investigacin de mercado. "
                                + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                                + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                                + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                                + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                                + "de 2012.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                frase = new Chunk(" -  Honradez\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.add(frase);
                frase = new Chunk(
                        "La seleccin del procedimiento de adjudicacin directa tiene como nico fin contratar bajo "
                                + "las mejores condiciones los " + justi.getBienServicioTxt()
                                + " requeridos, actuando con rectitud, "
                                + "responsabilidad e integridad y con apego estricto al marco jurdico aplicable, evitando as "
                                + "incurrir en actos de corrupcin y conflictos de inters, ya que por parte de los servidores "
                                + "pblicos que intervinieron en este procedimiento quedo evidenciado que no se ha favorecido a "
                                + "persona alguna interesada en la contratacin ya que en base a la investigacin de mercado "
                                + "queda demostrado que es proveedor nico.\n\n"
                                + "Lo anterior de acuerdo con lo establecido en el numeral 4.2.4 (ADJUDICACIN DIRECTA) y "
                                + "numeral 4.2.4.1.1 (Verificar Acreditamiento de Excepcin) del Acuerdo por el que se modifica el "
                                + "Manual Administrativo de Aplicacin General en Materia de Adquisiciones, Arrendamientos y "
                                + "Servicios del Sector Pblico, publicado en el Diario Oficial de la Federacin el 21 de noviembre "
                                + "de 2012.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.add(frase);
                document.add(parrafo);

                if (justi.getEsUnico()) {
                    parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setSpacingAfter(20);
                    parrafo.setIndentationLeft(30);
                    parrafo.setLeading(15);
                    parrafo.setSpacingBefore(20);
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                    frase = new Chunk(" -  Transparencia\n",
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                    parrafo.add(frase);
                    frase = new Chunk(mapa.get("transparencia_unico"),
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.add(frase);
                    document.add(parrafo);
                } else {
                    parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.setSpacingAfter(20);
                    parrafo.setIndentationLeft(30);
                    parrafo.setLeading(15);
                    parrafo.setSpacingBefore(20);
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);

                    frase = new Chunk(" -  Transparencia\n",
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                    parrafo.add(frase);
                    frase = new Chunk(mapa.get("transparencia_no_unico"),
                            new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                    parrafo.add(frase);
                    document.add(parrafo);
                }

                parrafo = new Paragraph("VIII.- LUGAR Y FECHA DE EMISIN:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph("En la Ciudad de Chihuahua, Estado de Chihuahua a los "
                        + justi.getFechaElaboracion().getDayOfMonth() + " das del mes de "
                        + justi.getFechaElaboracion().getMonth().getDisplayName(TextStyle.FULL,
                                new Locale("es", "ES"))
                        + " de " + justi.getFechaElaboracion().getYear()
                        + ", se emite la presente justificacin para los efectos legales a que haya lugar.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "En cumplimiento a lo establecido en el penltimo prrafo del artculo 71 del Reglamento "
                                + "de la Ley de Adquisiciones, Arrendamientos y Servicios del Sector Pblico, se acompaa a la "
                                + "presente como ANEXO DOS?, la Requisicin o Solicitud de Contratacin (Requisicin) A la "
                                + "cual se deber anexar, mediante sello del departamento de Presupuesto, la Constancia con la "
                                + "que se acredita la existencia de recursos para iniciar el procedimiento de contratacin.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                parrafo.setLeading(15);
                parrafo.setIndentationLeft(30);
                parrafo.setSpacingBefore(20);
                document.add(parrafo);

                if (justi.getEsUnico()) {
                    parrafo = new Paragraph(mapa.get("nota_1"),
                            new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.BOLD));
                    parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                    parrafo.setLeading(15);
                    parrafo.setIndentationLeft(30);
                    parrafo.setSpacingBefore(20);
                    document.add(parrafo);
                }

                parrafo = new Paragraph("ATENTAMENTE", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(60);
                document.add(parrafo);

                parrafo = new Paragraph(
                        justi.getAutoriza().getName() + "\n" + justi.getAutorizaCargo().toUpperCase(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(60);
                document.add(parrafo);

                document.close();
                outputStream.close();

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

        }
    };

    ResponseBuilder response = Response.ok(streamingOutput);
    String fileName = ("inline; filename=" + justi.getRequisicion() + "-" + justi.getEmpleado().getCuentaCimav()
            + ".pdf").replace(" ", "").replace(",", "-");
    response.header("Content-Disposition", fileName);

    return response.build();
}

From source file:cimav.restrh.services.JustificacionREST.java

private Response tablaMercado(Integer id_param) {
    Justificacion justif = (Justificacion) JustificacionREST.this.find(id_param);

    StreamingOutput streamingOutput = new StreamingOutput() {
        public void write(OutputStream outputStream) throws IOException, WebApplicationException {

            try {
                //Create Document instance.
                Document document = new Document();
                PdfWriter.getInstance(document, outputStream);

                document.addAuthor("Generador adquisiciones | " + justif.getEmpleado().getCuentaCimav());
                String fileName1 = (justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav())
                        .replace(" ", "").replace(",", "");
                document.addTitle("Justificacin: " + fileName1);
                document.addSubject("Justificacin de Requisicin");

                document.open();// w w w .jav a2 s  .  c o  m

                //Titulo del documento
                Paragraph parrafo = new Paragraph("Centro de Investigacin en Materiales Avanzados S. C.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingAfter(20);
                document.add(parrafo);

                PdfPTable table = new PdfPTable(3); // 3 columns.

                table.setWidths(new int[] { 30, 50, 100 });

                PdfPCell cell0 = new PdfPCell(
                        new Paragraph("Fecha:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell1 = new PdfPCell(new Paragraph(
                        justif.getFechaInicio().getDayOfMonth() + " de "
                                + justif.getFechaInicio().getMonth().getDisplayName(TextStyle.FULL,
                                        new Locale("es", "ES"))
                                + " de " + justif.getFechaInicio().getYear(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("No. de Requisicin:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph(justif.getRequisicion(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("Procedimiento:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph("Adjudicacin Directa",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("Origen de los bienes:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph(justif.esNacional(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                document.add(table);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                table = new PdfPTable(5);// 5 columns.
                table.setWidthPercentage(90); //table size %

                table.setWidths(new int[] { 'a', 'a', 'a', 'a', 'a' });

                cell0 = new PdfPCell(
                        new Paragraph("PARTIDA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell1 = new PdfPCell(
                        new Paragraph("DESCIPCIMAV", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell2 = new PdfPCell(
                        new Paragraph("PROVEEDOR No. 1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("PROVEEDOR No.2", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                PdfPCell cell4 = new PdfPCell(
                        new Paragraph("PROVEEDOR No.3", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell0.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                cell0 = new PdfPCell(
                        new Paragraph("Partida #1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell1 = new PdfPCell(new Paragraph(justif.getDescripcion(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell0.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell0.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell0.setRowspan(2);
                cell1.setRowspan(2);
                table.addCell(cell0);
                table.addCell(cell1);

                cell2 = new PdfPCell(new Paragraph(justif.getProveedorUno(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell3 = new PdfPCell(new Paragraph(justif.getProveedorDos(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell4 = new PdfPCell(new Paragraph(justif.getProveedorTres(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoUno(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoDos() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                } else {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                }
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);
                document.add(table);

                parrafo = new Paragraph(
                        "Tal como lo establece el artculo 29 " + "del Reglamento de la Ley de Adquisiciones, "
                                + "Arrendamientos y Servicios del Sector Pblico,"
                                + " la investigacin de mercado arrojo los siguientes resultados:\n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(10);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "Fraccin I, determinamos la existencia de oferta de los bienes requeridos.\n"
                                + "Fraccin II, verificamos existencias de los mismos con los proveedores que nos proporcionaron cotizacin formal.\n"
                                + "Fraccin III, conocimos los precios que prevalecan en el mercado nacional.\n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));

                parrafo.setIndentationLeft(50);
                parrafo.setLeading(15);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "A travs de la investigacin de mercado realizada, "
                                + "concluimos que la mejor opcin de compra es la oferta del proveedor" + " "
                                + justif.getProveedorUno(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(10);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                document.close();
                outputStream.close();

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

        }
    };
    ResponseBuilder response = Response.ok(streamingOutput);
    String fileName = ("inline; filename=" + justif.getRequisicion() + "-"
            + justif.getEmpleado().getCuentaCimav() + ".pdf").replace(" ", "").replace(",", "-");
    response.header("Content-Disposition", fileName);

    return response.build();
}

From source file:cis_690_report.DynamicReporter.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File3 = chooser.getSelectedFile().getAbsolutePath();
        }/*  w  w w .  j a v a 2s.c  o m*/

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

        }

        String line = "";

        bull1 = new String[number_of_rows - 1][];
        int k = 0;
        BufferedReader br3 = null;
        try {
            br3 = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br3.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                if (k != 0) {
                    System.out.println(Bull.length);
                    bull1[k - 1] = new String[Bull.length];
                    for (int j = 0; j < Bull.length; j++) {

                        bull1[k - 1][j] = Bull[j];

                    }
                }
                k++;
            }
        } catch (IOException ex) {
        }
        Document doc = new Document();
        PdfWriter docWriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {

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

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

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

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

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

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

            String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                    + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                    + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

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

            //specify column widths
            int temp = dlm2.size();

            float[] columnWidths = new float[temp];
            for (int x = 0; x < columnWidths.length; x++) {
                columnWidths[x] = 2f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            DynamicReporter re;
            re = new DynamicReporter();

            for (int i = 0; i < dlm2.size(); i++) {
                String[] parts = dlm2.get(i).toString().split(": ");
                String part2 = parts[1];

                re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
            }

            table.setHeaderRows(1);
            //insert an empty row

            //create section heading by cell merging

            //just some random data to fill 
            for (int x = 0; x < dlm3.size(); x++) {
                String str = dlm3.get(x).toString();

                System.out.println(str);
                String[] parts = str.split(":");

                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                for (int i = 0; i < dlm2.getSize(); i++)
                    for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                        String str1 = dlm2.get(i).toString();
                        String[] p1 = str1.split(": ");
                        String p2 = p1[0];
                        if (p2.equals(header[j])) {
                            re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                        }
                    }
                // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
            }

            doc.add(table);
            if (jCheckBox2.isSelected()) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                for (int i = 0; i < dlm3.size(); i++) {

                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }

                }
                JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                        "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

                if (dlm3.size() > 12) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);
            }
            if (jCheckBox1.isSelected()) {

                for (int i = 0; i < dlm3.size(); i++) {
                    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }
                    JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                            "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                    if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                        doc.newPage();
                    }
                    PdfContentByte contentByte = docWriter.getDirectContent();
                    PdfTemplate template = contentByte.createTemplate(325, 250);
                    PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                    chart.draw(graphics2d, rectangle2d);

                    graphics2d.dispose();
                    contentByte.addTemplate(template, 0, 0);

                    doc.newPage();
                }
            }

        } catch (DocumentException dex) {
            dex.printStackTrace();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (doc != null) {
                //close the document
                doc.close();
            }
            if (docWriter != null) {
                //close the writer
                docWriter.close();
            }

        }
    }
    // TODO add your handling code here:

}

From source file:cis_690_report.DynamicReporter.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed

    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();//from  www .  j  a v  a 2s  . c om
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/reporter.pdf";

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

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

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

        //file path

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

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

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

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

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

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

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

        //specify column widths
        int temp = dlm2.size();

        float[] columnWidths = new float[temp];
        for (int x = 0; x < columnWidths.length; x++) {
            columnWidths[x] = 2f;
        }

        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(90f);
        DynamicReporter re;
        re = new DynamicReporter();

        for (int i = 0; i < dlm2.size(); i++) {
            String[] parts = dlm2.get(i).toString().split(": ");
            String part2 = parts[1];

            re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
        }

        table.setHeaderRows(1);
        //insert an empty row

        //create section heading by cell merging

        //just some random data to fill 

        for (int x = 0; x < dlm3.size(); x++) {
            String str = dlm3.get(x).toString();

            System.out.println(str);
            String[] parts = str.split(":");

            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            for (int i = 0; i < dlm2.getSize(); i++)
                for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                    String str1 = dlm2.get(i).toString();
                    String[] p1 = str1.split(": ");
                    String p2 = p1[0];
                    if (p2.equals(header[j])) {
                        re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                    }
                }
            // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
        }

        doc.add(table);
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);
}

From source file:cis_690_report.DynamicReporter.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();/*from  w  w  w.j av a  2 s.c om*/
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/reporter.pdf";

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

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

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

        //file path

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

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

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

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

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

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

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

        //specify column widths
        int temp = dlm2.size();

        float[] columnWidths = new float[temp];
        for (int x = 0; x < columnWidths.length; x++) {
            columnWidths[x] = 2f;
        }

        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(90f);
        DynamicReporter re;
        re = new DynamicReporter();

        for (int i = 0; i < dlm2.size(); i++) {
            String[] parts = dlm2.get(i).toString().split(": ");
            String part2 = parts[1];

            re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
        }

        table.setHeaderRows(1);
        //insert an empty row

        //create section heading by cell merging

        //just some random data to fill 

        for (int x = 0; x < dlm3.size(); x++) {
            String str = dlm3.get(x).toString();

            System.out.println(str);
            String[] parts = str.split(":");

            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            for (int i = 0; i < dlm2.getSize(); i++)
                for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                    String str1 = dlm2.get(i).toString();
                    String[] p1 = str1.split(": ");
                    String p2 = p1[0];
                    if (p2.equals(header[j])) {
                        re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                    }
                }
            // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
        }

        doc.add(table);
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);
}

From source file:cis_690_report.Reporter.java

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

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

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

                // use comma as separator
                number_of_rows1++;
            }

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

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

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

        DecimalFormat df = new DecimalFormat("0.00");

        try {

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

            //file path

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

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

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

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

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

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

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

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

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

            table.setHeaderRows(1);

            //insert an empty row

            //create section heading by cell merging

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

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

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

From source file:clases.Funciones.java

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

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

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

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

    try {
        documento.open();

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

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

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

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

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

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

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

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

        tabla.setWidthPercentage(100);

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

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

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

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

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

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

From source file:clases.Funciones.java

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

    int Folio = GenerateFolioService();

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

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

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

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

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

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

        try {
            documento.open();

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

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

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

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

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

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

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

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

            tabla.setWidthPercentage(100);

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

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

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

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

            //Tabla_Vehiculos
            String Vehiculos_header = "VEHICULO";

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

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

            tabla_vehiculos.setWidthPercentage(100);

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

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

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

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

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

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

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

            tabla_PRODUCTS.setWidthPercentage(100);

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

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

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

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

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

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

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

From source file:clases.Funciones.java

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

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

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

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

    int Folio = id;

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

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

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

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

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

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

    try {
        documento.open();

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

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

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

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

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

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

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

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

        tabla.setWidthPercentage(100);

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

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

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

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

        //Tabla_Vehiculos
        String Vehiculos_header = "VEHICULO";

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

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

        tabla_vehiculos.setWidthPercentage(100);

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

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

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

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

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

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

        JTable t_productos = new JTable();

        Table_LoadProductsServicio(t_productos);

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

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

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

        tabla_PRODUCTS.setWidthPercentage(100);

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

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

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

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

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

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

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

From source file:clases.Funciones.java

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

    try {//from w  w  w.  jav  a  2 s  .c o  m
        coneccion = new Conexion();
        try (ResultSet rs = coneccion.Consulta(
                "SELECT id, id_cliente, id_vehiculo, s_solicitado, s_realizado, productos, total, p_urgente FROM services where id = "
                        + id_service + " ")) {

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

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

    int Folio = id;

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

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

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

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

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

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

    try {
        documento.open();

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

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

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

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

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

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

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

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

        tabla.setWidthPercentage(100);

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

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

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

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

        //Tabla_Vehiculos
        String Vehiculos_header = "VEHICULO";

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

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

        tabla_vehiculos.setWidthPercentage(100);

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

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

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

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

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

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

        JTable t_productos = new JTable();

        Table_LoadProductsServicio(t_productos);

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

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

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

        tabla_PRODUCTS.setWidthPercentage(100);

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

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

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

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

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

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

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