List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. From source file:br.com.tcc.relat.VendasDoAno.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 YEAR(dataVenda) as ano, SUM(totalVenda) as total FROM vendaregistro GROUP BY ano"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoAno.pdf")); PDFLogReport.open();//from www.j av a2 s. c o m 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); //we have two columns in our table PdfPTable LogTable = new PdfPTable(2); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio Anual"); 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, 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("Ano ", fonte)); LogTable.addCell(new Paragraph("Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String ano = query.getString("ano"); LogTable.addCell(new Paragraph(ano, fonteDados)); String total = query.getString("total"); LogTable.addCell(new Paragraph(total, 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\\VendaDoAno.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../VendaDoAno.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.VendasDoDia.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 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"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoDia.pdf")); PDFLogReport.open();/*from w w w .ja v a 2 s. c o m*/ 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); //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.VendasDoDiaValores.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 dataVenda, Sum(totalVenda) As total FROM vendaregistro GROUP BY dataVenda DESC LIMIT 100"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoDiaValores.pdf")); PDFLogReport.open();//from ww w. j a v a2s. c o m 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); //we have two columns in our table PdfPTable LogTable = new PdfPTable(2); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio das Vendas - Valores"); 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, 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("Data ", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String data = query.getString("dataVenda"); LogTable.addCell(new Paragraph(data, fonteDados)); String total = query.getString("total"); LogTable.addCell(new Paragraph(total, 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\\VendaDoDiaValores.pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../VendaDoDiaValores.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.VendasDoMes.java
public static void main(String[] args) throws Exception { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); Calendar cal = Calendar.getInstance(); int ano = cal.get(Calendar.YEAR); /* Define the SQL query */ ResultSet query = stmt.executeQuery( "SELECT MONTH(dataVenda) as mes, SUM(totalVenda) as total FROM vendaregistro WHERE YEAR(dataVenda) = YEAR(CURRENT_DATE) GROUP BY mes"); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoMes" + ano + ".pdf")); PDFLogReport.open();// w w w .ja v a 2 s . c o m 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); //we have two columns in our table PdfPTable LogTable = new PdfPTable(2); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio Mensal -" + ano); 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, 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("Mes ", fonte)); LogTable.addCell(new Paragraph("Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String mes = query.getString("mes"); int mesInteiro = Integer.parseInt(mes); switch (mesInteiro) { case 1: mes = "Janeiro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 2: mes = "Fevereiro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 3: mes = "Maro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 4: mes = "Abril"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 5: mes = "Maio"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 6: mes = "Junho"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 7: mes = "Julho"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 8: mes = "Agosto"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 9: mes = "Setembro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 10: mes = "Outubro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 11: mes = "Novembro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; case 12: mes = "Dezembro"; LogTable.addCell(new Paragraph(mes, fonteDados)); break; } String total = query.getString("total"); LogTable.addCell(new Paragraph(total, 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\\VendaDoMes" + ano + ".pdf"; //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); File pdf = new File("../../VendaDoMes" + ano + ".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.view.FormaPagamentoView.java
private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed int row = tblRegistro.getSelectedRow(); int id = vendaRegistroList.get(row).getId(); Connection con = new ConnectionFactory().getConnection(); try {/* w ww .ja va2 s.co m*/ Statement stmt = con.createStatement(); ResultSet query = stmt.executeQuery( "SELECT produto.descricao, vendadetalhe.qtde, vendadetalhe.vlrUnitario, vendadetalhe.vlrTotal from vendadetalhe as vendadetalhe INNER JOIN produto as produto ON (vendadetalhe.idProduto = produto.ID) where idVendaRegistro = " + id); Document documento = new Document(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0: mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } try { OutputStream outputStream = new FileOutputStream( "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"); PdfWriter.getInstance(documento, outputStream); documento.open(); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 36, Font.BOLD); Font fonteItem = new Font(Font.FontFamily.COURIER, 28, Font.BOLD); 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" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + txtCodigo.getText()); cabecalho.setAlignment(Element.ALIGN_CENTER); documento.add(cabecalho); Paragraph paragrafo = new Paragraph("Relatrio da Venda", fonte); paragrafo.setAlignment(Element.ALIGN_CENTER); documento.add(paragrafo); Paragraph paragrafoCliente = new Paragraph("Cliente: " + cbxCliente.getSelectedItem().toString()); documento.add(paragrafoCliente); Paragraph paragrafoFuncionario = new Paragraph( "Funcionrio: " + cbxFuncionario.getSelectedItem().toString()); documento.add(paragrafoFuncionario); Paragraph paragrafoPagamento = new Paragraph( "Tipo de Pagamento: " + cbxTipoPagamento.getSelectedItem().toString()); documento.add(paragrafoPagamento); // Paragraph paragrafoParcela = new Paragraph("Parcelas: " + cbxParcelas.getSelectedItem().toString()); // documento.add(paragrafoParcela); // Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); // documento.add(paragrafoValor); if (cbxTipoPagamento.getSelectedItem().toString().equals(" vista") || cbxTipoPagamento.getSelectedItem().toString().equals("C. Debito")) { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtCompra.getText()); documento.add(paragrafoValor); Paragraph paragrafoAVista = new Paragraph("Valor vista: " + txtTotal.getText()); documento.add(paragrafoAVista); } else { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); documento.add(paragrafoValor); int parcela = Integer.parseInt(cbxParcelas.getSelectedItem().toString()); double valorParcelas = Double.parseDouble(txtTotal.getText()); double total = valorParcelas / parcela; Paragraph paragrafoVezes = new Paragraph( cbxParcelas.getSelectedItem().toString() + " parcelas de R$: " + total); documento.add(paragrafoVezes); } Paragraph quebraLinha = new Paragraph("\n\n"); documento.add(quebraLinha); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte2 = 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 ", fonte2)); LogTable.addCell(new Paragraph("Quantidade", fonte2)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte2)); LogTable.addCell(new Paragraph("Valor Total", fonte2)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ documento.add(LogTable); // Paragraph paragrafoItemVenda = new Paragraph("Produtos da venda", fonteItem); // paragrafoItemVenda.setAlignment(Element.ALIGN_CENTER); // documento.add(paragrafoItemVenda); // Paragraph cabecalhoItemVenda = new Paragraph("Produto Qtde. Vlr Unit. Vlr Total"); // documento.add(cabecalhoItemVenda); // vendaDetalheQuery = entityManager.createQuery("from Vendadetalhe where idVendaRegistro=" + txtCodigo.getText()); // Paragraph paragrafoLista = new Paragraph(vendaDetalheQuery.getResultList().toString().substring(1, vendaDetalheQuery.getResultList().toString().length() - 1)); // documento.add(paragrafoLista); documento.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); } catch (FileNotFoundException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.com.tcc.view.MovimentoEntradaView.java
private void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = entradaRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0://w w w.j av a 2s . com mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* 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("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".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" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // 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("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = entradaRegistroList.get(row).getVlrTotal(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:br.com.tcc.view.MovimentoOrcamentoView.java
private void relat(String sql) throws IOException, DocumentException, SQLException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = orcamentoRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0:/*from w w w .j av a2 s .c om*/ mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* 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("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Oramento " + id + ".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" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Oramento"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // 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("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = orcamentoRegistroList.get(row).getVlrTotalOrcamento(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Oramento " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:br.com.tcc.view.MovimentoPedidoView.java
private void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = pedidoRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0://from w w w. j ava 2 s. c om mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* 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("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Pedidos " + id + ".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" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Lista de Pedidos"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // 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("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtdePedido"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = pedidoRegistroList.get(row).getVlrPedido(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Pedidos " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:br.unisc.video_locadora.controll.Generator_PDF.java
public void geraRelatorio() throws DocumentException, FileNotFoundException { // Cria um novo documento com tamanho e margens definidas pelo usurio // new Document(tamanho da pgina, margem esquerda, margem direita, // margem topo, margem rodap); Document doc = new Document(PageSize.A4, 10, 10, 10, 10); try {/* ww w.j a v a 2 s. c om*/ JFileChooser jFileChooser = new JFileChooser(); //seta para selecionar apenas arquivos jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //desabilita todos os tipos de arquivos jFileChooser.setAcceptAllFileFilterUsed(false); //filtra por extensao jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Extenso PDF"; } @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith("pdf"); } }); //mostra janela para salvar int acao = jFileChooser.showSaveDialog(null); //executa acao conforme opcao selecionada if (acao == JFileChooser.APPROVE_OPTION) { //escolheu arquivo System.out.println(jFileChooser.getSelectedFile().getAbsolutePath()); PdfWriter.getInstance(doc, new FileOutputStream(jFileChooser.getSelectedFile().getAbsolutePath() + ".pdf")); doc.open(); listaF = f.buscaFilme(""); // Definindo uma fonte, com tamanho 20 e negrito Font f = new Font(Font.FontFamily.COURIER, 30, Font.BOLD); Font f2 = new Font(Font.FontFamily.HELVETICA, 20, Font.BOLD); // adicionando um pargrafo ao documento com a fonte acima Paragraph pa = new Paragraph("Relatrio", f); // Setando o alinhamento p/ o centro pa.setAlignment(Paragraph.ALIGN_CENTER); // Definindo pa.setSpacingAfter(50); doc.add(pa); //doc.add(new Paragraph(" ")); // Criando uma tabela com 4 colunas PdfPTable table = new PdfPTable(7); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Todos os Ttulos", f2); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 4 colunas header.setColspan(7); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela table.addCell(header); List<String> list = new ArrayList<>(); list.add("Id"); list.add("Ttulo"); list.add("Ano"); list.add("Diretor"); list.add("Gnero"); list.add("Linguagem"); list.add("Locado"); for (Filmes p : listaF) { list.add(String.valueOf(p.getId())); list.add(p.getTitulo()); list.add(String.valueOf(p.getAno())); list.add(p.getDiretor()); list.add(p.getGenero()); list.add(p.getIdioma()); list.add(p.getLocado()); } for (String s : list) { table.addCell(s); } doc.add(table); /* doc.add(new Paragraph(" ID | Nome | Idade | Cidade")); for (Pessoa p : lista) { doc.add(new Paragraph(p.getId() + " | " + p.getNome() + " | " + p.getIdade() + " | " + p.getCidade())); }*/ } } catch (FileNotFoundException | DocumentException e) { System.err.println(e.getMessage()); } doc.close(); }
From source file:bsf.conn.DBMS.java
private static void createTable(Section subCatPart, javax.swing.JTable table) { try {/*from w w w . j av a2 s.com*/ PdfPTable ptable = new PdfPTable(table.getColumnCount()); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); for (String col : DBMS.getTableHeader(table)) ptable.addCell(col); String[][] row = DBMS.getTable(table); for (String[] col : row) for (String cell : col) if (!(cell.equals("null"))) ptable.addCell(cell); else ptable.addCell(" "); subCatPart.add(ptable); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } }