Example usage for com.itextpdf.text.pdf PdfContentByte setFontAndSize

List of usage examples for com.itextpdf.text.pdf PdfContentByte setFontAndSize

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte setFontAndSize.

Prototype

public void setFontAndSize(final BaseFont bf, final float size) 

Source Link

Document

Set the font and the size for the subsequent text writing.

Usage

From source file:Report.RelatorioCurso.java

/**
 * Funo para gerar o stream do relatrio anual de atividades
 *
 * @param proforiseparada//from   www.j  a  v  a 2  s  .  c o  m
 * @param sm
 * @param sa
 * @param am
 * @param aa
 * @param dtinicial
 * @param dtfinal
 * @param ano
 * @param cursoNome
 * @param coordenador
 * @param campus
 * @return ByteArrayOutputStream
 */
public ByteArrayOutputStream relatorioAnualDeAtividades(ArrayList<Professororientacaoseparada> proforiseparada,
        ArrayList<Sumariomatricula> sm, ArrayList<Sumarioaprovado> sa, ArrayList<Alunomatriculado> am,
        ArrayList<Alunoaprovado> aa, Date dtinicial, Date dtfinal, String ano, String cursoNome,
        Professor coordenador, Campus campus) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FacesContext faces = FacesContext.getCurrentInstance();
    // pega o contexto da aplicacao
    realPath = faces.getExternalContext().getRealPath("/");
    //realPath = "C:/Users/Alessandro/Desktop/TCC2/SisGES/build/web";

    try {
        BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
        BaseFont fHelveticaBOLD = BaseFont.createFont(BaseFont.HELVETICA_BOLD, "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();
        writer.setPageEvent(headerFooter);
        //----------------------------------------------------------------------
        // ABRE DOCUMENTO PARA ESCRITA
        //----------------------------------------------------------------------
        document.open();
        //----------------------------------------------------------------------
        //ADICIONAR LOGO NO DOCUMENTO
        //----------------------------------------------------------------------
        Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFU.png");
        logoUfu.scaleAbsolute(57, 56);//(largura,altura)
        logoUfu.isImgTemplate(); //add no template
        //logoUfu.setAbsolutePosition(30, 745); //x ,y por referencia do rodape
        document.add(logoUfu);

        Image logoFacom = Image.getInstance(realPath + "/resources/images/logoFacom.png");
        logoFacom.scaleAbsolute(62, 55);//(largura,altura)
        logoFacom.setAbsolutePosition(92, 767); //x ,y por referencia do rodape
        //logoFacom.isImgTemplate(); //add no template
        document.add(logoFacom);

        //----------------------------------------------------------------------
        //ADICIONAR CABEALHO
        //----------------------------------------------------------------------
        PdfContentByte univ = writer.getDirectContentUnder();
        univ.beginText();
        univ.setFontAndSize(fHelvetica, 10);
        univ.setTextMatrix(349, 805); // x e y
        univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        univ.setTextMatrix(405, 790); // x e y
        univ.showText("FACULDADE DE COMPUTAO");
        univ.setTextMatrix(403, 775); // 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);

        //----------------------------------------------------------------------
        //ADICIONAR TITULO
        //----------------------------------------------------------------------
        PdfContentByte t1 = writer.getDirectContentUnder();
        t1.beginText();
        t1.setFontAndSize(fHelveticaBOLD, 12);
        t1.setTextMatrix(175, 700); // x e y
        t1.showText("RELATRIO ANUAL DE ATIVIDADES - " + ano);
        t1.endText();

        PdfContentByte t2 = writer.getDirectContentUnder();
        t2.beginText();
        t2.setFontAndSize(fHelveticaBOLD, 12);
        t2.setTextMatrix(160, 680); // x e y
        if (cursoNome.contains("sistema") || cursoNome.contains("Sistemas") || cursoNome.contains("Sistema")) {
            t2.showText("BACHARELADO EM SISTEMAS DE INFORMAO");
            cursoNome = "Sistemas de Informao";
        } else if (cursoNome.contains("cincia") || cursoNome.contains("Cincias")
                || cursoNome.contains("Cincia")) {
            t2.showText("BACHARELADO EM CINCIA DA COMPUTAO");
            cursoNome = "Cincia da Computao";
        } else {
            t2.showText("BACHARELADO EM " + cursoNome.toUpperCase());
        }
        t2.endText();

        Paragraph p0 = new Paragraph("1. Introduo");
        p0.setSpacingBefore(95);
        p0.getFont().setStyle(Font.BOLD);
        p0.getFont().setSize(12);
        document.add(p0);

        //----------------------------------------------------------------------
        String textoIntro = "Este documento tem o objetivo de apresentar as atividades da coordenao de estgio "
                + "supervisionado da Faculdade de Computao da Universidade Federal de Uberlndia. As principais "
                + "atividades desenvolvidas foram:";

        Chunk chunk1 = new Chunk(textoIntro);
        Paragraph paragraph = new Paragraph();
        paragraph.setSpacingBefore(20);
        paragraph.setSpacingAfter(10);
        paragraph.setFont(new Font(fHelvetica, 12));
        paragraph.add(chunk1);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph);

        //lista
        List overview = new List(false, 10);
        overview.setAutoindent(true);
        overview.add("Aprovao dos documentos de matricula do estgio supervisionado;");
        overview.add("Alocao de professores orientadores de estgio;");
        overview.add(
                "Matrcula de alunos do curso de " + cursoNome + " na disciplina de estgio supervisionado;");
        overview.add("Acompanhamento das atividades do estagirio na empresa;");
        overview.add("Aprovao do Relatrio parcial/final do estagirio.");
        document.add(overview);

        String textoIntro2 = "Os resultados das atividades listadas so apresentados nas prximas sees.";

        Chunk chunk2 = new Chunk(textoIntro2);
        Paragraph paragraph2 = new Paragraph();
        paragraph2.setSpacingBefore(10);
        paragraph2.setSpacingAfter(10);
        paragraph2.setFont(new Font(fHelvetica, 12));
        paragraph2.add(chunk2);
        paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph2);

        Paragraph p01 = new Paragraph("2. Sumrio das Atividades");
        p01.setSpacingBefore(5);
        p01.getFont().setStyle(Font.BOLD);
        p01.getFont().setSize(12);
        document.add(p01);

        //----------------------------------------------------------------------
        //FAZER SUMARIO
        //----------------------------------------------------------------------
        PdfPTable tabelaSumario = new PdfPTable(4);
        tabelaSumario.setTotalWidth(100f);
        tabelaSumario.setWidthPercentage(100);
        float[] widths = { 40, 20, 20, 20 };//largura das colunas
        tabelaSumario.setWidths(widths);
        tabelaSumario.setHeaderRows(1);

        Paragraph l1 = new Paragraph(" ");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        PdfPCell cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.WHITE);
        cell1.setBorderColor(BaseColor.WHITE);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaSumario.addCell(cell1);

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

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

        l1 = new Paragraph("Reprovaes");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        PdfPCell cell4 = new PdfPCell(l1); // celula
        cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell4.setBorderColor(BaseColor.LIGHT_GRAY);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaSumario.addCell(cell4);

        int i = 0;
        for (Sumariomatricula m : sm) {
            Sumarioaprovado a = sa.get(i);

            Paragraph texto = new Paragraph(m.getTipoestagio());
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            texto.getFont().setSize(8);
            tabelaSumario.addCell(cell1);

            if (m.getMatriculas() != null) {
                texto = new Paragraph(String.valueOf(m.getMatriculas()));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaSumario.addCell(cell1);
            } else {
                texto = new Paragraph(String.valueOf(0));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaSumario.addCell(cell1);
            }

            if (m.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")
                    && a.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")) {
                if (a.getAprovados() != null) {
                    //aprovados
                    texto = new Paragraph(String.valueOf(a.getAprovados()));
                    cell1 = new PdfPCell(texto); // celula
                    cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    texto.getFont().setSize(8);
                    tabelaSumario.addCell(cell1);
                } else {
                    texto = new Paragraph(String.valueOf(0));
                    cell1 = new PdfPCell(texto); // celula
                    cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    texto.getFont().setSize(8);
                    tabelaSumario.addCell(cell1);
                }

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

            } else if (m.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio")
                    && a.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio")) {

                if (a.getAprovados() != null) {
                    //aprovados
                    texto = new Paragraph(String.valueOf(a.getAprovados()));
                    cell1 = new PdfPCell(texto); // celula
                    cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    texto.getFont().setSize(8);
                    tabelaSumario.addCell(cell1);
                } else {
                    texto = new Paragraph(String.valueOf(0));
                    cell1 = new PdfPCell(texto); // celula
                    cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    texto.getFont().setSize(8);
                    tabelaSumario.addCell(cell1);
                }

                //reprovados
                texto = new Paragraph(String.valueOf(0));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaSumario.addCell(cell1);
            }
            i++;
        }
        tabelaSumario.setSpacingBefore(20);
        tabelaSumario.setSpacingAfter(20);
        tabelaSumario.completeRow();

        document.add(tabelaSumario);

        //----------------------------------------------------------------------
        //ALUNOS MATRICULADOS
        //----------------------------------------------------------------------
        Paragraph p1 = new Paragraph("3. Alunos Matriculados");
        p1.setSpacingBefore(5);
        p1.getFont().setStyle(Font.BOLD);
        p1.getFont().setSize(12);
        document.add(p1);

        p01 = new Paragraph("Estgio Obrigatrio");
        p01.setSpacingBefore(5);
        p01.getFont().setStyle(Font.BOLD);
        p01.getFont().setSize(10);
        document.add(p01);

        //----------------------------------------------------------------------
        //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO OBRIGATORIO
        //----------------------------------------------------------------------
        PdfPTable tabelaAlunoMatriculadoEO = new PdfPTable(4);
        tabelaAlunoMatriculadoEO.setTotalWidth(100f);
        tabelaAlunoMatriculadoEO.setWidthPercentage(100);
        float[] widthsEO = { 20, 30, 30, 20 };//largura das colunas
        tabelaAlunoMatriculadoEO.setWidths(widthsEO);
        tabelaAlunoMatriculadoEO.setHeaderRows(1);

        l1 = new Paragraph("Matrculas");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoEO.addCell(cell1);

        l1 = new Paragraph("Nome");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoEO.addCell(cell1);

        l1 = new Paragraph("Orientador");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoEO.addCell(cell1);

        l1 = new Paragraph("Data de Matrcula");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoEO.addCell(cell1);

        for (int j = 0; j < am.size(); j++) {
            Alunomatriculado amat = am.get(j);
            if (amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")
                    || amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio")
                    || amat.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) {

                Paragraph texto = new Paragraph(amat.getMatricula());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoEO.addCell(cell1);

                texto = new Paragraph(amat.getNome());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoEO.addCell(cell1);

                texto = new Paragraph(amat.getOrientador());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoEO.addCell(cell1);

                texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula()));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoEO.addCell(cell1);
            }
        }

        tabelaAlunoMatriculadoEO.setSpacingBefore(20);
        tabelaAlunoMatriculadoEO.setSpacingAfter(20);
        tabelaAlunoMatriculadoEO.completeRow();

        document.add(tabelaAlunoMatriculadoEO);

        //----------------------------------------------------------------------
        //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO NO OBRIGATORIO
        //----------------------------------------------------------------------
        p01 = new Paragraph("Estgio No Obrigatrio");
        p01.setSpacingBefore(5);
        p01.getFont().setStyle(Font.BOLD);
        p01.getFont().setSize(10);
        document.add(p01);

        PdfPTable tabelaAlunoMatriculadoENO = new PdfPTable(4);
        tabelaAlunoMatriculadoENO.setTotalWidth(100f);
        tabelaAlunoMatriculadoENO.setWidthPercentage(100);
        float[] widthsENO = { 20, 30, 30, 20 };//largura das colunas
        tabelaAlunoMatriculadoENO.setWidths(widthsENO);
        tabelaAlunoMatriculadoENO.setHeaderRows(1);

        l1 = new Paragraph("Matrculas");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoENO.addCell(cell1);

        l1 = new Paragraph("Nome");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoENO.addCell(cell1);

        l1 = new Paragraph("Orientador");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoENO.addCell(cell1);

        l1 = new Paragraph("Data de Matrcula");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoMatriculadoENO.addCell(cell1);

        for (int k = 0; k < am.size(); k++) {
            Alunomatriculado amat = am.get(k);

            if (amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio")
                    || amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatorio")
                    || amat.getTipoestagio().equalsIgnoreCase("Estagio No Obrigatorio")) {

                Paragraph texto = new Paragraph(amat.getMatricula());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoENO.addCell(cell1);

                texto = new Paragraph(amat.getNome());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoENO.addCell(cell1);

                texto = new Paragraph(amat.getOrientador());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoENO.addCell(cell1);

                texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula()));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoMatriculadoENO.addCell(cell1);
            }

        }

        tabelaAlunoMatriculadoENO.setSpacingBefore(20);
        tabelaAlunoMatriculadoENO.setSpacingAfter(20);
        tabelaAlunoMatriculadoENO.completeRow();

        document.add(tabelaAlunoMatriculadoENO);

        //add nova pagina
        //document.newPage();
        //----------------------------------------------------------------------
        //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO
        //----------------------------------------------------------------------
        p1 = new Paragraph("4. Alunos Aprovados em Estgio Obrigatrio");
        p1.setSpacingBefore(20);
        p1.getFont().setStyle(Font.BOLD);
        p1.getFont().setSize(12);
        document.add(p1);

        PdfPTable tabelaAlunoAprovadoEO = new PdfPTable(5);
        tabelaAlunoAprovadoEO.setTotalWidth(100f);
        tabelaAlunoAprovadoEO.setWidthPercentage(100);
        float[] widthsAprovadoEO = { 20, 30, 30, 10, 10 };//largura das colunas
        tabelaAlunoAprovadoEO.setWidths(widthsAprovadoEO);
        tabelaAlunoAprovadoEO.setHeaderRows(1);

        l1 = new Paragraph("Matrculas");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoAprovadoEO.addCell(cell1);

        l1 = new Paragraph("Nome");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoAprovadoEO.addCell(cell1);

        l1 = new Paragraph("Orientador");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoAprovadoEO.addCell(cell1);

        l1 = new Paragraph("Data de Matrcula");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoAprovadoEO.addCell(cell1);

        l1 = new Paragraph("Data de Finalizao");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaAlunoAprovadoEO.addCell(cell1);

        for (int t = 0; t < aa.size(); t++) {
            Alunoaprovado aprov = aa.get(t);

            if (aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")
                    || aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio")
                    || aprov.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) {

                Paragraph texto = new Paragraph(aprov.getMatricula());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoAprovadoEO.addCell(cell1);

                texto = new Paragraph(aprov.getNome());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoAprovadoEO.addCell(cell1);

                texto = new Paragraph(aprov.getOrientador());
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoAprovadoEO.addCell(cell1);

                texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatamatricula()));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoAprovadoEO.addCell(cell1);

                texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatafinalizacao()));
                cell1 = new PdfPCell(texto); // celula
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                texto.getFont().setSize(8);
                tabelaAlunoAprovadoEO.addCell(cell1);
            }
        }

        tabelaAlunoAprovadoEO.setSpacingBefore(20);
        tabelaAlunoAprovadoEO.setSpacingAfter(20);
        tabelaAlunoAprovadoEO.completeRow();

        document.add(tabelaAlunoAprovadoEO);

        //----------------------------------------------------------------------
        //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO
        //----------------------------------------------------------------------
        p1 = new Paragraph("5. Participao dos professores FACOM");
        p1.setSpacingBefore(20);
        p1.getFont().setStyle(Font.BOLD);
        p1.getFont().setSize(12);
        document.add(p1);

        //
        PdfPTable tabelaProfOriSeparada = new PdfPTable(3);
        tabelaProfOriSeparada.setTotalWidth(100f);
        tabelaProfOriSeparada.setWidthPercentage(100);
        float[] widths0 = { 60, 20, 20 };//largura das colunas
        tabelaProfOriSeparada.setWidths(widths0);
        tabelaProfOriSeparada.setHeaderRows(1);

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

        l1 = new Paragraph("Orientaes Estgio Obrigatrio");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaProfOriSeparada.addCell(cell1);

        l1 = new Paragraph("Orientaes Estgio No Obrigatrio");
        l1.getFont().setStyle(Font.BOLD);
        l1.getFont().setSize(8);
        cell1 = new PdfPCell(l1); // celula
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabelaProfOriSeparada.addCell(cell1);

        for (int ii = 0; ii < proforiseparada.size(); ii++) {

            Professororientacaoseparada profoe = proforiseparada.get(ii);

            Paragraph texto = new Paragraph(profoe.getNome());
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            texto.getFont().setSize(8);
            tabelaProfOriSeparada.addCell(cell1);

            texto = new Paragraph(profoe.getOrientacoesestobrigatorio().toString());
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            texto.getFont().setSize(8);
            tabelaProfOriSeparada.addCell(cell1);

            texto = new Paragraph(profoe.getOrientacoesestnaoobrigatorio().toString());
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            texto.getFont().setSize(8);
            tabelaProfOriSeparada.addCell(cell1);

        }

        tabelaProfOriSeparada.setSpacingBefore(20);
        tabelaProfOriSeparada.setSpacingAfter(20);
        tabelaProfOriSeparada.completeRow();
        document.add(tabelaProfOriSeparada);

        //----------------------------------------------------------------------
        p1 = new Paragraph("6. Observaes e Consideraes Finais");
        p1.setSpacingBefore(20);
        p1.getFont().setStyle(Font.BOLD);
        p1.getFont().setSize(12);
        document.add(p1);

        String text6 = "O processo de matrcula, acompanhamento, composio de bancas e "
                + "defesas ocorreu sem nenhum problema ou acontecimento excepcional.";

        chunk1 = new Chunk(text6);
        paragraph = new Paragraph();
        paragraph.setSpacingBefore(20);
        paragraph.setSpacingAfter(10);
        paragraph.setFont(new Font(fHelvetica, 12));
        paragraph.add(chunk1);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        //-----------------------------------------------------
        Paragraph paragraphCab = new Paragraph();
        paragraphCab.setSpacingBefore(25);
        paragraphCab.add("Uberlndia, " + CalendarFormat.getDataPorExtenso(CalendarFormat.getDataSO()) + ".");
        paragraphCab.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraphCab);
        document.add(Chunk.NEWLINE);
        //-----------------------------------------------------
        // distancia do fim da pagina
        float y = 120f;
        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 a0 = writer.getDirectContentUnder();
        a0.beginText();
        a0.setFontAndSize(fHelvetica, 10);
        a0.setTextMatrix(x + 50, y - 15); // x e y
        a0.showText("Prof. " + coordenador.getNome());
        a0.endText();
        PdfContentByte a1 = writer.getDirectContentUnder();
        a1.beginText();
        a1.setFontAndSize(fHelvetica, 10);
        a1.setTextMatrix(x + 50, y - 30); // 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 - 45); // x e y
        a2.showText("SIAPE: " + coordenador.getSiape());
        a2.endText();
        //----------------------------------------------------------------------
        //FIM DO DOCUMENTO
        //add nova pagina
        document.newPage();
        //close document
        document.close();
        //----------------------------------------------------------------------
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream
    return baos;
}

