List of usage examples for com.itextpdf.text.pdf PdfPCell addElement
public void addElement(Element element)
From source file:Visao.Relatorio.GraficoPerCapta.java
public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException { Document document = null;//from w w w . j a va2 s .c o m PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); //add image int width = 500; int height = 400; BufferedImage bufferedImage = chart.createBufferedImage(width, height); Image image = Image.getInstance(writer, bufferedImage, 1.0f); document.add(image); Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); String quebralinha = "\n\nPopulao dos Estados\n\n"; Paragraph preface = new Paragraph(quebralinha, boldFont); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(2); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); Phrase secondLine = new Phrase("Populao", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); table.addCell("SP"); table.addCell(String.valueOf(44396484)); table.addCell("MG"); table.addCell(String.valueOf(20869101)); table.addCell("RJ"); table.addCell(String.valueOf(16550024)); table.addCell("BA"); table.addCell(String.valueOf(15203934)); table.addCell("RS"); table.addCell(String.valueOf(11247972)); table.addCell("PR"); table.addCell(String.valueOf(11163018)); table.addCell("PE"); table.addCell(String.valueOf(9345173)); table.addCell("CE"); table.addCell(String.valueOf(8904459)); table.addCell("PA"); table.addCell(String.valueOf(8175113)); table.addCell("MA"); table.addCell(String.valueOf(6904241)); table.addCell("SC"); table.addCell(String.valueOf(6819190)); table.addCell("GO"); table.addCell(String.valueOf(6610681)); table.addCell("PB"); table.addCell(String.valueOf(3972202)); table.addCell("AM"); table.addCell(String.valueOf(3938336)); table.addCell("ES"); table.addCell(String.valueOf(3929911)); table.addCell("RN"); table.addCell(String.valueOf(3442175)); table.addCell("AL"); table.addCell(String.valueOf(3340932)); table.addCell("MT"); table.addCell(String.valueOf(3270973)); table.addCell("PI"); table.addCell(String.valueOf(3204028)); table.addCell("DF"); table.addCell(String.valueOf(2914830)); table.addCell("MS"); table.addCell(String.valueOf(2651235)); table.addCell("SE"); table.addCell(String.valueOf(2242937)); table.addCell("RO"); table.addCell(String.valueOf(1768204)); table.addCell("TO"); table.addCell(String.valueOf(1515126)); table.addCell("AC"); table.addCell(String.valueOf(803513)); table.addCell("AP"); table.addCell(String.valueOf(766679)); table.addCell("RR"); table.addCell(String.valueOf(505665)); document.add(table); //release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesCidadeIntervalo.java
public void create(OutputStream outputStream) throws DocumentException, IOException { Document document = null;//from w w w . j a va2 s . co m PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); Paragraph paragraph = new Paragraph("\n\nReclamaes\n\nCidade: " + cidade, new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); Paragraph paragraph1 = new Paragraph("\nMs Abertura: " + mes + "\nAno Abertura: " + ano, new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); document.add(paragraph1); document.add(new Paragraph("\n\n\n")); PdfPTable table = new PdfPTable(3); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); PdfPCell pdfWordCell2 = new PdfPCell(); Phrase firstLine = new Phrase("Quantidade de reclamaes", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase secondLine = new Phrase("Nota mdia consumidor", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase thirdLine = new Phrase("Tempo mdio de resposta", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); pdfWordCell2.addElement(thirdLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); table.addCell(pdfWordCell2); table.addCell(String.valueOf(quantidade)); table.addCell(decimalFormat.format(notamedia)); table.addCell(decimalFormat.format(tempoResposta) + " dias"); document.add(table); document.add(new Paragraph("\n\n\nEmpresas Reclamadas\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD))); PdfPTable table1 = new PdfPTable(2); PdfPCell pdfWordCel3 = new PdfPCell(); PdfPCell pdfWordCel4 = new PdfPCell(); Phrase firstLine1 = new Phrase("Empresa", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); Phrase secondLine1 = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCel3.addElement(firstLine1); pdfWordCel4.addElement(secondLine1); table1.addCell(pdfWordCel3); table1.addCell(pdfWordCel4); String consulta = "Select e.nomefantasia, count(r.codigoreclamacao)" + " from Reclamacao r, Empresa e" + " where r.codempresa = e.codigoempresa and" + " r.cidade='" + cidade + "' and r.mesabertura=" + mes + " and r.anoabertura=" + ano + " group by e.nomefantasia" + " order by e.nomefantasia"; Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator(); while (i.hasNext()) { Object[] reclamacaoEmpresa = (Object[]) i.next(); table1.addCell(reclamacaoEmpresa[0].toString()); table1.addCell(reclamacaoEmpresa[1].toString()); } document.add(table1); document.add(new Paragraph("\n\n\nAssuntos Reclamados\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD))); PdfPTable table2 = new PdfPTable(2); PdfPCell pdfWordCel5 = new PdfPCell(); PdfPCell pdfWordCel6 = new PdfPCell(); Phrase firstLine5 = new Phrase("Assunto", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)); pdfWordCel5.addElement(firstLine5); pdfWordCel6.addElement(secondLine1); table2.addCell(pdfWordCel5); table2.addCell(pdfWordCel6); String consulta1 = "select assunto, count(codigoreclamacao)" + " from Reclamacao where cidade='" + cidade + "'" + " and mesabertura=" + mes + " and anoabertura=" + ano + " group by assunto " + " order by assunto"; Iterator ii = dao.getSessao().createSQLQuery(consulta1).list().iterator(); while (ii.hasNext()) { Object[] reclamacaoAssunto = (Object[]) ii.next(); table2.addCell(reclamacaoAssunto[0].toString()); table2.addCell(reclamacaoAssunto[1].toString()); } document.add(table2); document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesUF.java
public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException { Document document = null;/*w w w .ja va 2 s.com*/ PdfWriter writer = null; try { //instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, outputStream); //open document document.open(); Image img = Image.getInstance("src\\Imagens\\logo.png"); img.setAlignment(Element.ALIGN_CENTER); document.add(img); //add image int width = 500; int height = 400; BufferedImage bufferedImage = chart.createBufferedImage(width, height); Image image = Image.getInstance(writer, bufferedImage, 1.0f); document.add(image); Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); String quebralinha = "\n\nQuantidade de reclamaes por UF\n\n"; Paragraph preface = new Paragraph(quebralinha, boldFont); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(2); PdfPCell pdfWordCell = new PdfPCell(); PdfPCell pdfWordCell1 = new PdfPCell(); Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); Phrase secondLine = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); pdfWordCell.addElement(firstLine); pdfWordCell1.addElement(secondLine); table.addCell(pdfWordCell); table.addCell(pdfWordCell1); String consulta = "Select uf, count(codigoreclamacao) from " + "Reclamacao group by (uf) order by count(codigoreclamacao) desc"; Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator(); while (i.hasNext()) { Object[] reclamacao = (Object[]) i.next(); table.addCell(reclamacao[0].toString()); table.addCell(reclamacao[1].toString()); } document.add(table); //release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException | IOException de) { throw de; } finally { //release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }