Example usage for com.itextpdf.text Rectangle Rectangle

List of usage examples for com.itextpdf.text Rectangle Rectangle

Introduction

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

Prototype

public Rectangle(final float llx, final float lly, final float urx, final float ury) 

Source Link

Document

Constructs a Rectangle -object.

Usage

From source file:PDF.Reportes.java

public void reportesPDF(HttpServletResponse response, int tr, ServletContext d, String usuario, String contra,
        String horario, int opc) {
    String reporteT = "";
    try {/*from   w ww  . j  a  v a 2  s  . c  o  m*/

        Document reporte = new Document();
        Calendar cal = Calendar.getInstance();

        Paragraph intro = new Paragraph();
        intro.setAlignment(Element.ALIGN_CENTER);

        String linea = "/Imagenes/rallita.png";
        String absolute_url_linea = d.getRealPath(linea);

        Image linea_div = Image.getInstance(absolute_url_linea);

        Paragraph vacio = new Paragraph("  ", FontFactory.getFont("arial", 10));
        vacio.setAlignment(Element.ALIGN_CENTER);

        if (tr == 0) {
            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png");
            writer.setPageEvent(event);
            reporte.open();
            reporte.add(vacio);
            reporte.add(vacio);
            ArrayList<JFreeChart> graf = grafica(usuario, contra);
            if (graf == null) {

                intro = new Paragraph(
                        "Lo sentimos, por el momento an no existe informacin para este reporte.",
                        FontFactory.getFont("arial", 18));

                reporte.add(intro);
            } else {
                for (int i = 0; i < graf.size(); i++) {
                    BufferedImage bufferedImage = graf.get(i).createBufferedImage(500, 300);
                    Image chart = Image.getInstance(writer, bufferedImage, 1.0f);
                    reporte.add(vacio);
                    reporte.add(chart);
                }
            }
            reporteT = "Estadsticas de registros.";
        }
        if (tr == 1) {
            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png");
            writer.setPageEvent(event);
            reporte.open();
            reporte.add(linea_div);
            Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n"
                    + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas",
                    FontFactory.getFont("arial", 10));
            reporte.add(creador);
            reporte.add(linea_div);
            intro = new Paragraph("Sin alta en CENEVAL " + cal.get(Calendar.YEAR),
                    FontFactory.getFont("arial", 18));
            intro.setAlignment(Element.ALIGN_CENTER);
            reporte.add(intro);
            reporte.add(vacio);
            reporte.add(vacio);
            reporte.add(noaltaCen(usuario, contra));
            reporteT = "Sin alta en CENEVAL.";
        }
        if (tr == 2) {
            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png");
            writer.setPageEvent(event);
            reporte.open();
            reporte.add(linea_div);
            Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n"
                    + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas",
                    FontFactory.getFont("arial", 10));
            reporte.add(creador);
            reporte.add(linea_div);
            intro = new Paragraph("Estatus Prefichas " + cal.get(Calendar.YEAR),
                    FontFactory.getFont("arial", 18));
            intro.setAlignment(Element.ALIGN_CENTER);
            reporte.add(intro);
            reporte.add(vacio);
            reporte.add(vacio);

            reporte.add(statusfichas(usuario, contra));
            reporteT = "Estatus prefichas";
        }
        if (tr == 3) {
            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png");
            writer.setPageEvent(event);
            reporte.open();
            reporte.add(linea_div);
            Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n"
                    + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas",
                    FontFactory.getFont("arial", 10));
            reporte.add(creador);
            reporte.add(linea_div);
            intro = new Paragraph("Pre proceso concluido " + cal.get(Calendar.YEAR),
                    FontFactory.getFont("arial", 18));
            intro.setAlignment(Element.ALIGN_CENTER);
            reporte.add(intro);
            reporte.add(vacio);
            reporte.add(vacio);
            reporte.add(procesoCon(usuario, contra));
            reporteT = "Pre proceso concluido";
        }
        if (tr == 4) {

            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            ArrayList<PdfPTable> tables = firmasAspAula(usuario, contra, horario, opc);
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png");
            writer.setPageEvent(event);
            reporte.open();

            if (tables.size() != 1) {
                PdfPTable tableH = tables.get(tables.size() - 1);
                tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent());
            } else {
                reporte.add(tables.get(0));
            }
            reporte.add(vacio);

            reporte.add(vacio);
            reporte.add(vacio);
            for (int i = 0; i < tables.size(); i++) {

                if (i + 1 != tables.size()) {

                    reporte.add(tables.get(i));
                    if (i + 2 != tables.size()) {
                        reporte.newPage();
                    }
                }

            }

            reporteT = "Firmas Aspirantes_" + horario;

        }
        if (tr == 5) {

            PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream());
            ArrayList<PdfPTable> tables = tablaAspAula(usuario, contra, horario, opc);
            Rectangle rect = new Rectangle(30, 30, 550, 800);
            writer.setBoxSize("art", rect);
            HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png");
            writer.setPageEvent(event);
            reporte.open();
            if (tables.size() != 1) {
                PdfPTable tableH = tables.get(tables.size() - 1);
                tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent());
            } else {
                reporte.add(tables.get(0));
            }

            reporte.add(vacio);

            reporte.add(vacio);
            reporte.add(vacio);
            for (int i = 0; i < tables.size(); i++) {

                if (i + 1 != tables.size()) {

                    reporte.add(tables.get(i));
                    if (i + 2 != tables.size()) {
                        reporte.newPage();
                    }
                }

            }

            reporteT = "Aspirantes por aula horario_" + horario;

        }

        reporte.addTitle("Reportes_" + reporteT);
        reporte.addSubject("Instituto Tecnolgico de Toluca");
        reporte.addKeywords("Instituto Tecnolgico de Toluca");
        reporte.addAuthor("Coordinacion de desarrollo de sistemas");
        reporte.addCreator("Centro de Cmputo ITT");

        //Asignamos el manejador de eventos al escritor.
        reporte.close();

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