From source file:Report.RelatorioProfessor.java

/**
 * Funo para gerar o stream do relatorio de orientaes por professor
 *
 * @param lOrientacao/*from w  w  w . jav a  2s .  co  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:ryerson.daspub.artifact.PublishQRTagSheetTask.java

License:Open Source License

/**
 * Draw a text label on the current page.
 * @param Writer PDF writer/*w  ww . ja  v a  2s . c om*/
 * @param Text
 * @param x
 * @param y
 * @param alignment
 * @throws DocumentException
 * @throws IOException 
 */
private void drawLabel(PdfWriter Writer, String Text, int x, int y, int alignment)
        throws DocumentException, IOException {
    PdfContentByte cb = Writer.getDirectContent();
    BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb.saveState();
    cb.beginText();
    cb.setFontAndSize(bf, 9);
    cb.showTextAligned(alignment, Text, x, y, 0);
    cb.endText();
    cb.restoreState();
}

From source file:ryerson.daspub.artifact.PublishQRTagSheetTask.java

License:Open Source License

/**
 * Draw a line on the page//from  ww w .  j a v a 2s.  c  om
 * @param Writer
 * @param x1 Line start, X coordinate
 * @param y1 Line start, Y coordinate
 * @param x2 Line end, X coordinate
 * @param y2 Line end, Y coordinate
 * @param t Stroke thickness
 */
private static void drawLine(PdfWriter Writer, int x1, int y1, int x2, int y2, float t)
        throws DocumentException, IOException {
    PdfContentByte cb = Writer.getDirectContent();
    cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 24); // TODO why do we have this here??
    cb.moveTo(x1, y1);
    cb.lineTo(x2, y2);
    cb.setLineWidth(t);
    cb.stroke();
}

From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java

License:Open Source License

protected void createSignatureNotRequiredField(PdfStamper pdfStamper, int lastPage)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    addOverlay = pdfStamper.getOverContent(lastPage);
    addOverlay.saveState();//from  w ww.j a v a  2  s.c  o  m
    addOverlay.setColorFill(SIGNATURE_NOT_REQUIRED_COLOR);
    addOverlay.setColorStroke(CMYKColor.BLACK);
    addOverlay.rectangle(SIGNATURE_NOT_REQUIRED_START_X, SIGNATURE_NOT_REQUIRED_START_Y,
            SIGNATURE_NOT_REQUIRED_WIDTH, SIGNATURE_NOT_REQUIRED_HEIGHT);
    addOverlay.setLineWidth(LINE_WIDTH);
    addOverlay.fillStroke();
    addOverlay.restoreState();
    // Do text
    addOverlay = pdfStamper.getOverContent(lastPage);
    addOverlay.saveState();
    BaseFont bf = BaseFont.createFont();
    addOverlay.beginText();
    addOverlay.setFontAndSize(bf, SIGNATURE_NOT_REQUIRED_FONT_SIZE);
    addOverlay.setTextMatrix(SIGNATURE_NOT_REQUIRED_START_X + SIGNATURE_NOT_REQUIRED_PADDING_LEFT,
            SIGNATURE_NOT_REQUIRED_START_Y + SIGNATURE_NOT_REQUIRED_PADDING_BOTTOM);
    addOverlay.showText(SIGNATURE_NOT_REQUIRED_TEXT);
    addOverlay.endText();
    addOverlay.restoreState();
}

