Example usage for com.itextpdf.text.pdf PdfPCell setBackgroundColor

List of usage examples for com.itextpdf.text.pdf PdfPCell setBackgroundColor

Introduction

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

Prototype


public void setBackgroundColor(final BaseColor backgroundColor) 

Source Link

Document

Sets the backgroundcolor of the rectangle.

Usage

From source file:eeebees.PDFGen.java

public static void main(String[] args) {

    try {/*from  w w  w  .ja  va2s  .  co  m*/

        OutputStream file = new FileOutputStream(new File("D:\\PDF_Java4s.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        //Inserting Image in PDF
        //Image image = Image.getInstance ("src/pdf/java4s.png");
        //image.scaleAbsolute(120f, 60f);//image width,height    

        //Inserting Table in PDF
        PdfPTable table = new PdfPTable(3);

        PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com"));

        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(10.0f);
        cell.setBackgroundColor(new BaseColor(140, 221, 8));

        table.addCell(cell);

        table.addCell("Name");
        table.addCell("Address");
        table.addCell("Country");
        table.addCell("Java4s");
        table.addCell("NC");
        table.addCell("United States");
        table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS
        table.setSpacingAfter(30.0f); // Space After table starts, like margin-Bottom in CSS                                          

        //Inserting List in PDF
        List list = new List(true, 30);
        list.add(new ListItem("Java4s"));
        list.add(new ListItem("Php4s"));
        list.add(new ListItem("Some Thing..."));

        //Text formating in PDF
        Chunk chunk = new Chunk("Welecome To Java4s Programming Blog...");
        chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between
        Chunk chunk1 = new Chunk("Php4s.com");
        chunk1.setUnderline(+4f, -8f);
        chunk1.setBackground(new BaseColor(17, 46, 193));

        //Now Insert Every Thing Into PDF Document
        document.open();//PDF document opened........                   

        //document.add(image);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)

        document.add(new Paragraph("Dear Java4s.com"));
        document.add(new Paragraph("Document Generated On - " + new Date().toString()));

        document.add(table);

        document.add(chunk);
        document.add(chunk1);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)                                

        document.newPage(); //Opened new page
        document.add(list); //In the new page we are going to add list

        document.close();

        file.close();

        System.out.println("Pdf created successfully..");

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

From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(5);
    table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 });
    table.setLockedWidth(true);//from  w  ww. j  a  v  a2 s.  com

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<VentaLinea> listVenta = getVenta().getVenta_lineas();

    for (VentaLinea vlinea : listVenta) {
        if (vlinea.getTipo() == 1) {
            if (vlinea.getProducto().getIva() != null) {
                iva2 = vlinea.getProducto().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        } else if (vlinea.getTipo() == 2) {
            if (vlinea.getServicio().getIva() != null) {
                iva2 = vlinea.getServicio().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        }

        //Para hacer el calculo nos vamos a quedar con el IVA mayor
        if (iva < iva2) {
            iva = iva2;
        }

        cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

        String descripcion = vlinea.getDescripcion();
        if (descripcion == null || "null".equals(descripcion)) {
            table.addCell(new PdfPCell(new Phrase(" ", small)));
            //                System.out.println("null:" + descripcion);
        } else {
            table.addCell(new PdfPCell(new Phrase(descripcion, small)));
            //                System.out.println("!null:" + descripcion);
        }

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCostesinIva()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    //        float costetotal = (float) (venta.getCoste() * (1+(iva*0.01)));

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getIvas()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCoste()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(6);
    table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 });
    table.setLockedWidth(true);/*from  ww  w .  j av a2  s . c  o m*/

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("FECHA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<Venta> ventas = this.getFactura().getVentas();
    for (Venta venta : ventas) {
        HashSet<VentaLinea> listVenta = venta.getVenta_lineas();

        for (VentaLinea vlinea : listVenta) {
            if (vlinea.getTipo() == 1) {
                if (vlinea.getProducto().getIva() != null) {
                    iva2 = vlinea.getProducto().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            } else if (vlinea.getTipo() == 2) {
                if (vlinea.getServicio().getIva() != null) {
                    iva2 = vlinea.getServicio().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            }

            //Para hacer el calculo nos vamos a quedar con el IVA mayor
            if (iva < iva2) {
                iva = iva2;
            }

            cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            if (vlinea.getTipo() == 2) { //Servicio
                table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                String descripcion = vlinea.getDescripcion();
                if (descripcion == null || "null".equals(descripcion)) {
                    table.addCell(new PdfPCell(new Phrase(" ", small)));
                    //                System.out.println("null:" + descripcion);
                } else {
                    table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                    //                System.out.println("!null:" + descripcion);
                }
            } else if (vlinea.getTipo() == 1) { //Producto
                //Si el producto es Tratamiento
                if (vlinea.getProducto().getFamilia().isTratamiento()) {
                    table.addCell(new PdfPCell(new Phrase("Tratamiento", small)));
                    table.addCell(new PdfPCell(new Phrase("", small)));
                } else {

                    table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                    String descripcion = vlinea.getDescripcion();
                    if (descripcion == null || "null".equals(descripcion)) {
                        table.addCell(new PdfPCell(new Phrase(" ", small)));
                        //                System.out.println("null:" + descripcion);
                    } else {
                        table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                        //                System.out.println("!null:" + descripcion);
                    }
                }
            }
            cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);
        }
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    float costetotal = (float) (factura.getCostetotal());

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:Export.ExportViagemSemanaPdf.java

public static void criarDoc(Date dataInicio, Date dateFim, String user, String nomeFuncinario) {
    Font fontTableCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f);
    Font fontTableTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f);

    Font fontRoadape = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
    Font fontRoadapeP = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f);
    Font fontRoadapeB = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
    Font fontRoadapeBU = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f,
            Font.UNDEFINED);/*from w ww. ja  v a  2  s  .  c o m*/

    Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
            9.5f);
    Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f);
    Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
            Font.UNDERLINE);

    OutputStream outputStraem;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss");
        SimpleDateFormat sdfTitile = new SimpleDateFormat("dd-MM-yyyy");
        Document documento = new Document();
        documento.setPageSize(PageSize.A4.rotate());
        documento.setMargins(10f, 10f, 35f, 20f);

        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Seguro Viagem/");
        ff.mkdirs();

        String Ddata = sdf.format(new Date());

        ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Viagem Semanal " + Ddata + ".pdf");
        String reString = "../Documentos/" + user + "/Seguro Viagem/" + "Export Mapa Viagem Semanal " + Ddata
                + ".pdf";
        outputStraem = new FileOutputStream(ff);

        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        PdfPTable tableDados = new PdfPTable(
                new float[] { 5f, 10.6f, 5f, 5f, 4.6f, 19f, 5.6f, 6f, 10.6f, 9.6f, 7f, 5.5f, 5.5f });
        tableDados.setWidthPercentage(100f);

        BaseColor colorCinza = new BaseColor(129, 138, 145);

        for (int j = 0; j < 13; j++) {
            PdfPCell cellTitileTable = new PdfPCell(new Phrase(titileTable(j), fontTableTitile));
            cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);

            cellTitileTable.setBackgroundColor(colorCinza);
            tableDados.addCell(cellTitileTable);
        }

        dataViagem(dataInicio, dateFim);

        float premiototal = 0;

        for (HashMap<String, Object> data : hasList) {
            tableDados.addCell(new Phrase(toString(data.get(DATA)), fontTableCorpo));
            tableDados.addCell(ExportViagemSemanaPdf
                    .cellEspecial(new PdfPCell(new Phrase(toString(data.get(NUMEROAPOLICE)), fontTableCorpo))));
            tableDados.addCell(
                    new Phrase(ConfigDoc.toFormat(toString(data.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"),
                            fontTableCorpo));
            tableDados.addCell(new Phrase(
                    ConfigDoc.toFormat(toString(data.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), fontTableCorpo));

            premiototal += toFloat(data.get(PREMIO));

            PdfPCell cellRigh = new PdfPCell(
                    new Phrase(ConfigDoc.toMoeda(toFloat(data.get(PREMIO)), ""), fontTableCorpo));
            cellRigh.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            tableDados.addCell(cellRigh);

            tableDados.addCell(new Phrase(toString(data.get(CLIENTE)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(DATANASCIMENTO)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(TELEFONE)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(ENDERECO)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(LOCALNASCIMENTO)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(PAISDESTINO)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(CIDADEDESTINO)), fontTableCorpo));
            tableDados.addCell(new Phrase(toString(data.get(ZONADESTINO)), fontTableCorpo));
        }

        PdfPCell cellTotal = new PdfPCell(ExportViagemSemanaPdf.cellEspecial(new PdfPCell(
                new Phrase("AL AMOUNT..........................................", fontTableTitile))));
        cellTotal.setColspan(4);
        cellTotal.setPadding(1.5f);
        cellTotal.setBackgroundColor(colorCinza);
        tableDados.addCell(cellTotal);

        cellTotal = new PdfPCell(ExportViagemSemanaPdf
                .cellEspecial(new PdfPCell(new Phrase(ConfigDoc.toMoeda(premiototal, ""), fontTableTitile))));
        cellTotal.setPadding(1.5f);
        cellTotal.setBackgroundColor(colorCinza);
        tableDados.addCell(cellTotal);

        cellTotal = new PdfPCell(
                ExportViagemSemanaPdf.cellEspecial(new PdfPCell(new Phrase(" ", fontTableTitile))));
        cellTotal.setColspan(8);
        cellTotal.setPadding(1.5f);
        cellTotal.setBackgroundColor(colorCinza);
        tableDados.addCell(cellTotal);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 15f, 85f });
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);

        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);
        PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN));
        pCellNomeEndereco.setBorder(0);
        PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN));
        pCellCaixaPostal.setBorder(0);
        PdfPCell pCellTeleFax = new PdfPCell(
                new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
        pCellTeleFax.setBorder(0);
        PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN));
        pCellSociedade.setBorder(0);
        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(120f, 85f);
        pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
        pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
        pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
        pTableEmpresaInforImpres1.addCell(pCellTeleFax);
        pTableEmpresaInforImpres1.addCell(pCellSociedade);
        PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
        cellTabela3.setBorder(0);
        pTableEmpresaInforImpres5.addCell(cellTabela3);
        PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
        cellTabela5.setBorder(0);
        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);
        pTableEmpresaPricipal.setWidthPercentage(95);
        pTableEmpresaPricipal.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);

        PdfPTable pTableTitulo = new PdfPTable(1);
        pTableTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pTableTitulo.setWidthPercentage(100);

        PdfPCell cellTitulo = new PdfPCell(new Phrase("RLELATORIO SEMANAL NO. " + "" + "\n"
                + ((dataInicio != null) ? sdfTitile.format(dataInicio) + " - " : "")
                + ((dateFim != null) ? sdfTitile.format(dateFim) : ""), fontCorpoNG));
        cellTitulo.setBorder(0);
        cellTitulo.setPaddingBottom(20f);
        cellTitulo.setPaddingTop(10f);
        cellTitulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableTitulo.addCell(cellTitulo);

        pTableEmpresaPricipal.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPTable pTableRodape = new PdfPTable(new float[] { 50f, 50f });
        pTableRodape.setWidthPercentage(90f);

        PdfPCell cellRodape = new PdfPCell(new Phrase("DEPARTAMENTO FINANCEIRO", fontRoadapeBU));
        cellRodape.setBorder(0);
        cellRodape.setColspan(2);
        cellRodape.setPaddingTop(20f);
        pTableRodape.addCell(cellRodape);

        cellRodape = new PdfPCell(new Phrase("QUEIRA POR FAVOR CONFERIR OS PAGAMENTOS", fontRoadape));
        cellRodape.setColspan(2);
        cellRodape.setBorder(0);
        pTableRodape.addCell(cellRodape);

        cellRodape = new PdfPCell(new Phrase("ELABORADO POR", fontRoadapeB));
        cellRodape.setBorder(0);
        pTableRodape.addCell(cellRodape);
        cellRodape = new PdfPCell(new Phrase("VENFICADO POR", fontRoadapeB));
        cellRodape.setBorder(0);
        cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        pTableRodape.addCell(cellRodape);

        cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape));
        cellRodape.setBorder(0);
        cellRodape.setPaddingTop(30f);
        pTableRodape.addCell(cellRodape);
        cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape));
        cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cellRodape.setBorder(0);
        cellRodape.setPaddingTop(30f);
        pTableRodape.addCell(cellRodape);

        cellRodape = new PdfPCell(new Phrase(nomeFuncinario, fontRoadapeP));
        cellRodape.setColspan(2);
        cellRodape.setBorder(0);
        pTableRodape.addCell(cellRodape);

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableTitulo);
        documento.add(tableDados);
        documento.add(pTableRodape);
        documento.close();

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");

    } catch (FileNotFoundException | DocumentException ex) {
        Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Export.GenericPDFs.java

/**
 *
 * @param user//ww w  .jav  a  2 s . co  m
 * @param nomeDoc
 * @param titleDoc
 * @param rs
 * @param op
 * @param paramFilter
 * @return
 */
public static String createDoc(String user, String nomeDoc, String titleDoc, DataTableControl rs,
        OrientacaoPagina op, int paramFilter) {
    nomeDocR = nomeDoc;
    try {

        Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                10f);
        Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoTable = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED,
                7.5f);
        Font fontCorpoTableN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                7.8f);
        Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                11.5f);
        Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                16f, Font.UNDERLINE);

        getMap(rs, paramFilter);
        ar = createPerncetage(list, paramFilter);
        PdfPTable tableDados = new PdfPTable(ar);

        Document documento = new Document();

        i = 0;
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");

        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio");

        ff.mkdirs();
        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + nomeDoc + " " + Ddata + ".pdf");
        OutputStream outputStraem = new FileOutputStream(ff);

        reString = "../Documentos/" + user + "/Relatorio/" + nomeDoc + " " + Ddata + ".pdf";

        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        MyFooter event = new MyFooter();
        writer.setPageEvent(event);

        if (op == OrientacaoPagina.HORIZONTAL) {
            documento.setPageSize(PageSize.A4.rotate());
        } else {
            documento.setPageSize(PageSize.A4);
        }

        documento.setMargins(10f, 10f, 35f, 35f);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(
                (OrientacaoPagina.HORIZONTAL == op) ? new float[] { 14f, 86f } : new float[] { 18.5f, 82.5f });
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);

        PdfPTable pTableNull = new PdfPTable(1);
        PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
        cellNull.setBorder(0);
        pTableNull.addCell(cellNull);

        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);

        PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN));
        pCellNomeEndereco.setBorder(0);

        PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN));
        pCellCaixaPostal.setBorder(0);

        PdfPCell pCellTeleFax = new PdfPCell(
                new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
        pCellTeleFax.setBorder(0);

        PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN));
        pCellSociedade.setBorder(0);

        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(120f, 85f);

        pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
        pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
        pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
        pTableEmpresaInforImpres1.addCell(pCellTeleFax);
        pTableEmpresaInforImpres1.addCell(pCellSociedade);

        PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
        cellTabela3.setBorder(0);

        pTableEmpresaInforImpres5.addCell(cellTabela3);

        PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
        cellTabela5.setBorder(0);

        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);
        pTableEmpresaPricipal.setWidthPercentage(97);
        pTableEmpresaPricipal.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);

        PdfPTable pTableTitile = new PdfPTable(1);
        SimpleDateFormat format = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR"));
        PdfPCell cellTitile = new PdfPCell(new Phrase(titleDoc.toUpperCase() + ((dF != null && dI != null)
                ? (" de " + format.format(dI) + "  " + format.format(dF)).toUpperCase()
                : ""), fontCorpoTitile));
        cellTitile.setPaddingBottom(20f);
        cellTitile.setBorder(0);
        cellTitile.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableTitile.addCell(cellTitile);
        documento.add(pTableTitile);

        tableDados.setWidthPercentage(97f);
        PdfPTable tableTitile = new PdfPTable(ar);
        tableTitile.setWidthPercentage(97f);

        if (paramFilter < 0) {
            for (Object[] emap : list) {
                tableDados = new PdfPTable(ar);
                tableDados.setWidthPercentage(97f);
                if (emap[0] == null || !emap[0].equals("TOTAL")) {
                    for (int j = 0; j < emap.length; j++) {
                        if (cabe && i == 0) {
                            lista_titulo_table = emap;
                            PdfPCell cellTitileTable = new PdfPCell(
                                    new Phrase(toString(emap[j]).toUpperCase(), fontCorpoNG));
                            cellTitileTable.setBorderWidth(1f);
                            cellTitileTable.setPaddingTop(8f);
                            cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                            cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                            BaseColor colorAzul = new BaseColor(255, 255, 255);
                            cellTitileTable.setBackgroundColor(colorAzul);
                            cellTitileTable.setPaddingBottom(8f);
                            tableTitile.addCell(cellTitileTable);
                        } else {
                            PdfPCell dados = new PdfPCell(new Phrase(toString(emap[j]), fontCorpoTable));
                            dados.setHorizontalAlignment(
                                    (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT);
                            dados.setPaddingTop(5f);
                            dados.setPaddingBottom(5f);
                            BaseColor colorCinza = new BaseColor(255, 255, 255);
                            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
                            tableDados.addCell(dados);
                        }
                    }
                    i++;
                    cabe = false;
                }

                if (i == 1) {
                    documento.add(tableTitile);
                }

                documento.add(tableDados);

            }

            PdfPTable tableTotal = new PdfPTable(ar);
            tableTotal.setWidthPercentage(97f);

            mapTotal.entrySet().stream().forEach((entrySet) -> {
                mapTotal.get(entrySet.getKey()).stream().forEach((get) -> {
                    for (int g = 0; g < get.length; g++) {
                        if (g != paramFilter) {
                            PdfPCell dados = new PdfPCell(
                                    new Phrase(((g == 0) ? "TOTAL" : toString(get[g])), fontCorpoTableN));
                            dados.setHorizontalAlignment(
                                    (alignment.containsKey(g)) ? alignment.get(g).i : PdfPCell.ALIGN_LEFT);
                            dados.setPaddingTop(5f);
                            dados.setPaddingBottom(5f);
                            BaseColor colorCinza = new BaseColor(255, 255, 255);
                            dados.setBackgroundColor(colorCinza);
                            tableTotal.addCell(dados);
                        }
                    }
                });
            });
            documento.add(tableTotal);
        } else {
            int t = 0;
            for (Map.Entry<String, ArrayList<Object[]>> lista : map.entrySet()) {
                i = 0;
                cabe = true;

                PdfPTable pTableSubTitile = new PdfPTable(new float[] { 100 });
                pTableSubTitile.setWidthPercentage(97f);

                PdfPCell cellSubTitile = new PdfPCell(
                        new Paragraph(lista.getKey().toUpperCase(), fontCorpoTitile));
                cellSubTitile.setBorder(PdfPCell.NO_BORDER);
                cellSubTitile.setPaddingTop(0f);
                cellSubTitile.setPaddingBottom(0f);
                pTableSubTitile.addCell(cellSubTitile);
                documento.add(pTableSubTitile);

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

                for (Object[] emap : lista.getValue()) {
                    tableDados = new PdfPTable(ar);
                    tableTitile = new PdfPTable(ar);
                    tableDados.setWidthPercentage(97f);
                    tableTitile.setWidthPercentage(97f);
                    int k = 0;
                    for (int j = 0; j < emap.length; j++) {
                        if (k != paramFilterOculta) {
                            if (cabe && i == 0) {
                                lista_titulo_table = emap;
                                PdfPCell cellTitileTable = new PdfPCell(
                                        new Phrase(toString(emap[j]).toUpperCase(), fontCorpoNG));
                                cellTitileTable.setBorderWidth(1f);
                                cellTitileTable.setPaddingTop(8f);
                                cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                                cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                                BaseColor colorAzul = new BaseColor(255, 255, 255);
                                cellTitileTable.setBackgroundColor(colorAzul);
                                cellTitileTable.setPaddingBottom(8f);
                                tableTitile.addCell(cellTitileTable);
                            } else {
                                PdfPCell dados = new PdfPCell(new Phrase(toString(emap[j]), fontCorpoTable));
                                dados.setHorizontalAlignment(
                                        (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT);
                                dados.setPaddingTop(5f);
                                dados.setPaddingBottom(5f);
                                BaseColor colorCinza = new BaseColor(255, 255, 255);
                                dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
                                tableDados.addCell(dados);
                            }
                        }
                        k++;
                    }
                    i++;

                    cabe = false;
                    if (i == 1) {
                        documento.add(tableTitile);
                    }

                    documento.add(tableDados);

                }
                PdfPTable tableTotal = new PdfPTable(ar);
                tableTotal.setWidthPercentage(97f);
                if (mapTotal.containsKey(lista.getKey())) {
                    mapTotal.get(lista.getKey()).stream().forEach((get) -> {
                        for (int g = 0; g < get.length; g++) {
                            if (g != paramFilterOculta) {
                                PdfPCell dados = new PdfPCell(
                                        new Phrase(((g == 0) ? "TOTAL" : toString(get[g])), fontCorpoTableN));
                                dados.setHorizontalAlignment(
                                        (alignment.containsKey(g)) ? alignment.get(g).i : PdfPCell.ALIGN_LEFT);
                                dados.setPaddingTop(5f);
                                dados.setPaddingBottom(5f);
                                BaseColor colorCinza = new BaseColor(255, 255, 255);
                                dados.setBackgroundColor(colorCinza);
                                tableTotal.addCell(dados);
                            }
                        }
                    });
                }
                documento.add(tableTotal);
                t++;

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

                if (t == map.size() && paramFilter > -1) {
                    PdfPTable tableTotal_t = new PdfPTable(ar);
                    tableTotal_t.setWidthPercentage(97f);
                    for (int j = 0; j < lista_titulo_table.length; j++) {
                        if (j != paramFilterOculta) {
                            PdfPCell cellTitileTable = new PdfPCell(
                                    new Phrase(toString(lista_titulo_table[j]).toUpperCase(), fontCorpoNG));
                            cellTitileTable.setBorderWidth(1f);
                            cellTitileTable.setPaddingTop(8f);
                            cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                            cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                            BaseColor colorAzul = new BaseColor(255, 255, 255);
                            cellTitileTable.setBackgroundColor(colorAzul);
                            cellTitileTable.setPaddingBottom(8f);
                            tableTotal_t.addCell(cellTitileTable);
                        }
                    }

                    Double[] total_total = new Double[lista_titulo_table.length];
                    mapTotal.entrySet().stream().forEach((entrySet) -> {
                        mapTotal.get(entrySet.getKey()).stream().forEach((value) -> {
                            for (int g = 0; g < value.length; g++) {
                                if (!entrySet.getKey().equals("TOTAL")) {
                                    if (g != paramFilterOculta) {
                                        if (Moeda.unFormat(toString(value[g]).replaceAll(" ", "")
                                                .replaceAll(",", ".").replaceAll("STD", "")) != -1) {
                                            double v = ((total_total[g] == null) ? 0.0 : total_total[g]);
                                            total_total[g] = (Moeda
                                                    .unFormat(toString(value[g]).replaceAll(" ", "")
                                                            .replaceAll(",", ".").replaceAll("STD", ""))
                                                    + v);
                                        }
                                        PdfPCell dados = new PdfPCell(new Phrase(
                                                ((g == 0) ? "TOTAL " + entrySet.getKey().toUpperCase()
                                                        : toString(value[g])),
                                                fontCorpoTableN));
                                        dados.setHorizontalAlignment(
                                                (alignment.containsKey(g)) ? alignment.get(g).i
                                                        : PdfPCell.ALIGN_LEFT);
                                        dados.setPaddingTop(5f);
                                        dados.setPaddingBottom(5f);
                                        BaseColor colorCinza = new BaseColor(255, 255, 255);
                                        dados.setBackgroundColor(colorCinza);
                                        tableTotal_t.addCell(dados);
                                    }
                                }
                            }
                        });
                    });
                    for (int j = 0; j < total_total.length; j++) {
                        if (j != paramFilterOculta) {
                            PdfPCell cellTitileTable = new PdfPCell(
                                    new Phrase((total_total[j] != null) ? Moeda.format(total_total[j]) : " ",
                                            fontCorpoNG));
                            cellTitileTable.setPaddingTop(5f);
                            cellTitileTable.setHorizontalAlignment(
                                    (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT);
                            BaseColor colorAzul = new BaseColor(255, 255, 255);
                            cellTitileTable.setBackgroundColor(colorAzul);
                            cellTitileTable.setPaddingBottom(5f);
                            tableTotal_t.addCell(cellTitileTable);
                        }
                    }
                    documento.add(tableTotal_t);
                }
            }
        }
        documento.close();
        no = false;
        nomeNo = "";
        dI = null;
        dF = null;
        paramFilterOculta = -1;
        removeItem = new int[] {};
        renameItem = new HashMap<>();
        alignment = new HashMap<>();
        arrValoresTotal = new int[] {};
        valoresTotal = new String[] {};
        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");
        return reString;
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(GenericPDFs.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (DocumentException ex) {
        Logger.getLogger(GenericPDFs.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:Export.ListaVeiculo.java

public static void criarDocPdf(List<Veiculo> ls, String user) {
    @SuppressWarnings("UnusedAssignment")
    OutputStream outputStraem = null;
    try {/*from   www  .j av a2  s.c o  m*/

        Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                10f);
        Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoTable = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED,
                8f);
        Font fontCorpoTableN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                8f);
        Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                11.5f);
        Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                16f, Font.UNDERLINE);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 15f, 85 });
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);
        PdfPTable pTableNull = new PdfPTable(1);

        PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
        cellNull.setBorder(0);
        pTableNull.addCell(cellNull);

        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);
        PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN));
        pCellNomeEndereco.setBorder(0);
        PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN));
        pCellCaixaPostal.setBorder(0);
        PdfPCell pCellTeleFax = new PdfPCell(
                new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
        pCellTeleFax.setBorder(0);
        PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN));
        pCellSociedade.setBorder(0);

        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(120f, 85f);

        pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
        pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
        pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
        pTableEmpresaInforImpres1.addCell(pCellTeleFax);
        pTableEmpresaInforImpres1.addCell(pCellSociedade);

        PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
        cellTabela3.setBorder(0);

        pTableEmpresaInforImpres5.addCell(cellTabela3);
        PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
        cellTabela5.setBorder(0);

        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);

        pTableEmpresaPricipal.setWidthPercentage(97);
        pTableEmpresaPricipal.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);
        Document documento = new Document(PageSize.A4.rotate());

        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio");
        ff.mkdirs();

        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Lista de Veiculos" + " " + Ddata + ".pdf");

        outputStraem = new FileOutputStream(ff);
        String reString = "../Documentos/" + user + "/Relatorio/" + "Lista de Veiculos" + " " + Ddata + ".pdf";
        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        BaseColor colorAzul = new BaseColor(176, 196, 222);
        BaseColor colorCinza = new BaseColor(240, 240, 240);
        //            BaseColor colorAzulEscuro = new BaseColor(100, 149, 237);

        PdfPTable pTableSubTitile = new PdfPTable(new float[] { 100 });
        pTableSubTitile.setWidthPercentage(97f);

        PdfPCell cellSubTitile = new PdfPCell(new Paragraph("Lista de Veiculos", fontCorpoTitile));
        cellSubTitile.setBorder(PdfPCell.NO_BORDER);
        cellSubTitile.setPaddingTop(0f);
        cellSubTitile.setPaddingBottom(0f);
        pTableSubTitile.addCell(cellSubTitile);

        PdfPTable tableDados = new PdfPTable(
                new float[] { 12.8f, 12.8f, 12.8f, 12.8f, 12.8f, 12.8f, 12.8f, 12.8f });
        tableDados.setWidthPercentage(97f);

        for (int i = 0; i < 8; i++) {
            PdfPCell cellTitileTable = new PdfPCell(new Phrase(getList(i), fontCorpoNG));
            cellTitileTable.setBorderWidth(1f);
            cellTitileTable.setPaddingTop(8f);
            cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cellTitileTable.setBackgroundColor(colorAzul);
            cellTitileTable.setPaddingBottom(8f);
            tableDados.addCell(cellTitileTable);
        }

        PdfPCell dados;

        for (int i = 0; i < ls.size(); i++) {

            dados = new PdfPCell(new Phrase(ls.get(i).getNumeroMatricula(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getMarca(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getModelo(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getNumMotor(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getChassi(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getAnoFabrico(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getAnoCompra(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

            dados = new PdfPCell(new Phrase(ls.get(i).getCapacidade(), fontCorpoTable));
            dados.setPaddingTop(5f);
            dados.setPaddingBottom(5f);
            dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null));
            tableDados.addCell(dados);

        }

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableSubTitile);
        documento.add(pTableNull);
        documento.add(tableDados);
        documento.close();

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");

    } catch (FileNotFoundException | DocumentException ex) {
        Logger.getLogger(ListaVeiculo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ListaVeiculo.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ExternalNonFormClasses.PDFEnator.java

public PdfPTable writeHeaders(Font font) {
    PdfPTable pdftable = new PdfPTable(setTableDimensions());
    pdftable.setTotalWidth(480);/*from  ww w.ja  va2s  .  com*/
    for (int a = 0; a < this.tableHeaderData.size(); a++) {
        System.out.println("Header #" + a);
        PdfPCell cell1 = new PdfPCell(new Paragraph(this.tableHeaderData.get(a), font));
        cell1.setPaddingBottom(5);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        pdftable.addCell(cell1);
    }
    return pdftable;
}

From source file:fll.util.PdfUtils.java

License:Open Source License

/**
 * Create a table cell with the specified text and background color.
 *///  w w  w .  j av  a 2  s.c o  m
public static PdfPCell createCell(final String text, final BaseColor backgroundColor)
        throws BadElementException {
    final PdfPCell cell = PdfUtils.createCell(text);
    if (null != backgroundColor) {
        cell.setBackgroundColor(backgroundColor);
    }
    return cell;
}

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException {

    // This creates our new PDF document and declares its orientation
    Document pdfDoc;/*from  w ww  . j ava 2s .co  m*/
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {
        pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape
    }
    PdfWriter.getInstance(pdfDoc, out);

    // Measurements are always in points (72 per inch)
    // This sets up 1/2 inch margins side margins and 0.35in top and bottom
    // margins
    pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH,
            0.35f * POINTS_PER_INCH);
    pdfDoc.open();

    // Header cell with challenge title to add to both scoresheets
    final Paragraph titleParagraph = new Paragraph();
    final Chunk titleChunk = new Chunk(m_pageTitle,
            FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.setAlignment(Element.ALIGN_CENTER);
    titleParagraph.add(titleChunk);

    titleParagraph.add(Chunk.NEWLINE);
    final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.add(swVersionChunk);
    if (null != m_revision) {

        final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision,
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));

        titleParagraph.add(revisionChunk);
    }

    final PdfPCell head = new PdfPCell();
    head.setColspan(2);
    head.setBorder(1);
    head.setPaddingTop(0);
    head.setPaddingBottom(3);
    head.setBackgroundColor(new BaseColor(64, 64, 64));
    head.setVerticalAlignment(Element.ALIGN_TOP);
    head.addElement(titleParagraph);

    // Cells for score field, and 2nd check initials
    final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL);
    final PdfPCell desC = new PdfPCell(des);
    desC.setBorder(0);
    desC.setPaddingTop(9);
    desC.setPaddingRight(36);
    desC.setHorizontalAlignment(Element.ALIGN_RIGHT);
    final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL);
    final PdfPCell sciC = new PdfPCell(sci);
    sciC.setBorder(0);
    sciC.setPaddingTop(9);
    sciC.setPaddingRight(36);
    sciC.setHorizontalAlignment(Element.ALIGN_RIGHT);

    // Create a table with a grid cell for each scoresheet on the page
    PdfPTable wholePage = getTableForPage(orientationIsPortrait);
    wholePage.setWidthPercentage(100);
    for (int i = 0; i < m_numSheets; i++) {
        if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) {
            pdfDoc.newPage();
            wholePage = getTableForPage(orientationIsPortrait);
            wholePage.setWidthPercentage(100);
        }

        // This table is a single score sheet
        final PdfPTable scoreSheet = new PdfPTable(2);
        // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM
        // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER
        scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        scoreSheet.getDefaultCell().setPaddingRight(1);
        scoreSheet.getDefaultCell().setPaddingLeft(0);

        scoreSheet.addCell(head);

        final PdfPTable teamInfo = new PdfPTable(7);
        teamInfo.setWidthPercentage(100);
        teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f });

        // Time label cell
        final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL);
        timeP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell());
        timeLc.addElement(timeP);
        teamInfo.addCell(timeLc);
        // Time value cell
        final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL);
        final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell());
        timeVc.addElement(timeV);
        teamInfo.addCell(timeVc);

        // Table label cell
        final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL);
        tblP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell());
        tblLc.addElement(tblP);
        teamInfo.addCell(tblLc);
        // Table value cell
        final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL);
        final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell());
        tblVc.addElement(tblV);
        teamInfo.addCell(tblVc);

        // Round number label cell
        final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL);
        rndP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell());
        rndlc.addElement(rndP);
        teamInfo.addCell(rndlc);
        // Round number value cell
        final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL);
        final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell());
        // rndVc.setColspan(2);
        rndVc.addElement(rndV);
        teamInfo.addCell(rndVc);

        final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp1.setColspan(2);
        temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp1);

        // Team number label cell
        final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL);
        nbrP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrlc.addElement(nbrP);
        teamInfo.addCell(nbrlc);
        // Team number value cell
        final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]),
                COURIER_10PT_NORMAL);
        final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrVc.addElement(nbrV);
        teamInfo.addCell(nbrVc);

        // Team division label cell
        final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL);
        divP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell());
        divlc.addElement(divP);
        divlc.setColspan(2);
        teamInfo.addCell(divlc);
        // Team division value cell
        final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL);
        final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell());
        divVc.setColspan(2);
        divVc.addElement(divV);
        teamInfo.addCell(divVc);

        final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp2.setColspan(2);
        temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp2);

        // Team name label cell
        final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL);
        nameP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell());
        namelc.setColspan(2);
        namelc.addElement(nameP);
        teamInfo.addCell(namelc);
        // Team name value cell
        final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL);
        final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell());
        nameVc.setColspan(5);
        nameVc.addElement(nameV);
        teamInfo.addCell(nameVc);

        // add team info cell to the team table
        final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell());
        teamInfoCell.addElement(teamInfo);
        teamInfoCell.setColspan(2);

        scoreSheet.addCell(teamInfoCell);

        if (null != m_goalsTable) {
            final PdfPCell goalCell = new PdfPCell(m_goalsTable);
            goalCell.setBorder(0);
            goalCell.setPadding(0);
            goalCell.setColspan(2);
            scoreSheet.addCell(goalCell);
        }

        scoreSheet.addCell(desC);
        scoreSheet.addCell(sciC);

        if (null != m_copyright) {
            final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i);
            final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell());
            copyrightC.addElement(copyright);
            copyrightC.setBorder(0);
            copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER);
            copyrightC.setColspan(2);

            scoreSheet.addCell(copyrightC);
        }

        // the cell in the whole page table that will contain the single score
        // sheet
        final PdfPCell scoresheetCell = new PdfPCell(scoreSheet);
        scoresheetCell.setBorder(0);
        scoresheetCell.setPadding(0);

        // Interior borders between scoresheets on a page
        if (!orientationIsPortrait) {
            if (i % 2 == 0) {
                scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH);
            } else {
                scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH);
            }
        }

        // Add the current scoresheet to the page
        wholePage.addCell(scoresheetCell);

        // Add the current table of scoresheets to the document
        if (orientationIsPortrait || (i % 2 != 0)) {
            pdfDoc.add(wholePage);
        }
    }

    // Add a blank cells to complete the table of the last page
    if (!orientationIsPortrait && m_numSheets % 2 != 0) {
        final PdfPCell blank = new PdfPCell();
        blank.setBorder(0);
        wholePage.addCell(blank);
        pdfDoc.add(wholePage);
    }

    pdfDoc.close();
}

