List of usage examples for com.itextpdf.text Document open
boolean open
To view the source code for com.itextpdf.text Document open.
Click Source Link
From source file:bouttime.utility.bracketsheet.Bracket16Maker.java
License:Open Source License
/** * @param args the command line arguments * arg0 String filename for output file//from w w w . ja va2 s .c o m * arg1 boolean value "true" will render/show PDF file in viewer, default is false * * For example : * Bracket2Maker /tmp/test.pdf true */ public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer PdfWriter writer; if (args.length >= 1) { writer = PdfWriter.getInstance(document, new FileOutputStream(args[0])); } else { System.err.println("ERROR : Must specify output file."); return; } // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf); } catch (DocumentException de) { System.err.println(de.getMessage()); return; } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } // step 5: we close the document document.close(); if ((args.length == 2) && (Boolean.parseBoolean(args[1]))) { RoundRobinBracketMaker.showPDF(args[0]); } }
From source file:bouttime.utility.bracketsheet.RoundRobinBracketMaker.java
License:Open Source License
/** * @param args the command line arguments * arg0 String filename for output file/* w ww . ja v a2 s . co m*/ * arg1 int number of wrestlers * arg2 boolean value "true" will render/show PDF file in viewer, default is false * * For example : * RoundRobinBracketMaker /tmp/test.pdf 3 true */ public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer PdfWriter writer; int numWrestlers; if (args.length >= 2) { writer = PdfWriter.getInstance(document, new FileOutputStream(args[0])); numWrestlers = Integer.parseInt(args[1]); } else { System.err.println("ERROR : Must specify output file and number of wrestlers."); return; } // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf, numWrestlers); } catch (DocumentException de) { System.err.println(de.getMessage()); return; } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } // step 5: we close the document document.close(); if ((args.length == 3) && (Boolean.parseBoolean(args[2]))) { showPDF(args[0]); } }
From source file:br.com.bikefood.model.PdfGenerator.java
public File menuGenerator(File a, Bikefood bike) throws BadElementException, IOException { try {/*from ww w . j av a 2 s . c o m*/ Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(a.getAbsolutePath())); doc.open(); doc.add(new Paragraph("Cardpio do Bike Food: " + bike.getName())); doc.add(new Paragraph("Especialidade em: " + bike.getType().getType())); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); Dal dal = new Dal(); List<Product> cardapio = dal.getProducts((int) bike.getId()); for (int x = 0; x < cardapio.size(); x++) { String image; if (cardapio.get(x).getImg().contains("br/com/bikefood")) { image = "C:\\Users\\Aluno\\Documents\\NetBeansProjects\\Bikefood\\src\\br\\com\\bikefood\\image\\product.png"; } else { image = cardapio.get(x).getImg(); } Image img = Image.getInstance(image); img.scaleAbsolute(125, 125); doc.add(img); doc.add(new Paragraph("Nome do Prato: " + cardapio.get(x).getName())); doc.add(new Paragraph("Preo do Prato: " + cardapio.get(x).getPrice())); doc.add(new Paragraph("Ingredientes: " + cardapio.get(x).getIngredients())); doc.add(new Paragraph("\n")); System.out.println(cardapio.get(x).getImg()); } doc.close(); return a; } catch (FileNotFoundException ex) { Logger.getLogger(PdfGenerator.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ee) { Logger.getLogger(PdfGenerator.class.getName()).log(Level.SEVERE, null, ee); } return a; }
From source file:br.com.docedesafio.pdfs.FirstPdf.java
public static void main(String[] args) { try {/*from w w w . j a v a 2s . c om*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:br.com.gerarpdf.view.ViewGerarPDF.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Document document = new Document(); try {//from w w w.j av a2s . c o m PdfWriter.getInstance(document, new FileOutputStream("documento.pdf")); document.open(); document.add(new Paragraph("#Teste_GERARDO_PDF https://github.com/Heverton")); } catch (DocumentException ex) { System.out.println("Error:" + ex); } catch (FileNotFoundException ex) { System.out.println("Error:" + ex); } finally { document.close(); } try { Desktop.getDesktop().open(new File("documento.pdf")); } catch (IOException ex) { System.out.println("Error:" + ex); } }
From source file:br.com.primetestes.TableBean.java
License:Apache License
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open(); pdf.setPageSize(PageSize.A4);/*from w w w . j a v a 2s.c om*/ ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "prime_logo.png"; pdf.add(Image.getInstance(logo)); }
From source file:br.com.tcc.relat.BalancoAnual.java
public static void main(String[] args) throws Exception { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); /* Define the SQL query */ ResultSet query = stmt.executeQuery( "SELECT produto.ID, produto.descricao, produto.numEstoque, produto.numEstoqueCritico, unidade.descricao, fornecedor.nome FROM produto as produto INNER JOIN unidade as unidade ON (produto.idUnidade = unidade.id) INNER JOIN fornecedor as fornecedor ON (produto.idFornecedor = fornecedor.id)"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); //PdfWriter.getInstance(PDFLogReport, new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Balanco.pdf")); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../RelatBalanco.pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph( "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho);/* w w w . j a v a2 s . com*/ //we have two columns in our table PdfPTable LogTable = new PdfPTable(6); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Balano Anual"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(6); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Fornecedor", fonte)); LogTable.addCell(new Paragraph("Unidade", fonte)); LogTable.addCell(new Paragraph("Estoque", fonte)); LogTable.addCell(new Paragraph("Estoque Crtico", fonte)); LogTable.addCell(new Paragraph("Quantidade", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String fornecedor = query.getString("nome"); LogTable.addCell(new Paragraph(fornecedor, fonteDados)); String unidade = query.getString("unidade.descricao"); LogTable.addCell(new Paragraph(unidade, fonteDados)); String estoque = query.getString("numEstoque"); LogTable.addCell(new Paragraph(estoque, fonteDados)); String critico = query.getString("numEstoqueCritico"); LogTable.addCell(new Paragraph(critico, fonteDados)); LogTable.addCell(new Paragraph(" ", fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Balanco.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../RelatBalanco.pdf"); try { Desktop.getDesktop().open(pdf); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex); } }
From source file:br.com.tcc.relat.ConsultarVendas.java
public void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); /* Define the SQL query */ // sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" + //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE dataVenda = CURRENT_DATE"; ResultSet query = stmt.executeQuery(sql); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoDia.pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph( "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho);/*from www. j a va2 s . co m*/ //we have two columns in our table PdfPTable LogTable = new PdfPTable(9); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio Venda do Dia"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(9); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Cliente ", fonte)); LogTable.addCell(new Paragraph("Funcionario", fonte)); LogTable.addCell(new Paragraph("Tipo Pagamento", fonte)); LogTable.addCell(new Paragraph("Data Compra", fonte)); LogTable.addCell(new Paragraph("Valor Sugerido", fonte)); LogTable.addCell(new Paragraph("Valor da Venda", fonte)); LogTable.addCell(new Paragraph("Parcelas", fonte)); LogTable.addCell(new Paragraph("1 Vencimento", fonte)); LogTable.addCell(new Paragraph("Status da Compra", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String cliente = query.getString("cliente.nome"); LogTable.addCell(new Paragraph(cliente, fonteDados)); String funcionario = query.getString("funcionario.nome"); LogTable.addCell(new Paragraph(funcionario, fonteDados)); String tipoPagamento = query.getString("tipopagamento.descricao"); LogTable.addCell(new Paragraph(tipoPagamento, fonteDados)); String dataVenda = query.getString("dataVenda"); LogTable.addCell(new Paragraph(dataVenda, fonteDados)); String vlrSugerido = query.getString("vlrSugerido"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String totalVenda = query.getString("totalVenda"); LogTable.addCell(new Paragraph(totalVenda, fonteDados)); String parcela = query.getString("parcela"); LogTable.addCell(new Paragraph(parcela, fonteDados)); String vencimento = query.getString("1vencimento"); LogTable.addCell(new Paragraph(vencimento, fonteDados)); String ativo = query.getString("ativo"); LogTable.addCell(new Paragraph(ativo, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\VendaDoDia.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../VendaDoDia.pdf"); try { Desktop.getDesktop().open(pdf); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex); } }
From source file:br.com.tcc.relat.MaisVendidos.java
public static void main(String[] args) throws Exception { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); /* Define the SQL query */ ResultSet query = stmt.executeQuery( "SELECT produto.descricao , SUM(vendadetalhe.qtde) AS qtde FROM produto INNER JOIN vendadetalhe" + " ON produto.ID = vendadetalhe.idProduto GROUP BY produto.descricao" + " ORDER BY qtde DESC LIMIT 30"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../MaisVendidos.pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph( "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho);//from ww w . j a va 2 s .com //we have two columns in our table PdfPTable LogTable = new PdfPTable(2); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("30 Mais vendidos"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(2); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Vendidos", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("descricao"); LogTable.addCell(new Paragraph(produto)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\MaisVendidos.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../MaisVendidos.pdf"); try { Desktop.getDesktop().open(pdf); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex); } }
From source file:br.com.tcc.relat.ProdutosRelat.java
public static void main(String[] args) throws Exception { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); /* Define the SQL query */ ResultSet query = stmt.executeQuery( "SELECT produto.ID, produto.descricao, produto.vlrCompra, produto.vlrVenda, produto.numEstoque, produto.numEstoqueCritico, unidade.descricao, fornecedor.nome FROM produto as produto INNER JOIN unidade as unidade ON (produto.idUnidade = unidade.id) INNER JOIN fornecedor as fornecedor ON (produto.idFornecedor = fornecedor.id)"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../TesteProdutos.pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph( "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho);// ww w. j a v a2s .c o m //we have two columns in our table PdfPTable LogTable = new PdfPTable(7); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Produtos"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(7); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Fornecedor", fonte)); LogTable.addCell(new Paragraph("Unidade", fonte)); LogTable.addCell(new Paragraph("Valor Compra", fonte)); LogTable.addCell(new Paragraph("Valor Venda", fonte)); LogTable.addCell(new Paragraph("Estoque", fonte)); LogTable.addCell(new Paragraph("Estoque Crtico", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String fornecedor = query.getString("nome"); LogTable.addCell(new Paragraph(fornecedor, fonteDados)); String unidade = query.getString("unidade.descricao"); LogTable.addCell(new Paragraph(unidade, fonteDados)); String compra = query.getString("vlrCompra"); LogTable.addCell(new Paragraph(compra, fonteDados)); String venda = query.getString("vlrVenda"); LogTable.addCell(new Paragraph(venda, fonteDados)); String estoque = query.getString("numEstoque"); LogTable.addCell(new Paragraph(estoque, fonteDados)); String critico = query.getString("numEstoqueCritico"); LogTable.addCell(new Paragraph(critico, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\TesteProdutos.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../TesteProdutos.pdf"); try { Desktop.getDesktop().open(pdf); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex); } }