From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java

License:Open Source License

protected void createRightMarginText(PdfStamper pdfStamper, int numberOfPages, String id, String text)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    BaseFont bf = BaseFont.createFont();
    // Do text/* www .java2 s. c om*/
    for (int i = 1; i <= numberOfPages; i++) {
        addOverlay = pdfStamper.getOverContent(i);
        addOverlay.saveState();
        addOverlay.beginText();
        addOverlay.setFontAndSize(bf, MARGIN_TEXT_FONTSIZE);
        addOverlay.setTextMatrix(0, 1, -1, 0, MARGIN_TEXT_START_X, MARGIN_TEXT_START_Y);
        addOverlay.showText(String.format("Intygs-ID: %s. %s", id, text));
        addOverlay.endText();
        addOverlay.restoreState();
    }
}

From source file:se.inera.intyg.intygstyper.ts_bas.pdf.PdfGeneratorImpl.java

License:Open Source License

private void createLeftMarginText(PdfStamper pdfStamper, int numberOfPages, String id, String text)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    BaseFont bf = BaseFont.createFont();
    // Do text//from   ww w .  ja va 2  s  . co  m
    for (int i = 1; i <= numberOfPages; i++) {
        addOverlay = pdfStamper.getOverContent(i);
        addOverlay.saveState();
        addOverlay.beginText();
        addOverlay.setFontAndSize(bf, MARGIN_TEXT_FONTSIZE);
        addOverlay.setTextMatrix(0, 1, -1, 0, MARGIN_TEXT_START_X, MARGIN_TEXT_START_Y);
        addOverlay.showText(String.format("Intygs-ID: %s. %s", id, text));
        addOverlay.endText();
        addOverlay.restoreState();
    }
}

