Example usage for com.itextpdf.text Paragraph setSpacingBefore

List of usage examples for com.itextpdf.text Paragraph setSpacingBefore

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph setSpacingBefore.

Prototype

public void setSpacingBefore(float spacing) 

Source Link

Usage

From source file:Report.RelatorioProfessor.java

/**
 * Funo para gerar o stream do relatorio de orientaes por professor
 *
 * @param lOrientacao/*from  w w w .j a v  a  2 s  .c  o m*/
 * @param dtinicial
 * @param dtfinal
 * @param coordenador
 * @param campus
 * @return ByteArrayOutputStream
 */
public ByteArrayOutputStream relatorioProfessorOrientacao(List<Professororientacao> lOrientacao, Date dtinicial,
        Date dtfinal, Professor coordenador, Campus campus) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FacesContext faces = FacesContext.getCurrentInstance();
    //pega o contexto da aplicacao
    String realPath = faces.getExternalContext().getRealPath("/");

    try {
        BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
        //----------------------------------------------------------------------
        //creation of the document with a certain size and certain margins
        //may want to use PageSize.LETTER instead
        Document document = new Document(PageSize.A4, 40, 40, 20, 50);
        document.addAuthor("SisGES"); // optional
        document.addSubject("Relatrio"); // opcional
        document.addKeywords("SisGES");
        document.addCreator("iText");
        //----------------------------------------------------------------------
        // creation of the different writers
        //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setBoxSize("header", new Rectangle(36, 54, 559, 788));
        //----------------------------------------------------------------------
        // ADICIONA HEADER E FOOTER
        //----------------------------------------------------------------------
        HeaderFooter headerFooter = new HeaderFooter();
        headerFooter.setY(760f);
        writer.setPageEvent(headerFooter);
        //----------------------------------------------------------------------
        //ABRE DOCUMENTO PARA ESCRITA
        //----------------------------------------------------------------------
        document.open();
        //----------------------------------------------------------------------
        //ADICIONAR LOGO NO DOCUMENTO
        //----------------------------------------------------------------------
        Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFUAta.png");
        logoUfu.scaleAbsolute(155, 39);//(largura,altura)
        logoUfu.isImgTemplate(); //add no template
        document.add(logoUfu);

        //----------------------------------------------------------------------
        //ADICIONAR CABEALHO
        //----------------------------------------------------------------------
        PdfContentByte univ = writer.getDirectContentUnder();
        univ.beginText();
        univ.setFontAndSize(fHelvetica, 10);
        univ.setTextMatrix(349, 816); // x e y
        univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        univ.setTextMatrix(405, 802); // x e y
        univ.showText("FACULDADE DE COMPUTAO");
        univ.setTextMatrix(403, 788); // x e y
        univ.showText("COORDENADORIA DE ESTGIO ");
        univ.endText();

        String info = "Campus Universitrio - " + campus.getNomecampus() + " - CEP " + campus.getCep() + " - "
                + campus.getCidade() + " - " + campus.getEstadosigla().toUpperCase();

        Chunk txtCampus = new Chunk(info);
        Paragraph paragraph0 = new Paragraph();
        paragraph0.setSpacingBefore(-10);
        paragraph0.setFont(new Font(fHelvetica, 7));
        paragraph0.add(txtCampus);
        paragraph0.setAlignment(Element.ALIGN_RIGHT);
        document.add(paragraph0);

        info = "Telefone: " + coordenador.getTelefone() + "   Email: " + coordenador.getEmail();
        Chunk txtCoordenador = new Chunk(info);
        Paragraph paragraph1 = new Paragraph();
        paragraph1.setSpacingBefore(-5);
        paragraph1.setSpacingAfter(10);
        paragraph1.setFont(new Font(fHelvetica, 7));
        paragraph1.add(txtCoordenador);
        paragraph1.setAlignment(Element.ALIGN_RIGHT);
        document.add(paragraph1);

        //            PdfContentByte univ = writer.getDirectContentUnder();
        //            univ.beginText();
        //            univ.setFontAndSize(fHelvetica, 12);
        //            univ.setTextMatrix(200, 815); // x e y
        //            univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        //            univ.setTextMatrix(235, 800); // x e y
        //            univ.showText("FACULDADE DE COMPUTAO");
        //            univ.endText();
        //
        //            PdfContentByte univEnd = writer.getDirectContentUnder();
        //            univEnd.beginText();
        //            univEnd.setFontAndSize(fHelvetica, 7);
        //            univEnd.setTextMatrix(210, 785); // x e y
        //            univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG");
        //            univEnd.setTextMatrix(260, 775); // x e y
        //            univEnd.showText("Telefone: (34)3239-4144 ou 3239-4393");
        //            univEnd.endText();
        //----------------------------------------------------------------------
        //ADICIONAR TITULO
        //----------------------------------------------------------------------
        PdfContentByte t1 = writer.getDirectContentUnder();
        t1.beginText();
        t1.setFontAndSize(fHelvetica, 14);
        t1.setTextMatrix(180, 730); // x e y
        t1.showText("Participao dos professores FACOM");
        t1.endText();

        PdfContentByte t2 = writer.getDirectContentUnder();
        t2.beginText();
        t2.setFontAndSize(fHelvetica, 12);
        t2.setTextMatrix(195, 705); // x e y
        String periodo = CalendarFormat.getDataBRtoDate(dtinicial) + " at "
                + CalendarFormat.getDataBRtoDate(dtfinal);
        t2.showText("Perodo: " + periodo);
        t2.endText();

        //----------------------------------------------------------------------
        //TABELA
        PdfPTable table = new PdfPTable(4);
        //espao do inicio da pagina
        table.setSpacingBefore(100f);
        table.setTotalWidth(100f);
        table.setWidthPercentage(100);
        float[] widths = { 20, 30, 35, 15 };//largura das colunas
        table.setWidths(widths);
        table.setHeaderRows(1);

        //CABEALHO DA TABELA
        Paragraph cabecalho = new Paragraph("Siape");
        PdfPCell cell1 = new PdfPCell(cabecalho); // celula
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell1);

        cabecalho = new Paragraph("Professor");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell2 = new PdfPCell(cabecalho); // celula
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell2.setBorderColor(BaseColor.LIGHT_GRAY);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell2);

        cabecalho = new Paragraph("Email do Professor");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell4 = new PdfPCell(cabecalho); // celula
        cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell4.setBorderColor(BaseColor.LIGHT_GRAY);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell4);

        cabecalho = new Paragraph("Orientaes");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell3 = new PdfPCell(cabecalho); // celula
        cell3.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell3.setBorderColor(BaseColor.LIGHT_GRAY);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell3);

        for (int i = 0; i < lOrientacao.size(); i++) {
            Professororientacao po = lOrientacao.get(i);

            Paragraph texto = new Paragraph(String.valueOf(po.getSiape()));
            texto.getFont().setSize(8);
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell1);

            texto = new Paragraph(po.getNome());
            texto.getFont().setSize(8);
            cell2 = new PdfPCell(texto); // celula
            cell2.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell2);

            texto = new Paragraph(po.getEmail());
            texto.getFont().setSize(8);
            cell4 = new PdfPCell(texto); // celula
            cell4.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell4);

            texto = new Paragraph(String.valueOf(po.getOrientacoes()));
            texto.getFont().setSize(8);
            cell3 = new PdfPCell(texto); // celula
            cell3.setBorderColor(BaseColor.LIGHT_GRAY);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell3);

            switch (i % 2) {
            case 0:
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
                break;
            case 1:

                break;
            }
        }

        //add a tabela
        document.add(table);
        //-----------------------------------------------------
        // distancia do fim da pagina
        float y = 70f;
        float x = 160f;
        //-----------------------------------------------------
        //linha
        PdfContentByte linha = writer.getDirectContentUnder();
        linha.setLineWidth(1f); // mostrar linha
        linha.setGrayStroke(0.5f); // 0 = preto, 1 = branco
        linha.moveTo(x, y);
        linha.lineTo(450f, y); // ate onde a linha vai
        linha.stroke();
        //------------------------------------------------------
        //assinatura
        PdfContentByte a1 = writer.getDirectContentUnder();
        a1.beginText();
        a1.setFontAndSize(fHelvetica, 10);
        a1.setTextMatrix(x + 50, y - 15); // x e y
        a1.showText("Coordenao de Estgio Supervisionado");
        a1.endText();
        //------------------------------------------------------
        //assinatura
        PdfContentByte a2 = writer.getDirectContentUnder();
        a2.beginText();
        a2.setFontAndSize(fHelvetica, 10);
        a2.setTextMatrix(x + 50, y - 27); // x e y
        a2.showText("FACOM/UFU");
        a2.endText();
        //------------------------------------------------------

        //add nova pagina
        document.newPage();
        //close document
        document.close();
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioProfessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream com dados
    return baos;
}

