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:Reporte.PdfPremio.java

private void generarFilaTotales() throws DocumentException {
    Font fuente = new Font();
    fuente.setSize(10);/*  www . ja v a2  s  . c o m*/

    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales", fuente));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    celdaFinal.setColspan(5);

    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    tabla.addCell(celdaFinal);
    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.totalPremio)));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);

    documento.add(tabla);

    documento.add(new Paragraph("Cantidad de registros: " + this.totalRegistros, fuente));
}

From source file:Reporte.PdfVenta.java

private void generarFilaTotales() throws DocumentException {
    Font fuente = new Font();
    fuente.setSize(10);/* w  ww  . j av a 2  s .c o m*/

    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales"));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    celdaFinal.setColspan(2);
    tabla.addCell(celdaFinal);

    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.ventas), fuente));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);
    PdfPCell parrafo2 = new PdfPCell(new Paragraph(formatoNumero.format(this.comisiones), fuente));
    parrafo2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo2);
    PdfPCell parrafo3 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonado), fuente));
    parrafo3.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo3);
    PdfPCell parrafo4 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonos), fuente));
    parrafo4.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo4);
    PdfPCell parrafo5 = new PdfPCell(new Paragraph(formatoNumero.format(this.saldos), fuente));
    parrafo5.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo5);

    PdfPCell parrafo6 = new PdfPCell(new Paragraph(formatoNumero.format(this.totalTicket), fuente));
    parrafo6.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo6);

    documento.add(tabla);
    documento.add(new Paragraph("Cantidad de registros : " + this.totalRegistros, fuente));
}

From source file:Reporte.PdfVentaPersona.java

private void generarFilaTotales() throws DocumentException {
    Font fuente = new Font();
    fuente.setSize(10);//from w  ww.ja v  a2 s  . co  m

    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales"));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    celdaFinal.setColspan(1);
    tabla.addCell(celdaFinal);

    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.ventas), fuente));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);

    PdfPCell parrafo2 = new PdfPCell(new Paragraph(formatoNumero.format(this.comisiones), fuente));
    parrafo2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo2);

    PdfPCell parrafo3 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonado), fuente));
    parrafo3.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo3);

    PdfPCell parrafo4 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonos), fuente));
    parrafo4.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo4);

    PdfPCell parrafo5 = new PdfPCell(new Paragraph(formatoNumero.format(this.saldos), fuente));
    parrafo5.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo5);

    PdfPCell parrafo6 = new PdfPCell(new Paragraph(formatoNumero.format(this.totalTicket), fuente));
    parrafo6.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo6);

    documento.add(tabla);
    documento.add(new Paragraph("Cantidad de registros : " + this.totalRegistros, fuente));
}

From source file:Reporte.PdfVentasGeneral.java

private void generarFilasTotalesFinalColombia() throws DocumentException {

    Font fuente = new Font();
    fuente.setSize(10);/*  w  w  w .  j  av  a 2  s .com*/

    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales"));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    celdaFinal.setColspan(2);
    tabla.addCell(celdaFinal);

    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalVentasColombia), fuente));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);
    PdfPCell parrafo2 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalcomisionesColombia), fuente));
    parrafo2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo2);
    PdfPCell parrafo3 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalaboonadoColombia), fuente));
    parrafo3.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo3);
    PdfPCell parrafo4 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalabonosColombia), fuente));
    parrafo4.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo4);
    PdfPCell parrafo5 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalsaldosColombia), fuente));
    parrafo5.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo5);

    PdfPCell parrafo6 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinaltickeColombia), fuente));
    parrafo6.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo6);

    documento.add(tabla);

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

}

From source file:Reporte.PdfVentasGeneral.java

private void generarFilasTotalesFinalVenezuela() throws DocumentException {

    Font fuente = new Font();
    fuente.setSize(10);//w  w w. j a  v  a2 s.  com

    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales"));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    celdaFinal.setColspan(2);
    tabla.addCell(celdaFinal);

    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalVentasVenezuela), fuente));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);
    PdfPCell parrafo2 = new PdfPCell(
            new Paragraph(formatoNumero.format(this.FinalcomisionesVenezuela), fuente));
    parrafo2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo2);
    PdfPCell parrafo3 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalaboonadoVenezuela), fuente));
    parrafo3.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo3);
    PdfPCell parrafo4 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalabonosVenezuela), fuente));
    parrafo4.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo4);
    PdfPCell parrafo5 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinalsaldosVenezuela), fuente));
    parrafo5.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo5);

    PdfPCell parrafo6 = new PdfPCell(new Paragraph(formatoNumero.format(this.FinaltickeVenezuela), fuente));
    parrafo6.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo6);

    documento.add(tabla);

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

}