From source file:pdf.Sign.java

License:Open Source License

private String doSignPdf(String pdfFile, String pdfFileSigned) {
    try {//from  www. j a  v a2s  . co m
        PdfReader reader = new PdfReader(pdfFile);
        FileOutputStream fout = new FileOutputStream(pdfFileSigned);
        PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
        PdfSignatureAppearance sap = stp.getSignatureAppearance();
        sap.setCrypto(null, _chain, null, PdfSignatureAppearance.SELF_SIGNED);
        sap.setReason("Declaratie unica");
        sap.setVisibleSignature(new Rectangle(500, 775, 600, 675), 1, null);
        sap.setExternalDigest(
                new byte[((RSAPublicKey) _certAlias._cert.getPublicKey()).getModulus().bitLength() / 8], null,
                "RSA");
        sap.preClose();
        byte[] content = streamToByteArray(sap.getRangeStream());
        Signature signature = Signature.getInstance("SHA1withRSA", _etpkcs11);
        signature.initSign((PrivateKey) _privateKey);
        signature.update(content);
        byte[] signatureBytes = signature.sign();
        // Self-Sign mode
        PdfPKCS7 sig = sap.getSigStandard().getSigner();
        sig.setExternalDigest(signatureBytes, null, "RSA");
        PdfDictionary dic = new PdfDictionary();
        dic.put(PdfName.CONTENTS, new PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
        sap.close(dic);
    } catch (FileNotFoundException ex) {
        return ex.toString();
    } catch (ProviderException ex) {
        if (ex.getMessage().equals("Initialization failed")) {
            return ex.toString()
                    + " (Probabil aveti un alt tip de SmartCard conectat. Deconectati alte tipuri de SmartCarduri (daca exista) si folositi optiunea \"*autoDetect\")";
        } else if (ex.getMessage().equals("Error parsing configuration")) {
            return ex.toString()
                    + " (Calea catre driverul SmartCardului (care se afla inscrisa in fisierul .cfg corespunzator acestuia) contine unul din urmatoarele caractere: \"~()\". Solutie: Copiati continutul intregului folder in alta locatie si modificati corespunzator calea din fisierul .cfg. (vezi si http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6581254))";
        }
        return ex.toString();
    } catch (NoSuchAlgorithmException ex) {
        return ex.toString();
    } catch (IOException ex) {
        return ex.toString();
    } catch (DocumentException ex) {
        return ex.toString();
    } catch (InvalidKeyException ex) {
        return ex.toString();
    } catch (SignatureException ex) {
        return ex.toString();
    } catch (Throwable ex) {
        return ex.toString();
    } finally {
        //wwww: eliminare key pt a putea introduce un nou pin
        //            String str = pin.getPassword().toString();
        //            pin.destroy();
        //            Security.removeProvider(_etpkcs11.getName());//"SunPKCS11-SmartCard");
        //wwww
    }
    return "";
}

From source file:Project.data.preparation.ExtractPageContentArea.java

public void parsePdf(String pdf, int pageNum, int upper_x, int upper_y, int lower_x, int lower_y)
        throws IOException {
    PdfReader reader = new PdfReader(pdf);
    //        System.out.println("(" + upper_x + " , " + upper_y + ") to ( " + lower_x + " , " + lower_y + ")");
    rect = new Rectangle(upper_x, upper_y, lower_x, lower_y);
    RenderFilter filter = new RegionTextRenderFilter(getRect());
    TextExtractionStrategy strategy;/*  ww  w  .  j a  v a2 s  .co  m*/
    strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter);
    TextCropped = PdfTextExtractor.getTextFromPage(reader, pageNum, strategy);
    setTextCropped(TextCropped);
    reader.close();
}