From source file:reporteFertilizacion.ReporteResultadoLaboratorio.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w w. j a v a  2  s . c  o  m*/
 *
 * @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:ro.ldir.chartpackage.GarbagePackageBuilder.java

License:Open Source License

public void writePDF(OutputStream out)
        throws DocumentException, MalformedURLException, XPathExpressionException, IOException {
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, "Cp1250", BaseFont.NOT_EMBEDDED);
    final Font hfFont = new Font(bf, 8, Font.NORMAL, BaseColor.GRAY);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    writer.setPageEvent(new PdfPageEventHelper() {
        private int page = 0;

        @Override//from   w  w w  . j  av  a2s  .c  o m
        public void onEndPage(PdfWriter writer, Document arg1) {
            page++;
            Rectangle rect = writer.getBoxSize("art");
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("Pachet mormane - \u00a9 Let's Do It, Romania!", hfFont),
                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 18, 0);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("- " + page + " -", hfFont), (rect.getLeft() + rect.getRight()) / 2,
                    rect.getBottom() - 18, 0);
        }
    });

    document.open();
    document.addAuthor("Let's Do It, Romania!");
    document.addTitle("Pachet mormane");
    document.addCreationDate();

    Font titleFont = new Font(bf, 24, Font.BOLD);
    Font noteFont = new Font(bf, 12, Font.NORMAL, BaseColor.RED);
    Font headerFont = new Font(bf, 12, Font.BOLD);
    Font normalFont = new Font(bf, 11);
    Font defFont = new Font(bf, 11, Font.BOLD);
    Paragraph par;
    int page = 0;

    for (Garbage garbage : garbages) {
        par = new Paragraph();
        par.setAlignment(Element.ALIGN_CENTER);
        par.add(new Chunk("Morman " + garbage.getGarbageId() + "\n", titleFont));
        par.add(new Chunk("Citi\u0163i cu aten\u0163ie!", noteFont));
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("1. Date generale\n", headerFont));
        par.add(new Chunk("Jude\u0163ul: ", defFont));
        par.add(new Chunk(garbage.getCounty().getName() + "\n", normalFont));
        par.add(new Chunk("Comuna: ", defFont));
        par.add(new Chunk(garbage.getTown().getName() + "\n", normalFont));
        if (garbage.getChartedArea() != null) {
            par.add(new Chunk("Zona cartare: ", defFont));
            par.add(new Chunk(garbage.getChartedArea().getName() + "\n", normalFont));
        }
        par.add(new Chunk("Pozi\u0163ie: ", defFont));
        par.add(new Chunk(garbage.getY() + ", " + garbage.getX() + "\n", normalFont));
        par.add(new Chunk("Descriere:\n", defFont));
        par.add(new Phrase(garbage.getDescription() + "\n", normalFont));
        par.add(new Chunk("Componen\u0163\u0103 gunoi:\n", defFont));
        List list = new List();
        list.add(new ListItem(
                new Chunk("Procent plastic: " + garbage.getPercentagePlastic() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent sticl\u0103: " + garbage.getPercentageGlass() + "%", normalFont)));
        list.add(new ListItem(new Chunk("Procent metale: " + garbage.getPercentageMetal() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent nereciclabile: " + garbage.getPercentageWaste() + "%", normalFont)));
        par.add(list);
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("2. Indica\u0163ii rutiere\n", headerFont));
        Image img = Image.getInstance(getImage(garbage));
        img.scaleToFit((float) (PageSize.A4.getWidth() * .75), (float) (PageSize.A4.getHeight() * .75));
        img.setAlignment(Element.ALIGN_CENTER);
        par.add(img);
        document.add(par);

        if (page < garbages.size() - 1)
            document.newPage();
        page++;
    }

    document.close();
}

From source file:Servlets.PDF.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/pdf");
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {//from  w w w .j  a v a  2  s  . c  om
        //obtengo datos de cliente,  reserva y total
        String rreserva = request.getParameter("reserva");
        String rcliente = request.getParameter("cliente");
        String rtotal = request.getParameter("total");
        //String rtipo = request.getParameter("esProv");

        // Obtener datos de cliente e items de reserva
        DtUsuario dtu = getDtUsuario(rcliente);
        String nombre = dtu.getNombre();
        String apellido = dtu.getApellido();
        String servicios = "";
        String promos = "";
        java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems();
        Iterator<DtItemReserva> iter = dtItems.iterator();
        DtItemReserva dtItem;

        // Crear y abrir documento

        String HomeDeUSuario = System.getProperty("user.home");

        String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf";

        FileOutputStream archivo = new FileOutputStream(ruta);

        PdfWriter writer = PdfWriter.getInstance(document, archivo);

        document.open();

        Date date = new Date();

        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String fecha = dateFormat.format(date);

        // Agregar marcador inicial

        // Crear y agregar prrafo simple
        Paragraph paragraph1 = new Paragraph();
        Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png");
        imagen.scaleAbsolute(200f, 200f);

        imagen.setAbsolutePosition(10, 650);
        imagen.setSpacingAfter(20);
        paragraph1.add(imagen);
        document.add(paragraph1);
        //fecha
        Paragraph fecha1 = new Paragraph(fecha);

        //encabezado
        Paragraph futuros = new Paragraph("Futuros Tecnologos SRL");
        Paragraph rut = new Paragraph("RUT 123456789012");
        Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629");
        Paragraph telefono = new Paragraph(" Tel: 555-5412");
        Paragraph nombre_empresa = new Paragraph(" Help4Travelling");

        //datos cliente
        String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase();
        String direccioncliente = " ";
        String rutcliente = "consumidor final".toUpperCase();
        Paragraph cliente = new Paragraph("Cliente: " + nombrecliente);
        Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente);
        Paragraph rutcli = new Paragraph("RUT: " + rutcliente);

        //datos boleta

        String factura = rreserva;
        Paragraph tipodoc = new Paragraph("Contado");
        Paragraph Nfac = new Paragraph(" N  " + factura);

        //alineaciones

        //fecha 
        fecha1.setAlignment(Element.ALIGN_RIGHT);

        //encabezado
        futuros.setAlignment(Element.ALIGN_CENTER);
        rut.setAlignment(Element.ALIGN_CENTER);
        direccion.setAlignment(Element.ALIGN_CENTER);
        telefono.setAlignment(Element.ALIGN_CENTER);

        //nombre empresa
        nombre_empresa.setAlignment(Element.ALIGN_LEFT);
        nombre_empresa.setSpacingBefore(10);
        nombre_empresa.setSpacingAfter(30);

        //datos de boleta
        tipodoc.setAlignment(Element.ALIGN_RIGHT);
        Nfac.setAlignment(Element.ALIGN_RIGHT);

        document.add(fecha1);
        document.add(futuros);
        document.add(rut);
        document.add(direccion);
        document.add(telefono);
        document.add(nombre_empresa);
        document.add(tipodoc);
        document.add(Nfac);
        document.add(cliente);
        document.add(dircliente);
        document.add(rutcli);

        PdfPTable tabla = new PdfPTable(4);
        tabla.setSpacingBefore(25);
        tabla.setSpacingAfter(25);

        //creo encabezado de tabla
        PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase()));
        PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase()));
        PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase()));
        PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase()));

        tabla.setHeaderRows(1);
        tabla.setWidthPercentage(100f);

        //alineamos las frases del cabezal
        codigo.setHorizontalAlignment(Element.ALIGN_CENTER);
        descripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
        ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
        eprecio.setHorizontalAlignment(Element.ALIGN_CENTER);

        //agrego cabezal de tabla
        tabla.addCell(codigo);
        tabla.addCell(descripcion);
        tabla.addCell(ecantidad);
        tabla.addCell(eprecio);

        //obtengo datos de la reserva para imprimir las distintas rows

        while (iter.hasNext()) {
            dtItem = iter.next();
            Integer cantidad = dtItem.getCantidad();
            String oferta = dtItem.getOferta().getNombre();
            String precio;
            String proveedor;
            if (existeServicio(oferta)) {
                proveedor = getNkProveedorServicio(oferta);
                DtServicio dts = getDtServicio(oferta, proveedor);
                precio = String.valueOf(dts.getPrecio());
            } else {
                proveedor = getNkProveedorPromocion(oferta);
                DtPromocion dtp = getDTPromocion(oferta, proveedor);
                precio = dtp.getDescuento();
            }
            /*  String item = "<li>Nombre: <em>" + oferta + "</em>"
                + " - Cantidad: <em>" + cantidad + "</em>"
                + " - $:<em>" + precio + "</em>"
                + " - Proveedor: <em>" + proveedor + "</em></li>";*/
            //creo encabezado de tabla
            PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase()));

            PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString()));
            PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase()));

            tabla.setHeaderRows(1);

            //alineamos las frases del cabezal
            iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER);
            icantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
            iprecio.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(iproveedor);
            if (existeServicio(oferta)) {
                PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            } else {
                PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            }
            tabla.addCell(icantidad);
            tabla.addCell(iprecio);
        }

        /*      // las distintas rows de los articulos
              tabla.addCell(proveedor);
              tabla.addCell(oferta);
              tabla.addCell(cantidad);
              tabla.addCell(precio);
        */
        //el ulimo de la tabla que da el total

        PdfPCell celdaFinal = new PdfPCell(new Paragraph(""));
        PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:"));
        PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal));
        // Indicamos cuantas columnas ocupa la celda
        celdaFinal.setColspan(2);

        celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);

        tabla.addCell(celdaFinal);
        tabla.addCell(celdaTotal);
        tabla.addCell(celdaPrecioTotal);
        document.add(tabla);
        document.close();
        if (request.getParameter("dispositivo").equals("true"))
            response.sendRedirect("Movil.Reservas.jsp");
        else
            response.sendRedirect("Usuario.jsp");
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:util.ImageExample.java