From source file:Servicios.SmLogistics.java

private void b_pago_formatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pago_formatoActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {// w w  w  .jav  a 2 s . c o m
        Orden ord = (Orden) session.get(Orden.class, orden_act.getIdOrden());
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);

        String formato = "PagoAXA.pdf";//ord.getCompania().getFormatoPago();
        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();

        PdfReader reader = new PdfReader("imagenes/" + formato);
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();

        cb.beginText();
        //IMAGEN
        try {
            Image img = Image.getInstance("imagenes/" + con.getLogo());
            img.setAbsolutePosition(25, 710);
            img.scaleAbsoluteWidth(75);
            img.scaleAbsoluteHeight(50);
            cb.addImage(img, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Image img_1 = Image.getInstance(ord.getCompania().getFoto());
            img_1.setAbsolutePosition(500, 735);
            img_1.scaleAbsoluteWidth(80);
            img_1.scaleAbsoluteHeight(50);
            cb.addImage(img_1, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Foto foto = (Foto) session.createCriteria(Foto.class)
                .add(Restrictions.eq("orden.idOrden", orden_act.getIdOrden())).addOrder(Order.desc("fecha"))
                .setMaxResults(1).uniqueResult();
        if (foto != null) {
            try {
                Image img_2 = Image
                        .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + foto.getDescripcion());
                img_2.setAbsolutePosition(480, 558);
                img_2.scaleAbsoluteWidth(90);
                img_2.scaleAbsoluteHeight(50);
                cb.addImage(img_2, true);
            } catch (Exception e) {
            }
        }

        //NOMBRE DEL TALLER
        if (con.getEmpresa() != null)
            fdfDoc.setField("NombreEmpresa", con.getEmpresa());

        //DIRECCION DEL TALLER 
        String direccion = "";
        if (con.getDireccion() != null)
            direccion += con.getDireccion() + " ";
        if (con.getNo() != null)
            direccion += con.getNo() + " ";
        if (con.getColonia() != null)
            direccion += con.getColonia();
        direccion = direccion.toUpperCase();
        fdfDoc.setField("DireccionEmpresa", direccion);

        //Municipio, Estado, CP
        String municipio = "";
        if (con.getMunicipio() != null)
            municipio += con.getMunicipio() + " ";
        if (con.getEstado() != null)
            municipio += con.getEstado() + " ";
        if (con.getCp() != null)
            municipio += con.getCp();
        municipio = municipio.toUpperCase();
        fdfDoc.setField("ColoniaEmpresa", municipio);

        //Pagina Web y Telefonos
        fdfDoc.setField("SitioEmpresa", "tracto.ddns.net");
        fdfDoc.setField("TelefonoEmpresa", "(722) 199 24 04 / 275 19 45");

        //Datos de la compaia
        fdfDoc.setField("Aseguradora1", ord.getCompania().getSocial());
        if (ord.getCompania().getDireccion() != null)
            fdfDoc.setField("Aseguradora2", ord.getCompania().getDireccion());
        if (ord.getCompania().getColonia() != null)
            fdfDoc.setField("Aseguradora3", ord.getCompania().getColonia());
        /*if(ord.getCompania().getComentarios()!=null)
            fdfDoc.setField("Extra", ord.getCompania().getComentarios());*/

        //Orden de trabajo
        fdfDoc.setField("Orden", "" + ord.getIdOrden());

        //FECHA INGRESO
        if (ord.getFecha() != null)
            fdfDoc.setField("FechaRecepcion", ord.getFecha().toString());

        //Marca
        fdfDoc.setField("Marca", ord.getMarca().getMarcaNombre());

        //Tipo
        fdfDoc.setField("Modelo", "" + ord.getTipo().getTipoNombre());

        //Placas
        if (ord.getNoPlacas() != null)
            fdfDoc.setField("Placas", "" + ord.getNoPlacas());

        //Poliza
        if (ord.getPoliza() != null)
            fdfDoc.setField("Poliza", "" + ord.getPoliza());

        //Siniestro
        if (ord.getSiniestro() != null)
            fdfDoc.setField("Siniestro", "" + ord.getSiniestro());

        //Datos cliente
        if (ord.getClientes() != null) {
            fdfDoc.setField("Nombre", ord.getClientes().getNombre());
            if (ord.getClientes().getContacto() != null)
                fdfDoc.setField("Contacto", ord.getClientes().getContacto());
        }

        //Datos de atencion a clientes
        fdfDoc.setField("Tel1", "722 299 240 25");
        fdfDoc.setField("Id1", "52*167862*13");
        fdfDoc.setField("Email1", "atencionaclientes@tractoservicio.com");
        fdfDoc.setField("Wat1", "722 299 240 25");

        float tam[] = new float[] { 160, 80, 130, 170 };
        Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
        PDF reporte = new PDF();
        PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT);
        tabla.setTotalWidth(tam);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;

        if (formato.compareToIgnoreCase("PagoAXA.pdf") != 0) {
            tabla.addCell(reporte.celda("BANCO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NO CONVENIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("N DE CUENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(
                    reporte.celda("NOMBRE DE LA COMPAIA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            Cuenta[] cuentas = (Cuenta[]) ord.getCompania().getCuentas().toArray(new Cuenta[0]);
            if (cuentas.length > 0) {
                for (int i = 0; i < cuentas.length; i++) {
                    tabla.addCell(reporte.celda(cuentas[i].getBanco(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getConvenio().toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getTransferencia(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getNombre(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                }
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 40, 420, cb);
        }
        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);

        cb.setTextMatrix(160, 466);
        BaseFont bf = BaseFont.createFont();
        cb.setFontAndSize(bf, 9);
        cb.showText("" + formatoPorcentaje.format(orden_act.getDeducible()));

        cb.setTextMatrix(450, 466);
        cb.showText("" + formatoPorcentaje.format(orden_act.getDemerito()));
        cb.endText();

        stamp.close();
        reporte.cerrar();
        reporte.visualizar2("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf");

    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java

License:Open Source License

public String imprimirTicket() {
    try {/*from w ww . ja va 2 s . com*/

        BaseColor colorBlack = new BaseColor(0, 0, 0);

        BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252,
                BaseFont.NOT_EMBEDDED);
        BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy");

        Rectangle pageSize = new Rectangle(210, 210);

        Document document = new Document(pageSize);
        document.addTitle(getI18N().getText("etiqueta.reserva.title"));

        ByteArrayOutputStream os = new ByteArrayOutputStream();

        PdfWriter pdfWriter = PdfWriter.getInstance(document, os);
        document.open();

        PdfContentByte pdfContent = pdfWriter.getDirectContent();

        InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties()
                .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY));

        byte[] arrImage = new byte[4096];
        is.read(arrImage);

        Image img = Image.getInstance(arrImage);

        img.scaleAbsolute(100, 30);
        img.setAbsolutePosition(55, 170);
        document.add(img);

        //Dibujo primer lnea
        LineSeparator line = new LineSeparator();
        line.setAlignment(LineSeparator.ALIGN_CENTER);
        line.setLineColor(colorBlack);
        line.setLineWidth(0.5f);

        line.drawLine(pdfContent, 10, 200, 170);

        //Etiqueta RESERVA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, 15);
        pdfContent.setTextMatrix(45, 150);
        pdfContent.showText(getI18N().getText("etiqueta.reserva.showText"));
        pdfContent.endText();

        //Fecha de la reserva
        String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio());

        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, 16);
        pdfContent.setTextMatrix(130, 150);
        pdfContent.showText(fecha_reserva);
        pdfContent.endText();

        //Dibujo segunda lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140);

        int etiqHoraTamanio = 25;
        int etiqHoraX = 15;
        int etiqHoraY = 85;

        int valorHoraTamanio = 40;
        int valorHoraX = 105;
        int valorHoraY = 80;

        String serie = sesionMBean.getRecurso().getSerie();
        boolean conSerie = (serie != null) && (serie.length() >= 1);

        if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) {

            if (!conSerie) {
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 110;

                valorHoraTamanio = 30;
                valorHoraX = 120;
                valorHoraY = 107;

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 65);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 60);
                pdfContent.setTextMatrix(nro_pos, 55);
                pdfContent.showText(nro);
                pdfContent.endText();
            } else {
                //<<<<<< Agregado >>>>>>
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 123;

                valorHoraTamanio = 20;
                valorHoraX = 120;
                valorHoraY = 122;

                //Etiqueta SERIE
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 87);
                pdfContent.showText(getI18N().getText("etiqueta.numero.serie"));
                pdfContent.endText();

                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(120, 87);
                pdfContent.showText(serie);
                pdfContent.endText();

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 50);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 40);
                pdfContent.setTextMatrix(nro_pos, 47);
                pdfContent.showText(nro);
                pdfContent.endText();
            }
        }

        //Etiqueta HORA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio);
        pdfContent.setTextMatrix(etiqHoraX, etiqHoraY);
        pdfContent.showText(getI18N().getText("etiqueta.hora.hora"));
        pdfContent.endText();

        //Hora de la reserva
        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, valorHoraTamanio);
        pdfContent.setTextMatrix(valorHoraX, valorHoraY);
        pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio()));
        pdfContent.endText();

        //Dibujo tercer lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45);

        String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno();
        String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos();
        int largoEtiqUno = 0;
        int largoEtiqDos = 0;
        int xValores = 0;

        if (ticketEtiqUno != null) {
            largoEtiqUno = ticketEtiqUno.length();
        }

        if (ticketEtiqDos != null) {
            largoEtiqDos = ticketEtiqDos.length();
        }

        if (largoEtiqUno > largoEtiqDos) {
            xValores = 8 * (largoEtiqUno + 1);
        } else {
            xValores = 8 * (largoEtiqDos + 1);
        }

        //Etiqueta uno
        if (ticketEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 30);
            pdfContent.showText(ticketEtiqUno + ":");
            pdfContent.endText();
        }

        //Valor etiqueta uno
        String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno();
        if (valorEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 30);
            pdfContent.showText(valorEtiqUno);
            pdfContent.endText();
        }

        //Etiqueta dos

        if (ticketEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 15);
            pdfContent.showText(ticketEtiqDos + ":");
            pdfContent.endText();
        }

        //Valor etiqueta dos
        String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos();
        if (valorEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 15);
            pdfContent.showText(valorEtiqDos);
            pdfContent.endText();
        }

        pdfWriter.addJavaScript("this.print({bUI: true, bSilent: true, bShrinkToFit: true});", false);
        pdfWriter.addJavaScript("this.closeDoc(true);");

        document.close();

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        response.setContentType("application/pdf");

        os.writeTo(response.getOutputStream());

        response.getOutputStream().flush();
        response.getOutputStream().close();
        facesContext.responseComplete();

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

    return null;
}

From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java

License:Open Source License

public String guardarTicket() {
    try {/*w ww  .  j ava  2 s  . c o  m*/

        BaseColor colorBlack = new BaseColor(0, 0, 0);

        BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252,
                BaseFont.NOT_EMBEDDED);
        BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy");

        Rectangle pageSize = new Rectangle(210, 210);

        Document document = new Document(pageSize);
        document.addTitle(getI18N().getText("etiqueta.reserva.title"));

        ByteArrayOutputStream os = new ByteArrayOutputStream();

        PdfWriter pdfWriter = PdfWriter.getInstance(document, os);
        document.open();

        PdfContentByte pdfContent = pdfWriter.getDirectContent();

        InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties()
                .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY));

        byte[] arrImage = new byte[4096];
        is.read(arrImage);

        Image img = Image.getInstance(arrImage);

        img.scaleAbsolute(100, 30);
        img.setAbsolutePosition(55, 170);
        document.add(img);

        //Dibujo primer lnea
        LineSeparator line = new LineSeparator();
        line.setAlignment(LineSeparator.ALIGN_CENTER);
        line.setLineColor(colorBlack);
        line.setLineWidth(0.5f);

        line.drawLine(pdfContent, 10, 200, 170);

        //Etiqueta RESERVA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, 15);
        pdfContent.setTextMatrix(45, 150);
        pdfContent.showText(getI18N().getText("etiqueta.reserva.showText"));
        pdfContent.endText();

        //Fecha de la reserva
        String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio());

        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, 16);
        pdfContent.setTextMatrix(130, 150);
        pdfContent.showText(fecha_reserva);
        pdfContent.endText();

        //Dibujo segunda lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140);

        int etiqHoraTamanio = 25;
        int etiqHoraX = 15;
        int etiqHoraY = 85;

        int valorHoraTamanio = 40;
        int valorHoraX = 105;
        int valorHoraY = 80;

        String serie = sesionMBean.getRecurso().getSerie();
        boolean conSerie = (serie != null) && (serie.length() >= 1);

        if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) {

            if (!conSerie) {
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 110;

                valorHoraTamanio = 30;
                valorHoraX = 120;
                valorHoraY = 107;

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 65);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 60);
                pdfContent.setTextMatrix(nro_pos, 55);
                pdfContent.showText(nro);
                pdfContent.endText();
            } else {

                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 123;

                valorHoraTamanio = 20;
                valorHoraX = 120;
                valorHoraY = 122;

                //Etiqueta SERIE
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 87);
                pdfContent.showText(getI18N().getText("etiqueta.numero.serie"));
                pdfContent.endText();

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 20);
                pdfContent.setTextMatrix(120, 87);
                pdfContent.showText(serie);
                pdfContent.endText();

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 50);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 40);
                pdfContent.setTextMatrix(nro_pos, 47);
                pdfContent.showText(nro);
                pdfContent.endText();
            }
        }

        //Etiqueta HORA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio);
        pdfContent.setTextMatrix(etiqHoraX, etiqHoraY);
        pdfContent.showText(getI18N().getText("etiqueta.hora.hora"));
        pdfContent.endText();

        //Hora de la reserva
        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, valorHoraTamanio);
        pdfContent.setTextMatrix(valorHoraX, valorHoraY);
        pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio()));
        pdfContent.endText();

        //Dibujo tercer lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45);

        String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno();
        String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos();
        int largoEtiqUno = 0;
        int largoEtiqDos = 0;
        int xValores = 0;

        if (ticketEtiqUno != null) {
            largoEtiqUno = ticketEtiqUno.length();
        }

        if (ticketEtiqDos != null) {
            largoEtiqDos = ticketEtiqDos.length();
        }

        if (largoEtiqUno > largoEtiqDos) {
            xValores = 8 * (largoEtiqUno + 1);
        } else {
            xValores = 8 * (largoEtiqDos + 1);
        }

        //Etiqueta uno
        if (ticketEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 30);
            pdfContent.showText(ticketEtiqUno + ":");
            pdfContent.endText();
        }

        //Valor etiqueta uno
        String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno();
        if (valorEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 30);
            pdfContent.showText(valorEtiqUno);
            pdfContent.endText();
        }

        //Etiqueta dos
        if (ticketEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 15);
            pdfContent.showText(ticketEtiqDos + ":");
            pdfContent.endText();
        }

        //Valor etiqueta dos
        String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos();
        if (valorEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 15);
            pdfContent.showText(valorEtiqDos);
            pdfContent.endText();
        }

        document.close();

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "attachment; filename=" + "Ticket de confirmacin.pdf");

        os.writeTo(response.getOutputStream());

        response.getOutputStream().flush();
        response.getOutputStream().close();
        facesContext.responseComplete();

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

    return null;
}