From source file:Report.RelatorioAluno.java

/**
 * funcao para gerar o stream do relatorio
 *
 * @return ByteArrayOutputStream//from  ww  w .  ja va2 s.  c o  m
 */
public ByteArrayOutputStream relatorioAlunosMatriculados() {

    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);

        //----------------------------------------------------------------------
        // 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();

        PdfContentByte univEnd = writer.getDirectContentUnder();
        univEnd.beginText();
        univEnd.setFontAndSize(fHelvetica, 7);
        univEnd.setTextMatrix(326, 761); // x e y
        univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG");
        univEnd.setTextMatrix(432, 750); // x e y
        univEnd.showText("Telefone: (34) 3239-4144 ou 3239-4393");
        univEnd.endText();

        //----------------------------------------------------------------------
        //ADICIONAR TITULO
        //----------------------------------------------------------------------
        PdfContentByte titulo = writer.getDirectContentUnder();
        titulo.beginText();
        titulo.setFontAndSize(fHelvetica, 16);
        titulo.setTextMatrix(210, 700); // x e y
        titulo.showText("Alunos Matrculados");
        titulo.endText();
        //----------------------------------------------------------------------

        //----------------------------------------------------------------------
        AlunoDAO aDAO = new AlunoDAO();
        List<Aluno> allAlunos = aDAO.getAllAlunos();
        aDAO.closeSession();

        PdfPTable table = new PdfPTable(5);

        table.setTotalWidth(100f);
        table.setWidthPercentage(100);
        float[] widths = { 10, 30, 30, 13, 17 };//largura das colunas
        table.setWidths(widths);
        table.setHeaderRows(1);

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

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

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

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

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

        for (int i = 0; i < allAlunos.size(); i++) {
            Aluno aluno = allAlunos.get(i);
            Paragraph texto = new Paragraph(aluno.getMatricula());
            cellMatricula = new PdfPCell(texto); // celula
            cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
            texto.getFont().setSize(8);
            table.addCell(cellMatricula);
            texto = new Paragraph(aluno.getNome());
            texto.getFont().setSize(8);
            cellNome = new PdfPCell(texto); // celula
            cellNome.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellNome);
            texto = new Paragraph(aluno.getEmail());
            texto.getFont().setSize(8);
            cellEmail = new PdfPCell(texto); // celula
            cellEmail.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellEmail);
            texto = new Paragraph(aluno.getTelefone());
            texto.getFont().setSize(8);
            cellTelefone = new PdfPCell(texto); // celula
            cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellTelefone);
            texto = new Paragraph(aluno.getCursoidcurso().getNomecurso());
            texto.getFont().setSize(8);
            cellCurso = new PdfPCell(texto); // celula
            cellCurso.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellCurso);

        }
        table.setSpacingBefore(100);
        table.setSpacingAfter(10);
        table.completeRow();

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

From source file:Report.RelatorioBanca.java

/**
 * funcao para gerar o stream do relatorio
 *
 * @param banca// w  w w .  j  ava  2s.  c  o m
 * @param listaConvidados
 * @param coordenador
 * @param campus
 * @return ByteArrayOutputStream
 */
public ByteArrayOutputStream relatorioAtaDeDefesa(Banca banca, List<Convidado> listaConvidados,
        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 curso = writer.getDirectContentUnder();
        curso.beginText();
        curso.setFontAndSize(fHelvetica, 14);
        curso.setTextMatrix(140, 720); // x e y
        String cursoAluno;
        //curso.showText("Curso de Bacharelado em Cincia da Computao");
        cursoAluno = banca.getTrabalhoidtrabalho().getAlunomatricula().getCursoidcurso().getNomecurso();
        if (cursoAluno.contains("sistema")) {
            cursoAluno = "Bacharelado em Sistemas de Informao";
        } else {
            cursoAluno = "Bacharelado em Cincia da Computao";
        }

        curso.showText("Curso de " + cursoAluno);
        curso.endText();

        PdfContentByte titulo = writer.getDirectContentUnder();
        titulo.beginText();
        titulo.setFontAndSize(fHelvetica, 12);
        titulo.setTextMatrix(160, 660); // x e y
        titulo.showText("Ata de Defesa de Trabalho de Estgio Supervisionado");
        titulo.endText();
        //----------------------------------------------------------------------]
        String texto = "Ata da ___________ de defesa de Trabalho de Estgio Supervisionado, do Curso de Bacharelado "
                + "em Cincia da Computao, realizada em "
                + CalendarFormat.getDataBRtoDate(banca.getDatabanca()) + ", na " + banca.getLocalbanca()
                + ", s " + CalendarFormat.parseDateToTimeString(banca.getHorario()) + " horas, pelo aluno "
                + banca.getTrabalhoidtrabalho().getAlunomatricula().getNome() + " ("
                + banca.getTrabalhoidtrabalho().getAlunomatricula().getMatricula() + "). O trabalho "
                + "intitulado \"" + banca.getTrabalhoidtrabalho().getTitulo()
                + "\" foi apresentado pelo aluno em sesso pblica "
                + "com cerca de 1 hora de durao. Na ocasio, o aluno foi arguido oralmente pelos membros "
                + "da banca, sendo considerado ________________________ (aprovado/reprovado).";

        Chunk chunk1 = new Chunk(texto);
        Paragraph paragraph = new Paragraph();
        paragraph.setFont(new Font(fHelvetica, 12));
        paragraph.setSpacingBefore(170);
        paragraph.add(chunk1);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph);

        document.add(Chunk.NEWLINE);
        texto = "Carga horria total do estgio: ____________ horas (preenchido pela coordenao de estgios)";
        Paragraph paragraph2 = new Paragraph();
        paragraph2.setSpacingBefore(15);
        paragraph2.setFont(new Font(fHelvetica, 10));
        paragraph2.add(texto);
        paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph2);
        document.add(Chunk.NEWLINE);

        Paragraph paragraph3 = new Paragraph();
        paragraph3.setSpacingBefore(25);
        paragraph3.add("Uberlndia, " + CalendarFormat.getDataPorExtenso(banca.getDatabanca()) + ".");
        paragraph3.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(paragraph3);
        document.add(Chunk.NEWLINE);
        //----------------------------------------------------------------------
        PdfContentByte tituloMembros = writer.getDirectContentUnder();
        tituloMembros.beginText();
        tituloMembros.setFontAndSize(fHelvetica, 12);
        tituloMembros.setTextMatrix(220, 350); // x e y
        tituloMembros.showText("Membros da Banca Examinadora");
        tituloMembros.endText();
        //----------------------------------------------------------------------
        float x = 160f;
        float y = 300f; // distancia do fim da pagina
        //retorna orientador
        //-----------------------------------------------------
        //linha
        PdfContentByte linhaOrientador = writer.getDirectContentUnder();
        linhaOrientador.setLineWidth(1f); // mostrar linha
        linhaOrientador.setGrayStroke(0.5f); // 0 = preto, 1 = branco
        linhaOrientador.moveTo(x, y);
        linhaOrientador.lineTo(450f, y); // ate onde a linha vai
        linhaOrientador.stroke();
        //------------------------------------------------------
        //nome orientador
        PdfContentByte orientador = writer.getDirectContentUnder();
        orientador.beginText();
        orientador.setFontAndSize(fHelvetica, 12);
        orientador.setTextMatrix(x, y - 20); // x e y
        orientador.showText("Prof.Orientador - " + banca.getTrabalhoidtrabalho().getProfessorsiape().getNome());
        orientador.setTextMatrix(x, y - 35); // x e y
        orientador.showText("Presidente da banca");
        orientador.endText();

        y = y - 100;
        //retorna convidados
        for (int i = 0; i < listaConvidados.size(); i++) {
            Convidado convidado = listaConvidados.get(i);
            if (convidado.getConfirmado() == true) {
                //-----------------------------------------------------
                //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();
                //------------------------------------------------------
                //nome convidado

                PdfContentByte conv = writer.getDirectContentUnder();
                conv.beginText();
                conv.setFontAndSize(fHelvetica, 12);
                conv.setTextMatrix(x, y - 20); // x e y
                conv.showText("Prof.Convidado - " + convidado.getProfessorsiape().getNome());
                conv.endText();
                //------------------------------------------------------
                y = y - 80;
            }
        }
        //add nova pagina
        document.newPage();
        //close document
        document.close();
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioBanca.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream
    return baos;
}

From source file:Report.RelatorioBanca.java

/**
 * funcao para gerar o stream do relatorio de participaes em banca
 *
 * @param prof/*from ww w.  ja va2s  .co m*/
 * @param listaOrientador
 * @param listaConvidado
 * @param dtinicial
 * @param dtfinal
 * @param coordenador
 * @param campus
 * @return ByteArrayOutputStream
 */
public ByteArrayOutputStream relatorioParticipacaoEmBanca(Professor prof, List<Banca> listaOrientador,
        List<Convidado> listaConvidado, 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(210, 735); // x e y
        t1.showText("Participao em Bancas");
        t1.endText();

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

        PdfContentByte t3 = writer.getDirectContentUnder();
        t3.beginText();
        t3.setFontAndSize(fHelvetica, 12);
        t3.setTextMatrix(40, 675); // x e y
        t3.showText("Professor: " + prof.getNome());
        t3.endText();
        //----------------------------------------------------------------------
        //TABELA
        PdfPTable table = new PdfPTable(6);
        //espao do inicio da pagina
        table.setSpacingBefore(100f);
        table.setTotalWidth(110f);
        table.setWidthPercentage(100);
        float[] widths = { 13, 25, 22, 18, 12, 10 };//largura das 2 colunas
        table.setWidths(widths);
        table.setHeaderRows(1);

        //CABEALHO DA TABELA
        Paragraph cabecalho = new Paragraph("Matricula do Aluno");
        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("Nome do Aluno");
        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("Ttulo do Trabalho");
        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);

        cabecalho = new Paragraph("Nome do Orientador");
        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("Papel do Professor");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell5 = new PdfPCell(cabecalho); // celula
        cell5.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell5.setBorderColor(BaseColor.LIGHT_GRAY);
        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell5);

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

        for (int i = 0; i < listaOrientador.size(); i++) {
            Banca b = listaOrientador.get(i);

            Paragraph texto = new Paragraph(b.getTrabalhoidtrabalho().getAlunomatricula().getMatricula());
            texto.getFont().setSize(8);
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell1);

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

            texto = new Paragraph(b.getTrabalhoidtrabalho().getTitulo());
            texto.getFont().setSize(8);
            cell3 = new PdfPCell(texto); // celula
            cell3.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell3);

            texto = new Paragraph(b.getTrabalhoidtrabalho().getProfessorsiape().getNome());
            texto.getFont().setSize(8);
            cell4 = new PdfPCell(texto); // celula
            cell4.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell4);

            texto = new Paragraph("Orientador");
            texto.getFont().setSize(8);
            cell5 = new PdfPCell(texto); // celula
            cell5.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell5);

            texto = new Paragraph(CalendarFormat.getDataBRtoDate(b.getDatabanca()));
            texto.getFont().setSize(8);
            cell6 = new PdfPCell(texto); // celula
            cell6.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell6);

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

                break;
            }

        }

        for (int i = 0; i < listaConvidado.size(); i++) {
            Convidado c = listaConvidado.get(i);

            Paragraph texto = new Paragraph(
                    c.getBancaidbanca().getTrabalhoidtrabalho().getAlunomatricula().getMatricula());
            texto.getFont().setSize(8);
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell1);

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

            texto = new Paragraph(c.getBancaidbanca().getTrabalhoidtrabalho().getTitulo());
            texto.getFont().setSize(8);
            cell3 = new PdfPCell(texto); // celula
            cell3.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell3);

            texto = new Paragraph(c.getBancaidbanca().getTrabalhoidtrabalho().getProfessorsiape().getNome());
            texto.getFont().setSize(8);
            cell4 = new PdfPCell(texto); // celula
            cell4.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell4);

            texto = new Paragraph("Convidado");
            texto.getFont().setSize(8);
            cell5 = new PdfPCell(texto); // celula
            cell5.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell5);

            texto = new Paragraph(CalendarFormat.getDataBRtoDate(c.getBancaidbanca().getDatabanca()));
            texto.getFont().setSize(8);
            cell6 = new PdfPCell(texto); // celula
            cell6.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell6);

        }
        //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();

        //----------------------------------------------------------------------
        /*String texto = "Ata da defesa de Trabalho de Estgio Supervisionado, do Curso de Bacharelado"
         + "em Cincia da Computao, realizada em " + CalendarFormat.getDataBRtoDate(banca.getDatabanca()) + ", na " + banca.getLocalbanca()
         + ", s " + CalendarFormat.parseDateToTimeString(banca.getHorario()) + " horas, pelo aluno " + banca.getTrabalhoidtrabalho().getAlunomatricula().getNome()
         + " (" + banca.getTrabalhoidtrabalho().getAlunomatricula().getMatricula() + "). O trabalho "
         + "intitulado \"" + banca.getTrabalhoidtrabalho().getTitulo() + "\" foi apresentado pelo aluno em sesso pblica "
         + "com cerca de 1 hora de durao. Na ocasio, o aluno foi arguido oralmente pelos membros "
         + "da banca, sendo considerado ________________________ (aprovado/reprovado).";
         */
        //Chunk chunk1 = new Chunk(texto);
        //Paragraph paragraph = new Paragraph();
        // paragraph.setSpacingBefore(180);
        //paragraph.add(chunk1);
        //paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        //document.add(paragraph);
        //document.add(Chunk.NEWLINE);
        //Paragraph paragraph2 = new Paragraph();
        //paragraph2.setSpacingBefore(25);
        //paragraph2.add("Uberlndia, " + CalendarFormat.getDataPorExtenso(banca.getDatabanca()) + ".");
        //paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        ///document.add(paragraph2);
        //document.add(Chunk.NEWLINE);
        //----------------------------------------------------------------------
        //----------------------------------------------------------------------
        //float x = 160f;
        //float y = 340f; // distancia do fim da pagina
        //retorna orientador
        //-----------------------------------------------------
        //linha
        //PdfContentByte linhaOrientador = writer.getDirectContentUnder();
        //linhaOrientador.setLineWidth(1f); // mostrar linha
        //linhaOrientador.setGrayStroke(0.5f); // 0 = preto, 1 = branco
        //linhaOrientador.moveTo(x, y);
        //linhaOrientador.lineTo(450f, y); // ate onde a linha vai
        //linhaOrientador.stroke();
        //------------------------------------------------------
        //nome orientador
        //PdfContentByte orientador = writer.getDirectContentUnder();
        //orientador.beginText();
        //orientador.setFontAndSize(fHelvetica, 12);
        //orientador.setTextMatrix(x, y - 20); // x e y
        //orientador.showText("Prof.Orientador - " + banca.getTrabalhoidtrabalho().getProfessorsiape().getNome());
        //orientador.setTextMatrix(x, y - 35); // x e y
        //orientador.showText("Presidente da banca");
        //orientador.endText();
        /*
         y = y - 100;
         //retorna convidados
         for (int i = 0; i < listaConvidados.size(); i++) {
         Convidado convidado = listaConvidados.get(i);
         if (convidado.getConfirmado() == true) {
         //-----------------------------------------------------
         //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();
         //------------------------------------------------------
         //nome convidado
                
         PdfContentByte conv = writer.getDirectContentUnder();
         conv.beginText();
         conv.setFontAndSize(fHelvetica, 12);
         conv.setTextMatrix(x, y - 20); // x e y
         conv.showText("Prof.Convidado - " + convidado.getProfessorsiape().getNome());
         conv.endText();
         //------------------------------------------------------
         y = y - 80;
         }
         }
         */
        //----------------------------------------------------------------------
        //AlunoDAO aDAO = new AlunoDAO();
        //List<Aluno> allAlunos = aDAO.getAllAlunos();
        //aDAO.closeSession();
        //            PdfPTable table = new PdfPTable(5);
        //            table.setSpacingBefore(35f);
        //            table.setTotalWidth(100f);
        //            table.setWidthPercentage(100);
        //            float[] widths = {10, 30, 30, 13, 17};//largura das 2 colunas
        //            table.setWidths(widths);
        //            table.setHeaderRows(1);
        //
        //            Paragraph cabecalho = new Paragraph("Matricula");
        //            PdfPCell cellMatricula = new PdfPCell(cabecalho); // celula
        //            cabecalho.getFont().setStyle(Font.BOLD);
        //            cabecalho.getFont().setSize(8);
        //            cellMatricula.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //            cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
        //            cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            table.addCell(cellMatricula);
        //
        //            cabecalho = new Paragraph("Nome");
        //            cabecalho.getFont().setStyle(Font.BOLD);
        //            cabecalho.getFont().setSize(8);
        //            PdfPCell cellNome = new PdfPCell(cabecalho); // celula
        //            cellNome.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //            cellNome.setBorderColor(BaseColor.LIGHT_GRAY);
        //            cellNome.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            table.addCell(cellNome);
        //
        //            cabecalho = new Paragraph("Email");
        //            cabecalho.getFont().setStyle(Font.BOLD);
        //            cabecalho.getFont().setSize(8);
        //            PdfPCell cellEmail = new PdfPCell(cabecalho); // celula
        //            cellEmail.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //            cellEmail.setBorderColor(BaseColor.LIGHT_GRAY);
        //            cellEmail.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            table.addCell(cellEmail);
        //
        //            cabecalho = new Paragraph("Telefone");
        //            cabecalho.getFont().setStyle(Font.BOLD);
        //            cabecalho.getFont().setSize(8);
        //            PdfPCell cellTelefone = new PdfPCell(cabecalho); // celula
        //            cellTelefone.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //            cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY);
        //            cellTelefone.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            table.addCell(cellTelefone);
        //
        //            cabecalho = new Paragraph("Curso");
        //            cabecalho.getFont().setStyle(Font.BOLD);
        //            cabecalho.getFont().setSize(8);
        //            PdfPCell cellCurso = new PdfPCell(cabecalho); // celula
        //            cellCurso.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //            cellCurso.setBorderColor(BaseColor.LIGHT_GRAY);
        //            cellCurso.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            table.addCell(cellCurso);
        //            for (int i = 0; i < allAlunos.size(); i++) {
        //                Aluno aluno = allAlunos.get(i);
        //                Paragraph texto = new Paragraph(aluno.getMatricula());
        //                cellMatricula = new PdfPCell(texto); // celula
        //                cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
        //                texto.getFont().setSize(8);
        //                table.addCell(cellMatricula);
        //                texto = new Paragraph(aluno.getNome());
        //                texto.getFont().setSize(8);
        //                cellNome = new PdfPCell(texto); // celula
        //                cellNome.setBorderColor(BaseColor.LIGHT_GRAY);
        //                table.addCell(cellNome);
        //                texto = new Paragraph(aluno.getEmail());
        //                texto.getFont().setSize(8);
        //                cellEmail = new PdfPCell(texto); // celula
        //                cellEmail.setBorderColor(BaseColor.LIGHT_GRAY);
        //                table.addCell(cellEmail);
        //                texto = new Paragraph(aluno.getTelefone());
        //                texto.getFont().setSize(8);
        //                cellTelefone = new PdfPCell(texto); // celula
        //                cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY);
        //                table.addCell(cellTelefone);
        //                texto = new Paragraph(aluno.getCursoidcurso().getNomecurso());
        //                texto.getFont().setSize(8);
        //                cellCurso = new PdfPCell(texto); // celula
        //                cellCurso.setBorderColor(BaseColor.LIGHT_GRAY);
        //                table.addCell(cellCurso);
        //
        //                switch (i % 2) {
        //                    case 0:
        //                        cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
        //                        cellMatricula.setBackgroundColor(BaseColor.LIGHT_GRAY);
        //                        break;
        //                    case 1:
        //
        //                        break;
        //                }
        //
        //            }
        //add nova pagina
        document.newPage();
        //close document
        document.close();
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioBanca.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream com dados
    return baos;
}