public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress,
        int totalPrice, String comments, boolean kunde) throws Exception {
    this.date = date;
    this.settings = settings;
    this.courses = courses;
    this.time = time;
    this.eventAddress = eventAddress;
    this.totalPrice = totalPrice;
    this.comments = comments;
    this.fileName = "";
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();// w ww . j  a  va  2 s  .com
    FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded");
    Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102));
    Document document = new Document();

    System.out.println("Pdf creation startet");
    try {
        if (kunde) {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf";
        } else {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime())
                    + "Prisliste.pdf";
        }

        FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName));
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        Image img = Image.getInstance("src/pictures/cirkles.png");
        img.scaleToFit(277, 277);
        img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight());
        document.add(img);
        Chunk chunk = new Chunk("Grillmester 'Frankie'", font);
        chunk.setCharacterSpacing(3);
        Paragraph header = new Paragraph(chunk);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setSpacingBefore(15);
        document.add(header);
        Paragraph title = new Paragraph(
                "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".",
                new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD));
        title.setAlignment(Element.ALIGN_LEFT);
        title.setIndentationLeft(235);
        title.setSpacingBefore(100);
        title.setLeading(17);
        document.add(title);
        Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC));
        subtitle.setAlignment(Element.ALIGN_LEFT);
        subtitle.setIndentationLeft(235);
        subtitle.setLeading(17);
        document.add(subtitle);
        Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18));
        body.setAlignment(Element.ALIGN_LEFT);
        body.setIndentationLeft(235);
        body.setLeading(17);
        for (String course : courses) {
            body.add(course + "\n\n");
        }
        body.add("\nServeres klokken " + time + " i " + eventAddress + ".");
        document.add(body);
        Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        ending.setAlignment(Element.ALIGN_LEFT);
        ending.setIndentationLeft(235);
        ending.setLeading(17);
        document.add(ending);
        if (!comments.equals("null")) {
            if (!comments.equals("")) {
                Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments,
                        new Font(Font.FontFamily.TIMES_ROMAN, 18));
                comment.setAlignment(Element.ALIGN_LEFT);
                comment.setIndentationLeft(235);
                comment.setLeading(17);
                document.add(comment);
            }
        }

        Image footerImg = Image.getInstance("src/pictures/grillmester.png");
        footerImg.scaleToFit(210, 210);
        footerImg.setAbsolutePosition(40, 40);
        document.add(footerImg);

        Image img2 = Image.getInstance("src/pictures/Contact.png");
        img2.scaleToFit(250, 250);
        img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250);
        document.add(img2);

        document.close();

        System.out.println("Pdf finish");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getLocalizedMessage());
    }
}

