Example usage for com.itextpdf.text Font Font

List of usage examples for com.itextpdf.text Font Font

Introduction

In this page you can find the example usage for com.itextpdf.text Font Font.

Prototype


public Font(final BaseFont bf, final float size, final int style, final BaseColor color) 

Source Link

Document

Constructs a Font.

Usage

From source file:watermark.java

public static void main(String[] args) {
    try {/*from ww  w.j a  v a 2s.com*/
        PdfReader reader = new PdfReader(args[0]);
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(args[1]));
        stamp.getWriter().setCompressionLevel(9); // without this code it'll 3 times bigger

        int bottom_margin = Integer.parseInt(args[2]);
        String lic = String.format(LIC, args[3]);

        BaseFont bf = BaseFont.createFont(FONTFILE, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Chunk c = new Chunk(lic, new Font(bf, 7, Font.NORMAL, TCOLOR));
        c.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1 / 800f, null);

        Phrase phrase = new Phrase(c);

        int pages = reader.getNumberOfPages();
        int xpos = 90;
        for (int i = 1; i <= pages; i++) {
            if (i % 2 == 0)
                xpos = 160;
            else
                xpos = 90;

            PdfContentByte under = stamp.getUnderContent(i);
            ColumnText.showTextAligned(under, Element.ALIGN_LEFT, phrase, xpos, bottom_margin, -0);
        }

        stamp.setFullCompression(); // without this code it'll 3 times bigger
        stamp.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:adams.core.io.PdfFont.java

License:Open Source License

/**
 * Turns the font object into the PDF font.
 *
 * @param color   the color to use//  w w w .  j a v  a  2 s .  c  om
 * @return      the font
 */
public synchronized Font toFont(Color color) {
    if (m_Font == null)
        m_Font = new Font(getFontFamilyEnum(m_FontFamily), m_Size, m_FontFace, new BaseColor(color.getRGB()));
    return m_Font;
}

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();//from ww w.  java  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(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();/*from  w w w . j a  v  a 2  s  . co  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.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();//from  w  ww  .  j a va 2s  . com

    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("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();//w  ww  .  ja  v  a2  s.  c om

    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(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);
    }
}

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 w  w  w  .  ja  va 2s.  c  om

    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 ww  .j a  v a  2s.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  w w w. ja  v a2s  .c  om*/

    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.j  ava 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);
    }
}