From source file:Report.RelatorioCurso.java

/**
 * Funo para gerar o stream do relatrio anual de atividades
 *
 * @param proforiseparada/*from   w w  w.j a va 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 ww. j  av  a 2  s . 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: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/* w w w .  jav a2  s  . co 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:sandbox.columntext.DropTablePart.java

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*from w ww  . j a  va2s .com*/
    Rectangle column = new Rectangle(36, 36, 559, 806);
    ColumnText ct = new ColumnText(writer.getDirectContent());
    ct.setSimpleColumn(column);
    for (int i = 0; i < 4;) {
        PdfPTable table = new PdfPTable(new float[] { 0.25f, 0.25f, 0.25f, 0.25f });
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell(new Phrase("inner table " + (++i)));
        cell.setColspan(4);
        table.addCell(cell);
        for (int j = 0; j < 18; j++) {
            table.addCell(new Phrase("test Data " + (j + 1) + ".1"));
            table.addCell(new Phrase("test Data " + (j + 1) + ".1"));
            table.addCell(new Phrase("test Data " + (j + 1) + ".1"));
            table.addCell(new Phrase("test Data " + (j + 1) + ".1"));
        }
        ct.addElement(table);
        if (ColumnText.hasMoreText(ct.go())) {
            document.newPage();
            ct = new ColumnText(writer.getDirectContent());
            ct.setSimpleColumn(column);
        }
    }
    document.close();
}