From source file:utilities.itext.Turnover.java

public static void createTurnOver(String title, StatisticType type, Date from, Date to) {
    Document document = new Document();
    try {/* w w w  .  ja  va 2s  . co m*/
        PdfWriter.getInstance(document, new FileOutputStream("text.pdf"));

        document.open();

        Paragraph headline = new Paragraph("Umsatzstatistik von: " + title, Fonts.DOCUMENTHEADLINE);
        headline.setAlignment(Element.ALIGN_CENTER);
        document.add(headline);

        HashMap<String, BigDecimal> expenseData = null;
        if (type.equals(StatisticType.CATEGORY)) {
            expenseData = db.getTotalExpensesByCategory(from, to);
        }

        Paragraph tables = createTablesWithoutDetails(expenseData);
        tables.setSpacingBefore(30f);
        document.add(tables);

        //            document.add(createPieChart(expenseData, "Ausgaben"));
        Category cat = bl.getBillCategoryByName("Elektrogerte");

        document.add(createTablesWithDetails(bl.getPaymentPositionsByCategory(cat, from, to)));

        document.close();
        System.exit(0);
    } catch (Exception ex) {
        Logger.getLogger(Turnover.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithDetails(ArrayList<PaymentPosition> data) throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 5f, 1f };
    expense.setWidths(colWidths);/*  ww  w .j a v  a2s.co m*/

    int lastPaymentID = 0;
    for (PaymentPosition pp : data) {
        if (lastPaymentID != pp.getPayment().getId()) {
            //new Payment
            Paragraph p1 = new Paragraph(pp.getPayment().getPayee().getName());
            PdfPCell c1 = new PdfPCell(p1);

            //add next cell with price
            //calc price
            BigDecimal totalPrice = new BigDecimal(BigInteger.ZERO);
            for (PaymentPosition payPos : data) {
                if (payPos.getPayment().getId() == pp.getPayment().getId()) {
                    totalPrice = totalPrice.add(payPos.getTotalPrice());
                }
            }
            Paragraph p2 = new Paragraph(totalPrice.toPlainString());
            PdfPCell c2 = new PdfPCell(p2);

            c1.setBorder(Rectangle.NO_BORDER);
            c1.setBorderWidthTop(0.5f);
            c2.setBorder(Rectangle.NO_BORDER);
            c2.setBorderWidthTop(0.5f);

            expense.addCell(c1);
            expense.addCell(c2);
        }

        //payment position
        Paragraph p1 = new Paragraph("            " + pp.getQuantity() + "x: " + pp.getArticle().getName());
        PdfPCell c1 = new PdfPCell(p1);

        //add next cell with price
        Paragraph p2 = new Paragraph(pp.getTotalPriceAsString());
        PdfPCell c2 = new PdfPCell(p2);

        c1.setBorder(Rectangle.NO_BORDER);
        c2.setBorder(Rectangle.NO_BORDER);

        expense.addCell(c1);
        expense.addCell(c2);

        lastPaymentID = pp.getPayment().getId();
    }

    paragraph.add(expense);

    paragraph.setSpacingBefore(10f);

    return paragraph;
}

From source file:utils.pdf.cv_templates.Template1.java

private void addPersonalInformation(User user) throws DocumentException {

    Paragraph paragraph;
    PdfPCell cell;//from ww  w .j ava 2  s  . c  om
    PdfPTable table;
    table = new PdfPTable(new float[] { 0.5f, 2f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.name + " " + user.surnames, font1);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.birthDate + "\n", font4);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph("Calle " + user.residenceAddress + " N " + user.residenceNumber + " "
            + user.residenceZipCode + " " + user.residenceCity + "\n", font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.phoneNumber, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.email, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    document.add(table);
}

From source file:utils.pdf.cv_templates.Template2.java

private void addPersonalInformation(User user) throws DocumentException {

    Paragraph paragraph;
    PdfPCell cell;//from www  . ja  v  a2s  .  c  o  m
    PdfPTable table;
    table = new PdfPTable(new float[] { 0.5f, 2f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.name.toUpperCase() + " " + user.surnames.toUpperCase(), font1);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.birthDate + "\n", font2);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.phoneNumber, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.email, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);
    if (!user.drivingLicense.equals("No tengo carnet")) {
        paragraph = new Paragraph("\nPermiso de conducir: " + user.drivingLicense, font2);
        paragraph.setAlignment(paragraph.ALIGN_LEFT);
        cell.addElement(paragraph);
    }

    table.addCell(cell);

    document.add(table);
}

From source file:utils.pdf.cv_templates.Template3.java

private void addPersonalInformation(User user) throws DocumentException, IOException {
    Paragraph paragraph;
    PdfPCell cell;/*from   ww  w .j ava2 s. com*/
    PdfPTable table;
    Image photo_img;
    if (!user.photo.id.equals("")) {
        photo_img = Image
                .getInstance(String.format("https://s3.amazonaws.com/aunclickdelempleo2/" + user.photo.id));
    } else {
        photo_img = Image.getInstance(String.format("public/images/orientation/photo/ic_profile.png"));
    }

    table = new PdfPTable(new float[] { 3, 7 });
    table.setWidthPercentage(100);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingRight(15);
    cell.setPaddingLeft(50);
    cell.setPaddingTop(30);

    photo_img.setBorder(Image.BOX);
    photo_img.setBorderColor(BaseColor.WHITE);
    photo_img.scaleToFit(1000, 115);

    cell.addElement(photo_img);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setPaddingLeft(55);
    cell.setPaddingTop(19);
    cell.setBorder(PdfPCell.NO_BORDER);

    paragraph = new Paragraph("Datos Personales", font1);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    cell.addElement(paragraph);

    paragraph = new Paragraph(user.name + " " + user.surnames, font2);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    paragraph.setSpacingBefore(8);
    cell.addElement(paragraph);

    paragraph = new Paragraph(user.birthDate, font3);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    cell.addElement(paragraph);

    paragraph = new Paragraph("Calle " + user.residenceAddress + ", N " + user.residenceNumber + ", Ciudad "
            + user.residenceCity, font3);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    cell.addElement(paragraph);

    paragraph = new Paragraph("Telfono: " + user.phoneNumber, font3);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    cell.addElement(paragraph);

    paragraph = new Paragraph(user.email, font3);
    paragraph.setAlignment(paragraph.ALIGN_LEFT);
    cell.addElement(paragraph);

    if (!user.drivingLicense.equals("No tengo carnet")) {
        paragraph = new Paragraph("Permiso de conducir: " + user.drivingLicense, font3);
        paragraph.setAlignment(paragraph.ALIGN_LEFT);
        paragraph.setSpacingBefore(10);
        cell.addElement(paragraph);
    }

    table.addCell(cell);
    document.add(table);
}