Example usage for com.itextpdf.text.pdf PdfPTable addCell

List of usage examples for com.itextpdf.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable addCell.

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

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 {//  www. jav a  2  s  . c o  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:/*from  w  w  w  .j  a va  2  s. 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 a v  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   www . ja  v a  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 {//w ww .j av a  2  s .  c o m

        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  a  va2 s . c o  m*/
        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);
    }
}

From source file:BUS.ExportPDF.java

public boolean ExportPN(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from  w w  w.j a v a2 s .co m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuNhap_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data

        PdfPTable t = new PdfPTable(7);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu nhp", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Nh cung cp", f));
        t.addCell(c6);
        PdfPCell c7 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c7);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(new Phrase(al.get(i)[4], f));
            t.addCell(al.get(i)[5]);
        }
        document.add(t);
        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportPX(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from w  w w .ja  v a  2  s  .  c o  m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuXuat_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu xut", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportHD(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from   w w w . j  a va 2 s.  c  om*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "Hoadon_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(6);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M ha n", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn khch hng", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c6);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(al.get(i)[4]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKDT(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//  www .  ja  v a2 s . c o  m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nam can bao cao
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\barChart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(4);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("Thng", f));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Li", f));
        t.addCell(c4);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(al.get(i)[2]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}