From source file:Reporte.PdfVentasSaldos.java

private void generarFilaTotales() throws DocumentException {
    Font fuente = new Font();
    fuente.setSize(10);//w  w w. j ava2  s. c o  m
    PdfPCell celdaFinal = new PdfPCell(new Paragraph("Totales"));
    celdaFinal.setBackgroundColor(BaseColor.GRAY);
    NumberFormat formatoNumero = NumberFormat.getNumberInstance();
    celdaFinal.setColspan(2);
    tabla.addCell(celdaFinal);

    PdfPCell parrafox = new PdfPCell(new Paragraph(formatoNumero.format(this.saldoAnterior), fuente));
    parrafox.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafox);

    PdfPCell parrafo1 = new PdfPCell(new Paragraph(formatoNumero.format(this.ventas), fuente));
    parrafo1.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo1);
    PdfPCell parrafo2 = new PdfPCell(new Paragraph(formatoNumero.format(this.comisiones), fuente));
    parrafo2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo2);
    PdfPCell parrafo3 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonado), fuente));
    parrafo3.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo3);
    PdfPCell parrafo4 = new PdfPCell(new Paragraph(formatoNumero.format(this.abonos), fuente));
    parrafo4.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo4);
    PdfPCell parrafo5 = new PdfPCell(new Paragraph(formatoNumero.format(this.saldos), fuente));
    parrafo5.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo5);

    PdfPCell parrafo6 = new PdfPCell(new Paragraph(formatoNumero.format(this.totalTicket), fuente));
    parrafo6.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(parrafo6);
    documento.add(tabla);
    if (this.forma.equalsIgnoreCase("POSITIVOS")) {
        documento.add(new Paragraph("Cantidad de registros : " + this.totalRegistrosP, fuente));
    } else {
        documento.add(new Paragraph("Cantidad de registros : " + this.totalRegistrosN, fuente));
    }
}

From source file:reporteFertilizacion.ReporteResultadoLaboratorio.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww  w . j  a  v  a 2 s  .com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    try {
        Font font9BoldWhite = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD, BaseColor.WHITE);
        Font font7Bold = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD);
        Font font7Normal = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL);
        Font font8Bold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
        Font font8Normal = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL);
        Font font9Bold = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD);
        Font font9Normal = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        Font font10Bold = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
        Font font10Normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
        Font font12Bold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
        Font font12Normal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
        Font font14Bold = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD);
        Font font14Normal = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL);
        Font font18Bold = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD);
        Font font22Bold = FontFactory.getFont(FontFactory.HELVETICA, 22, Font.BOLD);

        //obtencion parametros *********************************************************
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map params = facesContext.getExternalContext().getRequestParameterMap();
        ObjectId parametroObtenido = new ObjectId(params.get("idMuestra").toString());

        ResultadoLaboratorio resLab = ResultadoLaboratorio.getResultadoLaboratorioById(parametroObtenido);
        MuestraLaboratorio muestra = MuestraLaboratorio.getMuestraLaboratorioById(resLab.getMuestra());
        Cliente cli = Cliente.getClienteById(
                Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getIdCliente());
        Hacienda hac = Hacienda
                .getHaciendaById(Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getId());
        //Lote lot = Lote.getLoteById(muestra.getLote());
        //String lot = muestra.getLote();
        Cultivo cul = Cultivo.getCultivoById(muestra.getSiembraCultivo().getIdCultivo());

        String cliente = cli.getNombre().toUpperCase();
        String ubicacion = Canton.getCantonById(cli.getCanton()).getNombre() + " - "
                + Canton.getCantonById(cli.getCanton()).getLeyendaProvincia() + " - "
                + Canton.getCantonById(cli.getCanton()).getLeyendaPais();
        String codigMuestra = muestra.getCodigo();

        String hacienda = hac.getNombre();
        String cultivo = cul.getNombre();
        //String varie = Variedad.getVariedadById(lot.getIdVariedad()).getNombre();
        String varie = muestra.getSiembraCultivo().getLeyendaVariedad();
        //String estacionMonitoreo = lot.getEstacion().get(0).getCodigo();
        String estacionMonitoreo = muestra.getSiembraCultivo().getUnidadManejo();
        //String estacionMonitoreo = muestra.getLoteCompleto().getListadoMonitoreo().get(0).getCodigo();
        String tituloProyecto = "Anlisis" + resLab.getLeyendaMatriz();
        String tipoMuestra = resLab.getLeyendaMatriz();
        String numeroMuestra = Integer.toString(
                MuestraLaboratorio.getNumberMuestraLaboratorio(muestra.getId(), muestra.getIdSiembraCultivo()));
        String numeroMonitoreo = numeroMuestra;
        //String lote = lot.getCodigo();
        String lote = "";
        int nn = muestra.getSiembraCultivo().getListaLotesSiembra().size();
        for (int i = 0; i < nn; i++) {
            lote = lote.concat(muestra.getSiembraCultivo().getListaLotesSiembra().get(i).getLeyendaLote());
        }

        String muestreador = muestra.getMuestreador();
        String fechaMuestreo = muestra.getFechaFormatMuestreo();
        String fechaRecepcionMuestra = muestra.getFechaFormatEnvio();
        String fechaResultado = resLab.getFechaFormatResultado();
        String periodoPrueba = resLab.getFechaFormatRecepcion() + " al " + resLab.getFechaFormatResultado();

        String contenidoHoja1 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 1 TEXTO INFORME")
                .getDescripcion();
        String responsableTecnico = TextoReporteResultadoLaboratorio.getByReferencia("RESPONSABLE TECNICO")
                .getDescripcion();
        String datosLaboratorio = TextoReporteResultadoLaboratorio.getByReferencia("DATOS LABORATORIO")
                .getDescripcion();
        String piePagina = TextoReporteResultadoLaboratorio.getByReferencia("PIE DE PAGINA").getDescripcion();
        String contenidoHoja2 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 2 OBSERVACION")
                .getDescripcion();

        //fin obtencion parametros *****************************************************

        /* TODO output your page here. You may use following sample code. */
        float left = 60;
        float right = 30;
        float top = 0;
        float bottom = 0;
        Document document = new Document(PageSize.A4, left, right, top, bottom);
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());

        //FOOTER TABLE *****************************************************************
        PdfPTable table = new PdfPTable(1);
        table.setTotalWidth(550);
        PdfPCell cell = new PdfPCell(new Phrase(piePagina, font8Normal));
        cell.setBackgroundColor(BaseColor.GREEN);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("www.agrorum.com.ec", font9BoldWhite));
        cell.setBackgroundColor(BaseColor.ORANGE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        table.addCell(cell);

        FooterTable event = new FooterTable(table);
        writer.setPageEvent(event);
        //FIN FOOTER TABLE *****************************************************************

        document.open();

        //HOJA 1 *********************************************************************************************************************************                        
        //IMAGE **********************************************************************************
        String relativeWebPathAg = "/images/agrorum.png";
        String absoluteDiskPathAg = getServletContext().getRealPath(relativeWebPathAg);
        Image logoAg = Image.getInstance(absoluteDiskPathAg);
        logoAg.setAbsolutePosition(10f, 750f);
        logoAg.scalePercent(80f);
        document.add(logoAg);

        String relativeWebPathEu = "/images/eurofins.png";
        String absoluteDiskPathEu = getServletContext().getRealPath(relativeWebPathEu);
        Image logoEu = Image.getInstance(absoluteDiskPathEu);
        logoEu.setAbsolutePosition(500f, 770f);
        logoEu.scalePercent(60f);
        document.add(logoEu);
        //FIN IMAGE ********************************************************************************         

        //CLIENTE UBICACION MUESTRA*****************************************************************
        Paragraph parphRepor = new Paragraph("Reporte de anlisis 1/2", font10Normal);
        parphRepor.setAlignment(Element.ALIGN_RIGHT);
        parphRepor.setSpacingBefore(90f);
        Paragraph parphCli = new Paragraph(cliente, font10Bold);
        parphCli.setAlignment(Element.ALIGN_LEFT);
        parphCli.setSpacingBefore(15f);
        Paragraph parphUbi = new Paragraph(ubicacion, font10Bold);
        parphUbi.setAlignment(Element.ALIGN_LEFT);
        parphUbi.setSpacingBefore(15f);
        //PARRAFO combinado con frases********************************************
        Phrase p1 = new Phrase("Cdigo de la Muestra:     ", font10Normal);
        Phrase p2 = new Phrase(codigMuestra, font10Bold);
        Paragraph parphMue = new Paragraph(p1);
        parphMue.add(p2);
        parphMue.setAlignment(Element.ALIGN_LEFT);
        parphMue.setSpacingBefore(15f);
        //FIN PARRAFO combinado***************************************************

        document.add(parphRepor);
        document.add(parphCli);
        document.add(parphUbi);
        document.add(parphMue);

        //FIN CLIENTE UBICACION MUESTRA*************************************************************
        //TABLA ***********************************************************************************
        PdfPTable tableDatos = new PdfPTable(new float[] { 0.20f, 0.80f });
        tableDatos.setWidthPercentage(100);

        tableDatos.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Cultivo Actual:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Ttulo Proyecto:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(tituloProyecto, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Tipo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Nmero Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(numeroMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Lote:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(lote, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Muestreador:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(muestreador.toUpperCase(), PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.setSpacingBefore(20f);
        document.add(tableDatos);
        //FIN TABLA ********************************************************************************

        //CONTENIDO ********************************************************************************
        Paragraph parphCont = new Paragraph(contenidoHoja1, font8Normal);
        parphCont.setAlignment(Element.ALIGN_JUSTIFIED);
        parphCont.setSpacingBefore(20f);

        Paragraph parphLLeida = new Paragraph("LLeida, " + fechaResultado, font8Normal);
        parphLLeida.setAlignment(Element.ALIGN_LEFT);
        parphLLeida.setSpacingBefore(20f);

        Paragraph parphTecnico = new Paragraph(responsableTecnico, font9Bold);
        parphTecnico.setAlignment(Element.ALIGN_LEFT);
        parphTecnico.setSpacingBefore(20f);

        Paragraph parphResponsable = new Paragraph("Responsable Tcnico", font8Normal);
        parphResponsable.setAlignment(Element.ALIGN_LEFT);
        parphResponsable.setSpacingBefore(1f);

        Paragraph parphLaboratorio = new Paragraph(datosLaboratorio, font8Bold);
        parphLaboratorio.setAlignment(Element.ALIGN_LEFT);
        parphLaboratorio.setSpacingBefore(30f);

        document.add(parphCont);
        document.add(parphLLeida);
        document.add(parphTecnico);
        document.add(parphResponsable);
        document.add(parphLaboratorio);
        //FIN CONTENIDO ****************************************************************************

        //FIN HOJA 1 *****************************************************************************************************************************
        document.newPage();

        //HOJA 2 *********************************************************************************************************************************                        
        //IMAGE **********************************************************************************
        String relativeWebPathAg1 = "/images/agrorum.png";
        String absoluteDiskPathAg1 = getServletContext().getRealPath(relativeWebPathAg1);
        Image logoAg1 = Image.getInstance(absoluteDiskPathAg1);
        logoAg1.setAbsolutePosition(10f, 750f);
        logoAg1.scalePercent(80f);
        document.add(logoAg1);

        String relativeWebPathEu1 = "/images/eurofins.png";
        String absoluteDiskPathEu1 = getServletContext().getRealPath(relativeWebPathEu1);
        Image logoEu1 = Image.getInstance(absoluteDiskPathEu1);
        logoEu1.setAbsolutePosition(500f, 770f);
        logoEu1.scalePercent(60f);
        document.add(logoEu1);

        Paragraph ini = new Paragraph("", font12Bold);
        ini.setAlignment(Element.ALIGN_CENTER);
        ini.setSpacingBefore(100f);

        PdfPTable cabT = new PdfPTable(new float[] { 1f });
        cabT.setWidthPercentage(100);
        PdfPCell cellCab = new PdfPCell(new Phrase("Informe de Prueba", font12Bold));
        cellCab.setPadding(2f);
        cellCab.setHorizontalAlignment(Element.ALIGN_CENTER);
        cabT.addCell(cellCab);

        Paragraph parphRep = new Paragraph("Reporte de anlisis 2/2", font10Normal);
        parphRep.setAlignment(Element.ALIGN_RIGHT);

        document.add(ini);
        document.add(cabT);
        document.add(parphRep);

        //TABLA ***********************************************************************************
        PdfPTable tableDatosH2 = new PdfPTable(new float[] { 0.20f, 0.80f });
        tableDatosH2.setWidthPercentage(100);

        tableDatosH2.addCell(getCell("Cliente:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(cliente, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Codigo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(codigMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Matriz:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Cultivo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Variedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(varie, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.setSpacingBefore(20f);
        document.add(tableDatosH2);
        //FIN TABLA ********************************************************************************

        Paragraph parphCont1 = new Paragraph(contenidoHoja2, font8Normal);
        parphCont1.setAlignment(Element.ALIGN_JUSTIFIED);
        parphCont1.setSpacingBefore(20f);

        PdfPTable tableDatosH3 = new PdfPTable(new float[] { 0.30f, 0.70f });
        tableDatosH3.setWidthPercentage(100);

        tableDatosH3.addCell(getCell(datosLaboratorio, PdfPCell.ALIGN_LEFT, font8Bold));

        PdfPTable subTable = new PdfPTable(new float[] { 1f });
        subTable.setWidthPercentage(100);

        subTable.addCell(getCell("LLeida, " + fechaResultado, PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));

        subTable.addCell(getCell(responsableTecnico, PdfPCell.ALIGN_CENTER, font9Bold));
        subTable.addCell(getCell("Responsable Tcnico", PdfPCell.ALIGN_CENTER, font8Normal));

        PdfPCell cellsub = new PdfPCell(subTable);
        cellsub.setBorder(PdfPCell.NO_BORDER);
        cellsub.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tableDatosH3.addCell(cellsub);

        tableDatosH3.setSpacingBefore(20f);

        document.add(parphCont1);
        document.add(tableDatosH3);

        //FIN IMAGE ********************************************************************************            
        //FIN HOJA 2 *****************************************************************************************************************************
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:Reportes.ReportePersonal.java

public PdfPTable tablaTitulos() {
    PdfPTable tabla = null;//from w  w  w .  j  a v  a2s.  c  om
    int numeroColumnas;
    String V[] = new String[5];
    V[0] = "Tipo Documento";
    V[1] = "Documento";
    V[2] = "Nombre";
    V[3] = "Correo";
    V[4] = "Perfil";

    // ResultSetMetaData metaDatos = rs.getMetaData();
    // Se obtiene el numero de columnas.
    numeroColumnas = 5;//metaDatos.getColumnCount();       
    tabla = new PdfPTable(numeroColumnas);

    PdfPCell celda = null;
    for (int i = 0; i < numeroColumnas; i++) {
        String tituloColumna = V[i];
        celda = new PdfPCell(
                new Paragraph(tituloColumna, FontFactory.getFont("arial", 12, Font.BOLD, BaseColor.BLACK)));
        celda.setBackgroundColor(BaseColor.WHITE);
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
    }
    return tabla;
}

From source file:Reportes.ReportePersonal.java

public PdfPTable tablaDatos() {

    PdfPTable tabla = null;//from ww w.ja  v a  2  s. c o m
    int numeroColumnas;

    String tipoDoc, documento, nombre, correo, perfil;
    String V[] = new String[6];

    PdfPCell celda;
    // Se obtiene el numero de columnas.
    numeroColumnas = 5;
    tabla = new PdfPTable(numeroColumnas);//construye una tabla con el nmero de columnas requeridas

    while (Nodo != null) // recorre cada registro del resultset
    {
        tipoDoc = Nodo.getUsuario().getTipoDoc();
        documento = Nodo.getUsuario().getDocumento();
        nombre = Nodo.getUsuario().getNombre();
        correo = Nodo.getUsuario().getCorreo();
        perfil = Nodo.getUsuario().getPerfil();

        V[0] = tipoDoc;
        V[1] = documento;
        V[2] = nombre;
        V[3] = correo;
        V[4] = perfil;

        for (int i = 0; i < numeroColumnas; i++)//lee cada campo del registro activo
        {
            String fila = V[i];
            celda = new PdfPCell(
                    new Paragraph(fila, FontFactory.getFont("arial", 12, Font.NORMAL, BaseColor.BLACK)));
            celda.setBackgroundColor(BaseColor.WHITE);
            tabla.addCell(celda);
        }
        Nodo = Nodo.getLiga();
    }

    return tabla;
}

From source file:ro.nextreports.engine.exporter.PdfExporter.java

License:Apache License

private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan,
        boolean image, int column) {
    Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan);

    FontFactoryImp fact = new FontFactoryImp();
    com.itextpdf.text.Font fnt;/*from   w  w  w.  ja  v a2  s.c  om*/
    if (bandElement != null) {
        fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY);
        int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue();
        fnt = getFont(size);
    } else {
        fnt = getFont(10);
    }

    PdfPCell cell;
    if (image) {
        if (value == null) {
            cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND));
        } else {
            ImageBandElement ibe = (ImageBandElement) bandElement;
            try {
                byte[] imageBytes = getImage((String) value);
                cell = getImageCell(ibe, imageBytes, column, colSpan);
            } catch (Exception e) {
                cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
            }
        }
    } else if (bandElement instanceof HyperlinkBandElement) {
        Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink();
        Anchor anchor = new Anchor(hyperlink.getText(), fnt);
        anchor.setReference(hyperlink.getUrl());
        Phrase ph = new Phrase();
        ph.add(anchor);
        cell = new PdfPCell(ph);
    } else if (bandElement instanceof ReportBandElement) {
        Report report = ((ReportBandElement) bandElement).getReport();
        ExporterBean eb = null;
        try {
            eb = getSubreportExporterBean(report);
            PdfExporter subExporter = new PdfExporter(eb);
            subExporter.export();
            PdfPTable innerTable = subExporter.getTable();
            cell = new PdfPCell(innerTable);
        } catch (Exception e) {
            cell = new PdfPCell();
            e.printStackTrace();
        } finally {
            if ((eb != null) && (eb.getResult() != null)) {
                eb.getResult().close();
            }
        }
    } else if ((bandElement instanceof VariableBandElement) && (VariableFactory
            .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) {
        try {
            cell = new PdfPCell(Image.getInstance(total));
        } catch (BadElementException e) {
            cell = new PdfPCell(new Phrase("NA"));
        }

    } else if (bandElement instanceof ImageColumnBandElement) {
        try {
            String v = StringUtil.getValueAsString(value, null);
            if (StringUtil.BLOB.equals(v)) {
                cell = new PdfPCell(new Phrase(StringUtil.BLOB));
            } else {
                byte[] bytes = StringUtil.decodeImage(v);
                cell = getImageCell(bandElement, bytes, column, colSpan);
            }
        } catch (Exception e) {
            e.printStackTrace();
            cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
        }
    } else {
        String stringValue;
        if (style.containsKey(StyleFormatConstants.PATTERN)) {
            stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN),
                    getReportLanguage());
        } else {
            stringValue = StringUtil.getValueAsString(value, null, getReportLanguage());
        }
        if (stringValue == null) {
            stringValue = "";
        }
        if (stringValue.startsWith("<html>")) {
            StringReader reader = new StringReader(stringValue);
            List<Element> elems = new ArrayList<Element>();
            try {
                elems = HTMLWorker.parseToList(reader, new StyleSheet());
                Phrase ph = new Phrase();
                for (int i = 0; i < elems.size(); i++) {
                    Element elem = (Element) elems.get(i);
                    ph.add(elem);
                }
                cell = new PdfPCell(ph);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Phrase ph = new Phrase(stringValue, fnt);
                cell = new PdfPCell(ph);
            }

        } else {
            Phrase ph = new Phrase(stringValue, fnt);
            cell = new PdfPCell(ph);
        }
    }

    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell.setUseDescender(true); // needed for a cell without padding
    cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty

    if (bandElement != null) {
        cell.setRotation(bandElement.getTextRotation());
    }

    if (colSpan > 1) {
        cell.setColspan(colSpan);
    }

    if (rowSpan > 1) {
        cell.setRowspan(rowSpan);
    }

    if (style != null) {

        updateFont(style, fnt);

        if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) {
            Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR);
            cell.setBackgroundColor(new BaseColor(val));
        }
        if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) {
            if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            }
        }

        if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) {
            if (StyleFormatConstants.VERTICAL_ALIGN_TOP
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_TOP);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
            }
        }

        if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT);
            cell.setPaddingLeft(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT);
            cell.setPaddingRight(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP);
            cell.setPaddingTop(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM);
            cell.setPaddingBottom(val);
        }
        cell.setBorderWidth(0);

        if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT);
            cell.setBorderWidthLeft(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR);
            cell.setBorderColorLeft(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT);
            cell.setBorderWidthRight(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR);
            cell.setBorderColorRight(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP);
            cell.setBorderWidthTop(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR);
            cell.setBorderColorTop(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM);
            cell.setBorderWidthBottom(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR);
            cell.setBorderColorBottom(new BaseColor(color));
        }

        // for subreports we use default no wrap
        if (cell.getTable() == null) {
            cell.setNoWrap(true);
            if (bandElement != null) {
                if (bandElement.isWrapText()) {
                    cell.setNoWrap(false);
                }
            }
        }

        // to see a background image all cells must not have any background!
        if (bean.getReportLayout().getBackgroundImage() != null) {
            cell.setBackgroundColor(null);
        }
    }
    return cell;
}