From source file:FormatoPDF.ClasesPDF.PDF1.java

public void CrearPDF1(String[][] tabla, String txt1, String txt2, String txt3, String txt4, String txt5,
            String txt6, JTable tabla2) {
        String[][] tabla1 = tabla;
        float[] medidas1 = { 8.5f, 9.0f, 7.5f, 3.5f, 4.5f, 4.0f };
        float[] medidas2 = { 7.5f, 3.5f, 7.0f, 5.5f, 4.5f, 4.5f, 4.5f };
        float[] medidas3 = { 6.5f, 20.5f };
        JFileChooser dlg = new JFileChooser();
        int option = dlg.showSaveDialog(dlg);
        if (option == JFileChooser.APPROVE_OPTION) {
            File f = dlg.getSelectedFile();
            String f1 = f.toString();
            try {
                BaseColor MiColor = WebColors.getRGBColor("#04B4AE");
                TablasPDF tab = new TablasPDF();
                ImagenHome img = new ImagenHome();
                Document document = new Document();
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f1 + ".pdf"));
                Paragraph saltolinea = new Paragraph();
                saltolinea.add("\n");
                document.open();//from   ww w .j  a v  a  2 s .co  m
                document.add(img.CrearImg());
                DatosEncabezado en = new DatosEncabezado();
                String[][] valores = new String[4][2];
                valores[0][0] = "Dependencia: ";
                valores[0][1] = txt1;
                valores[1][0] = "Expediente: ";
                valores[1][1] = txt2;
                valores[2][0] = "Sesin: ";
                valores[2][1] = txt3;
                valores[3][0] = "Fecha: ";
                valores[3][1] = txt4;
                en.Datos(valores, writer);

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                boolean color = true;
                PdfPTable tabpdf1 = new PdfPTable(6);
                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("Sesin:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell11 = new PdfPCell(
                        new Paragraph(tabla1[0][1], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell1);
                tabpdf1.addCell(cell11);
                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("Fecha:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell22 = new PdfPCell(
                        new Paragraph(tabla1[0][3], FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell2);
                tabpdf1.addCell(cell22);
                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("Acuerdo:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                PdfPCell cell33 = new PdfPCell(
                        new Paragraph(txt5, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell3.setBackgroundColor(MiColor);
                tabpdf1.addCell(cell3);
                tabpdf1.addCell(cell33);
                document.add(tab.DibujarTablaArre1(6, 6, tabla1, medidas1, color, tabpdf1, 1, ""));

                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf2 = new PdfPTable(7);
                PdfPCell cell1tab2 = new PdfPCell(new Phrase("ESTUDIO DE MERCADO",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1tab2.setBackgroundColor(MiColor);
                cell1tab2.setMinimumHeight(30);
                cell1tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab2.setColspan(7);
                cell1tab2.setRowspan(1);
                cell1tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell1tab2);

                PdfPCell cell2tab2 = new PdfPCell(new Phrase("Datos de la empresa ",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2tab2.setBackgroundColor(MiColor);
                cell2tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab2.setColspan(4);
                cell2tab2.setRowspan(1);
                cell2tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell2tab2);

                PdfPCell cell3tab2 = new PdfPCell(new Phrase("Datos de cotizacin ",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell3tab2.setBackgroundColor(MiColor);
                cell3tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3tab2.setColspan(3);
                cell3tab2.setRowspan(1);
                cell3tab2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf2.addCell(cell3tab2);

                PdfPCell cell4tab2 = new PdfPCell(new Paragraph("Nombre, Denominacin o Razn Social",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell4tab2.setBackgroundColor(MiColor);
                cell4tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell4tab2);
                PdfPCell cell5tab2 = new PdfPCell(
                        new Paragraph("RFC", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell5tab2.setBackgroundColor(MiColor);
                cell5tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell5tab2);
                PdfPCell cell6tab2 = new PdfPCell(new Paragraph("Representante Legal",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell6tab2.setBackgroundColor(MiColor);
                cell6tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell6tab2);
                PdfPCell cell7tab2 = new PdfPCell(new Paragraph("Domicilio Fiscal",
                        FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell7tab2.setBackgroundColor(MiColor);
                cell7tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell7tab2);
                PdfPCell cell8tab2 = new PdfPCell(
                        new Paragraph("Subtotal", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell8tab2.setBackgroundColor(MiColor);
                cell8tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell8tab2);
                PdfPCell cell9tab2 = new PdfPCell(
                        new Paragraph("IVA", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell9tab2.setBackgroundColor(MiColor);
                cell9tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell9tab2);
                PdfPCell cell10tab2 = new PdfPCell(
                        new Paragraph("TOTAL", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell10tab2.setBackgroundColor(MiColor);
                cell10tab2.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabpdf2.addCell(cell10tab2);

                document.add(tab.DibujarTabla(7, 5, tabla2, medidas2, tabpdf2));
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);
                document.add(saltolinea);

                PdfPTable tabpdf3 = new PdfPTable(2);
                PdfPCell cell1tab3 = new PdfPCell(
                        new Phrase("Observaciones:", FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell1tab3.setBackgroundColor(MiColor);
                cell1tab3.setMinimumHeight(60);
                cell1tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell1tab3);

                PdfPCell cell2tab3 = new PdfPCell(
                        new Phrase(txt6, FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.BLACK)));
                cell2tab3.setMinimumHeight(60);
                cell2tab3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2tab3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                tabpdf3.addCell(cell2tab3);
                tabpdf3.setWidths(medidas3);
                document.add(tabpdf3);

                document.close();
                JOptionPane.showMessageDialog(null, "El archivo se ha guardado", "Exito",
                        JOptionPane.INFORMATION_MESSAGE);

                File path = new File(f1 + ".pdf");
                Desktop.getDesktop().open(path);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error " + e, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }