List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:br.com.moises.servlet.RelatorioPessoa.java
private void mostrarRelatorio(byte[] arquivo, HttpServletResponse response) { /**/* w ww .j a v a2 s .c o m*/ * A simple Hello World Servlet. * @see HttpServlet#doGet( * HttpServletRequest request, HttpServletResponse response) */ response.setContentType("application/pdf"); try { // step 1 Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, response.getOutputStream()); } catch (IOException ex) { Logger.getLogger(RelatorioPessoa.class.getName()).log(Level.SEVERE, null, ex); } // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); document.add(new Paragraph(new Date().toString())); // step 5 document.close(); } catch (DocumentException de) { try { throw new IOException(de.getMessage()); } catch (IOException ex) { Logger.getLogger(RelatorioPessoa.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:br.edu.ifrs.restinga.modulorh.controle.SetorController.java
@RequestMapping(value = "/setor/gerarPDF") public String gerar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DocumentException { response.setContentType("application/pdf"); try {//from ww w .j a v a2s .c om Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); Image image = Image.getInstance("http://www.planalto.gov.br/cciVil_03/decreto/Quadros/anteri1.gif"); image.setAlignment(Image.ALIGN_CENTER); document.open(); document.add(image); document.add(new Paragraph("Ministrio da Educao")); document.add( new Paragraph("Instituto Federal de Educao, Cincia e Tecnologia do Rio Grande do Sul ")); document.add(new Paragraph("Campus Restinga")); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } return "forward:/setor/gerar"; }
From source file:br.edu.ifrs.restinga.sgru.bean.RelatorioBean.java
/** * Adiciona uma linha no arquivo PDF/*from w ww .j av a2s.c om*/ * @param paragraph * @param number */ private void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } }
From source file:br.edu.ifrs.restinga.sgru.modelo.ControladorVenda.java
/** * Realiza a venda de um ticket para um cliente * * @param documento//from w w w .j a v a 2s .co m * @throws br.edu.ifrs.restinga.sgru.excessao.TicketInvalidoException */ //public void realizarVendaTicket(Object documento) throws TicketInvalidoException { public void realizarVendaTicket() throws TicketInvalidoException { if (this.quantidade <= 0) { throw new TicketInvalidoException("Venda de Quantidade invalida!"); } Document pdfTicket = new Document(); File temp; try { temp = File.createTempFile("imp_ticket", ".pdf"); PdfWriter.getInstance(pdfTicket, new FileOutputStream(temp)); pdfTicket.open(); pdfTicket.setPageSize(PageSize.A4); Table tabela = new Table(1); tabela.setWidth(100); for (int i = 0; i < this.quantidade; i++) { VendaTicketsRecargas vendaTicketsRecarga = new VendaTicketsRecargas(); vendaTicketsRecarga.setCaixaRU(this.caixaRU); vendaTicketsRecarga.realizarVendaTicket(); Cell celula = new Cell(); celula.setHorizontalAlignment(Element.ALIGN_CENTER); celula.add(new Paragraph("SISTEMA DE GERENCIAMENTO DE RESTAURANTE UNIVERSIT?RIO")); Paragraph parag = new Paragraph(); parag.getFont().setSize(18); parag.add("TICKET"); celula.add(parag); // Gerando o codigo convetido do ticket String conversor = ""; for (char con : String.format("%07d", vendaTicketsRecarga.getTicket().getId()).toCharArray()) { conversor = con + conversor; } parag = new Paragraph(); parag.getFont().setSize(20); parag.add(String.valueOf(Integer.valueOf(conversor, 16))); celula.add(parag); NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("pt", "BR")); format.setMaximumFractionDigits(2); celula.add(new Paragraph("VALOR " + format.format(vendaTicketsRecarga.getTicket().getValor()))); celula.add(new Paragraph(vendaTicketsRecarga.getTicket().getDataCriado().getTime().toString())); celula.add(new Paragraph(" _ ")); tabela.addCell(celula); this.caixaRU.atualizarLstVendaTicketsRecargas(vendaTicketsRecarga); } pdfTicket.add(tabela); } catch (DocumentException | IOException de) { throw new TicketInvalidoException(de.getMessage()); } finally { pdfTicket.close(); } // Abrindo o pdf no pc try { Desktop.getDesktop().open(temp); temp.deleteOnExit(); } catch (IOException ex) { throw new TicketInvalidoException(ex.getMessage()); } }
From source file:br.gov.jfrj.siga.ex.util.GeradorRTF.java
License:Open Source License
public void geraRTF2() throws Exception { RtfWriter2.getInstance(document, new FileOutputStream("c:\\edson-teste2.rtf")); document.open();/*from w w w .ja v a 2s . c om*/ // MultiColumnText textoMultiColunas = new // MultiColumnText(MultiColumnText.AUTOMATIC); // textoMultiColunas.addRegularColumns(document.left(), // document.right(), 2f, 2); Paragraph paragrafoBase = new Paragraph("09090909"); // textoMultiColunas.addElement(paragrafoBase); document.add(paragrafoBase); document.close(); }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
public static boolean geraRelatorio(File file) { TradGeraRelatorioPDF.carregaTexto(TokenLang.LANG); Document document = new Document(PageSize.A4); try {/*from w w w . j a va 2 s . c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); writer.setPageEvent(new HeaderAndFooter()); document.open(); int linha = 0, j, tot_pg = ResumoDoRelatorio.getTotPage(); //calcula o total de htmls float tot_link = 0.0f; for (j = 1; j <= tot_pg; j++) { String conteudo = ResumoDoRelatorio.getPage(j); String arr[] = conteudo.split("\n"); tot_link += arr.length; } PainelStatusBar.showProgTarReq(); //loop por todas as pginas da paginacao for (j = 1; j <= tot_pg; j++) { String conteudo = ResumoDoRelatorio.getPage(j); String arr[] = conteudo.split("\n"); int tot = arr.length; int i; //loop por todos os links for (i = 0; i < tot; i++) { progresso = (linha++ / tot_link) * 100.0f; PainelStatusBar.setValueProgress((int) progresso); String arr2[] = arr[i].split("\t"); if (arr2.length == 8) { String strUrl = arr2[7];// URL /* int ap1 = Integer.parseInt(arr2[4]);// Aviso1 int ep1 = Integer.parseInt(arr2[1]);// Erro1 int ap2 = Integer.parseInt(arr2[5]);// Aviso2 int ep2 = Integer.parseInt(arr2[2]);// Erro2 int ap3 = Integer.parseInt(arr2[6]);// Aviso3 int ep3 = Integer.parseInt(arr2[3]);// Erro3 */ String myHash = arr2[0]; RelatorioDaUrl relatorio = new RelatorioDaUrl(); relatorio.recarregaArquivoRelatorioEmXml2(myHash); document.add(new Phrase("\n")); Font font = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD); Chunk url = new Chunk(strUrl, font); Paragraph p1 = new Paragraph(TradGeraRelatorioPDF.RELATORIO_URL); p1.add(url); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p1); document.add(new Phrase("\n\n")); if (relatorio.getErrosPrioridade1() <= 0 && relatorio.getErrosPrioridade2() <= 0 && relatorio.getErrosPrioridade3() <= 0) { Paragraph p2 = new Paragraph(TradGeraRelatorioPDF.PAGINAS_SEM_ERROS); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); } else { if (relatorio.getErrosPrioridade1() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P1, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP1()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } if (relatorio.getErrosPrioridade2() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P2, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP2()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } if (relatorio.getErrosPrioridade3() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P3, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP3()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } document.newPage(); } } } } writer.flush(); document.close(); } catch (DocumentException de) { log.error(de.getMessage(), de); PainelStatusBar.hideProgTarReq(); return false; } catch (IOException ioe) { log.error(ioe.getMessage(), ioe); PainelStatusBar.hideProgTarReq(); return false; } PainelStatusBar.hideProgTarReq(); return true; }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
public static boolean geraRelatorio_bkp(File file, ResumoDoRelatorio resumo) { Document document = new Document(PageSize.A4); try {/* w ww. ja v a 2 s. co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); writer.setPageEvent(new HeaderAndFooter()); document.open(); ArrayList<RelatorioDaUrl> relatorios = resumo.getRelatorios(); loop: for (RelatorioDaUrl relatorio : relatorios) { document.add(new Phrase("\n")); Font font = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD); Chunk url = new Chunk(relatorio.getUrl(), font); Paragraph p1 = new Paragraph(TradGeraRelatorioPDF.RELATORIO_URL); p1.add(url); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p1); document.add(new Phrase("\n\n")); if (relatorio.getErrosPrioridade1() <= 0 && relatorio.getErrosPrioridade2() <= 0 && relatorio.getErrosPrioridade3() <= 0) { Paragraph p2 = new Paragraph(TradGeraRelatorioPDF.PAGINAS_SEM_ERROS); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); continue loop; } if (relatorio.getErrosPrioridade1() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P1_SEM_TAB, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP1()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } if (relatorio.getErrosPrioridade2() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P2_SEM_TAB, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP2()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } if (relatorio.getErrosPrioridade3() > 0) { Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P3_SEM_TAB, font); p1.setAlignment(Paragraph.ALIGN_LEFT); document.add(p); document.add(new Chunk("\n")); PdfPTable table = geraLista(relatorio.getListaErrosP3()); if (table != null) { document.add(table); } document.add(new Phrase("\n\n")); } document.newPage(); } writer.flush(); document.close(); } catch (DocumentException de) { log.error(de.getMessage(), de); return false; } catch (IOException ioe) { log.error(ioe.getMessage(), ioe); return false; } return true; }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
private static void geraCabecalho(PdfPTable table) { PdfPCell cell;//www .j av a2s . c o m cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.P_V)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.DESCRICAO)); cell.setColspan(3); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.OCORRENCIAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.LINHAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
private static PdfPTable geraLista(HashSet<PontoVerificacao> pvs) { // Inicializa a Tabela PdfPTable table = new PdfPTable(6); table.setWidthPercentage(100f);/* w w w .j av a2s . com*/ geraCabecalho(table); // Preenche os dados da Tabela HashSet<PontoVerificacao> pontos = pvs; for (PontoVerificacao pv : pontos) { PdfPCell cell; // Ponto de Verificacao cell = new PdfPCell(new Paragraph(String.valueOf(pv.getGl()) + "." + String.valueOf(pv.getCp()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); // Descrio da Regra String descricao; int tipoaval = Integer.parseInt(Gerente.getProperties().getProperty("tipo_avaliacao")); if (tipoaval == 2) { //pegar do EMAG InterfRegrasHardCoded regras = MethodFactRegHardCod.mFRegHardCod("EMAG"); descricao = regras.getTextoRegra(String.valueOf(pv.getGl()) + "." + String.valueOf(pv.getCp())); } else if (tipoaval == 1) { //pegar do WCAG InterfRegrasHardCoded regras = MethodFactRegHardCod.mFRegHardCod("WCAG"); descricao = regras.getTextoRegra(String.valueOf(pv.getGl()) + "." + String.valueOf(pv.getCp())); } else { descricao = TokenLang.getRegra(pv.getIdRegra()); } cell = new PdfPCell(new Paragraph(descricao)); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); // Total Ocorrncias int size = pv.getLinhas().size(); String strSize = String.valueOf(size); strSize = !strSize.equals("0") ? strSize : "---"; cell = new PdfPCell(new Paragraph(strSize)); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); // Linhas em que ocorre o P.V. ArrayList<Integer> arrayLinhas = pv.getLinhas(); StringBuilder linha = new StringBuilder(); for (Integer nroLinha : arrayLinhas) { // String strLinha = Normalizador.normalizar(nroLinha); String strLinha = String.valueOf(nroLinha); linha.append(strLinha + " "); } cell = new PdfPCell(new Paragraph(linha.toString())); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:br.org.acessobrasil.silvinha.util.HeaderAndFooter.java
License:Open Source License
/** * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) *//*w w w . j a va 2s.c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Paragraph(GERAL.RELATORIOS_ASES)); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); cell.setBorder(Rectangle.BOTTOM); head.addCell(cell); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); PdfPTable foot = new PdfPTable(1); cell = new PdfPCell(new Paragraph(String.valueOf(document.getPageNumber()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); cell.setBorder(Rectangle.TOP); foot.addCell(cell); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } }