List of usage examples for com.itextpdf.text.pdf PdfContentByte lineTo
public void lineTo(final double x, final double y)
From source file:org.gephi.preview.plugin.renderers.ArrowRenderer.java
License:Open Source License
public void renderStraight(RenderTarget target, Item item, float x1, float y1, float x2, float y2, float radius, float size, Color color) { Edge edge = (Edge) item.getSource(); PVector direction = new PVector(x2, y2); direction.sub(new PVector(x1, y1)); direction.normalize();// w ww .jav a 2s. c om PVector p1 = new PVector(direction.x, direction.y); p1.mult(radius); p1.add(new PVector(x2, y2)); PVector p1r = new PVector(direction.x, direction.y); p1r.mult(radius - size); p1r.add(new PVector(x2, y2)); PVector p2 = new PVector(-direction.y, direction.x); p2.mult(size * BASE_RATIO); p2.add(p1r); PVector p3 = new PVector(direction.y, -direction.x); p3.mult(size * BASE_RATIO); p3.add(p1r); if (target instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) target).getGraphics(); graphics.noStroke(); graphics.fill(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); } else if (target instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) target; Element arrowElem = svgTarget.createElement("polyline"); arrowElem.setAttribute("points", String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)); arrowElem.setAttribute("class", edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId()); arrowElem.setAttribute("fill", svgTarget.toHexString(color)); arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + ""); arrowElem.setAttribute("stroke", "none"); svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem); } else if (target instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) target; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(p1.x, -p1.y); cb.lineTo(p2.x, -p2.y); cb.lineTo(p3.x, -p3.y); cb.closePath(); cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue()); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setFillOpacity(alpha); cb.setGState(gState); } cb.fill(); if (color.getAlpha() < 255) { cb.restoreState(); } } }
From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java
License:Open Source License
public void renderStraightEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color, PreviewProperties properties, RenderTarget renderTarget) { Edge edge = (Edge) edgeItem.getSource(); Float x1 = sourceItem.getData(NodeItem.X); Float x2 = targetItem.getData(NodeItem.X); Float y1 = sourceItem.getData(NodeItem.Y); Float y2 = targetItem.getData(NodeItem.Y); //Target radius - to start at the base of the arrow Float targetRadius = edgeItem.getData(TARGET_RADIUS); //Avoid edge from passing the node's center: if (targetRadius != null && targetRadius < 0) { PVector direction = new PVector(x2, y2); direction.sub(new PVector(x1, y1)); direction.normalize();//from www .j av a 2 s.c o m direction = new PVector(direction.x, direction.y); direction.mult(targetRadius); direction.add(new PVector(x2, y2)); x2 = direction.x; y2 = direction.y; } //Source radius Float sourceRadius = edgeItem.getData(SOURCE_RADIUS); //Avoid edge from passing the node's center: if (sourceRadius != null && sourceRadius < 0) { PVector direction = new PVector(x1, y1); direction.sub(new PVector(x2, y2)); direction.normalize(); direction = new PVector(direction.x, direction.y); direction.mult(sourceRadius); direction.add(new PVector(x1, y1)); x1 = direction.x; y1 = direction.y; } if (renderTarget instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics(); graphics.strokeWeight(thickness); graphics.strokeCap(PGraphics.SQUARE); graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.noFill(); graphics.line(x1, y1, x2, y2); } else if (renderTarget instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) renderTarget; Element edgeElem = svgTarget.createElement("path"); edgeElem.setAttribute("class", edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId()); edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f L %f,%f", x1, y1, x2, y2)); edgeElem.setAttribute("stroke", svgTarget.toHexString(color)); DecimalFormat df = new DecimalFormat("#.########"); edgeElem.setAttribute("stroke-width", df.format(thickness * svgTarget.getScaleRatio())); edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + ""); edgeElem.setAttribute("fill", "none"); svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem); } else if (renderTarget instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) renderTarget; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(x1, -y1); cb.lineTo(x2, -y2); cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (color.getAlpha() < 255) { cb.restoreState(); } } }
From source file:org.javad.pdf.PageTitle.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { int maxWidth = 0; content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Title); content.setFontAndSize(f.getBaseFont(), f.getSize()); float top = getY(); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, (int) (maxWidth * 1.1)); }/* w w w . j a va 2s . c o m*/ if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Subtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(getSubTitle().toUpperCase(), subFont.getSize())); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, (int) (maxWidth * 1.10)); } content.setHorizontalScaling(100.0f); if (getClassifier() != null && !getClassifier().isEmpty()) { Font classFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Classifier); content.setFontAndSize(classFont.getBaseFont(), classFont.getSize()); top -= classFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); float width = classFont.getBaseFont().getWidthPoint(getClassifier(), classFont.getCalculatedSize()) + 4; maxWidth = Math.max(maxWidth, (int) width + (2 * DASH_LENGTH)); content.setLineWidth(0.8f); float lineTop = top + ((int) classFont.getSize() / 2 - 1); content.moveTo(getX() - (width / 2) - DASH_LENGTH, lineTop); content.lineTo(getX() - (width / 2), lineTop); content.moveTo(getX() + (width / 2), lineTop); content.lineTo(getX() + (width / 2) + DASH_LENGTH, lineTop); content.stroke(); PdfUtil.renderConstrainedText(content, getClassifier(), classFont, getX(), top, (int) (maxWidth * 1.10)); } OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }
From source file:org.javad.stamp.pdf.SetTenant.java
License:Apache License
protected void drawSeparator(PdfContentByte content, float x, float y, float width, float height) { float sx = (getOrientation() == Orientation.HORIZONTAL) ? x : x + PdfUtil.convertFromMillimeters(getPadding() + 2); float dx = (getOrientation() == Orientation.HORIZONTAL) ? x : x + width - PdfUtil.convertFromMillimeters(getPadding() + 2); float sy = (getOrientation() == Orientation.HORIZONTAL) ? y + PdfUtil.convertFromMillimeters(getVerticalPadding() + 2) : y;/* w ww .j a v a 2 s .c o m*/ float dy = (getOrientation() == Orientation.HORIZONTAL) ? y + height - PdfUtil.convertFromMillimeters(getVerticalPadding() + 2) : y; content.setLineWidth(0.5f); content.setColorStroke(BaseColor.GRAY); content.moveTo(sx, sy); content.setLineDash(5.0f, 2.0f, 0.0f); content.lineTo(dx, dy); content.stroke(); content.setLineDash(1.0f, 0.0f, 0.0f); }
From source file:org.javad.stamp.pdf.StampBox.java
License:Apache License
private void drawPath(PdfContentByte content, OutputBounds rect) { switch (shape) { case rectangle: content.rectangle(rect.x, rect.y, rect.width, rect.height); break;/*from www . j ava2 s .co m*/ case triangle: // calculation of delta x based on triangle and cosine dimensions //float delta_x = (getPadding() / 2.0f) * (rect.width / 2.0f) / (float) Math.sqrt(Math.pow(rect.height, 2.0) + Math.pow(rect.width / 2.0, 2.0)); content.moveTo(rect.x, rect.y); content.lineTo(rect.x + rect.width, rect.y); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y); break; case triangleInverted: content.moveTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height); content.lineTo(rect.x + rect.width / 2.0f, rect.y); break; case diamond: content.moveTo(rect.x, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height / 2.0f); break; } }
From source file:org.javad.stamp.pdf.StampBox.java
License:Apache License
/** * Will draw the bisect lines within the content are of the output * rectangle.//from w w w .j a v a 2 s .c o m * * @param content * @param rect */ @SuppressWarnings("incomplete-switch") void drawBisect(PdfContentByte content, OutputBounds rect) { content.setLineWidth(0.5f); content.setColorStroke(BaseColor.GRAY); float dx1 = 0.0f; float dx2 = 0.0f; float dy1 = 0.0f; float dy2 = 0.0f; float xp = (int) PdfUtil.convertFromMillimeters(getPadding() + 2); float yp = (int) PdfUtil.convertFromMillimeters(getVerticalPadding() + 2); switch (bisect) { case top_left: dx1 = xp; dy1 = rect.height - yp; dx2 = rect.width - xp; dy2 = yp; break; case top_right: dx1 = xp; dy1 = yp; dx2 = rect.width - xp; dy2 = rect.height - yp; break; case vertical: dx1 = rect.width / 2; dy1 = yp; dx2 = dx1; dy2 = rect.height - yp; } content.moveTo(rect.x + dx1, rect.y + dy1); content.setLineDash(5.0f, 2.0f, 0.0f); content.lineTo(rect.x + dx2, rect.y + dy2); content.stroke(); content.setLineDash(1.0f, 0.0f, 0.0f); }
From source file:org.primaresearch.pdf.PageToPdfConverter.java
License:Apache License
/** * Draws the outline of the given layout object on the current PDF page. * @param obj// w ww.ja va 2s . c o m * @param canvas * @param pageHeight */ private void drawLayoutObject(ContentObject obj, PdfContentByte canvas, int pageHeight) { if (obj == null) return; Polygon polygon = obj.getCoords(); if (polygon == null || polygon.getSize() < 3) return; canvas.setColorStroke(getOutlineColor(obj.getType())); canvas.setLineWidth(1.0f); //Move to last point Point p = polygon.getPoint(polygon.getSize() - 1); canvas.moveTo(p.x, pageHeight - p.y); //Now draw all line segments for (int i = 0; i < polygon.getSize(); i++) { p = polygon.getPoint(i); canvas.lineTo(p.x, pageHeight - p.y); } canvas.stroke(); }
From source file:printInv.GenerateInvoice.java
public void generateLayout(Document doc, PdfContentByte cb) { try {/*www. j a va2s . c om*/ cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Invoice No."); createHeadings(cb, 422, 723, "Name"); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(360, 50); cb.lineTo(360, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "SNo."); createHeadings(cb, 52, 633, "Product ID"); createHeadings(cb, 362, 633, "Quantity"); createHeadings(cb, 432, 633, "Unit Price"); createHeadings(cb, 502, 633, "Line Total"); //add the images Image companyLogo = Image.getInstance("src/image/icon.png"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Report.RelatorioBanca.java
/** * funcao para gerar o stream do relatorio * * @param banca// ww w . ja va2 s .co 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 w w w . ja v a 2s . 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; }