Example usage for com.itextpdf.text Paragraph setAlignment

List of usage examples for com.itextpdf.text Paragraph setAlignment

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:View.TelaRelatorio.java

public void EntregasPorLocalidade() {
    NegocioRelatorio nr = new NegocioRelatorio();

    Document documentoPDF = new Document();
    String output = "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\Relatorios\\MaisVendidos\\EntregasPorLocalidades.pdf";
    try {//from ww w. ja  va 2  s .c o m

        PdfWriter.getInstance(documentoPDF, new FileOutputStream(output));

        documentoPDF.open();

        documentoPDF.setPageSize(PageSize.A4);

        Image imagem = Image.getInstance(
                "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\src\\View\\image.png");

        imagem.scaleToFit(100, 75);

        imagem.setAlignment(Element.ALIGN_CENTER);

        documentoPDF.add(imagem);

        Font fonte1 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD);

        Paragraph agr = new Paragraph("Aplicao para Gesto de Restaurantes", fonte1);

        agr.setAlignment(Element.ALIGN_CENTER);

        documentoPDF.add(agr);

        Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD);

        Paragraph cabecalho = new Paragraph("ENTREGAS POR LOCALIDADE", fonte);

        cabecalho.setAlignment(Element.ALIGN_CENTER);

        documentoPDF.add(cabecalho);

        documentoPDF.add(new Paragraph("\n\n"));

        List<Entrega> Entrega = nr.Localidades();

        PdfPTable dadosC = new PdfPTable(new float[] { 0.50f, 0.50f });

        List<String> dados = new ArrayList<String>();

        dados.add("BAIRRO");
        dados.add("TOTAL DE ENTREGAS");

        for (int x = 0; x < Entrega.size(); x++) {
            dados.add(Entrega.get(x).getDia());
            dados.add("" + Entrega.get(x).getQuant());
        }

        for (String s : dados) {
            dadosC.addCell(s);
        }

        dadosC.setWidthPercentage(100f);
        dadosC.setHorizontalAlignment(Element.ALIGN_CENTER);
        documentoPDF.add(dadosC);

    } catch (DocumentException ex) {
        Logger.getLogger(TelaRelatorio.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TelaRelatorio.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TelaRelatorio.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        documentoPDF.close();
        try {
            java.awt.Desktop.getDesktop().open(new File(output));
        } catch (IOException ex) {
            Logger.getLogger(TelaRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:views.Clientes.java

private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
    try {/*  w w  w .  j a v  a 2s. co  m*/
        OutputStream file = new FileOutputStream(new File("C:\\CuotaSoft\\Historial.pdf"));
        Document document = new Document();
        PdfWriter writer;

        writer = PdfWriter.getInstance(document, file);

        document.open();
        // Se agrega titulo y datos del cliente
        Paragraph p = new Paragraph("Historial de Cliente \n",
                FontFactory.getFont("Arial", 16, Font.BOLD, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        Paragraph pNumero = new Paragraph("N Cliente: " + txtNroCliente.getText(),
                FontFactory.getFont("Arial", 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph pNombre = new Paragraph(
                "Nombre Cliente: " + txtNombre.getText() + " " + txtApellido.getText(),
                FontFactory.getFont("Arial", 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph pProductos = new Paragraph("Productos Comprados: ",
                FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK));
        pProductos.setAlignment(Element.ALIGN_CENTER);
        Paragraph pSaldo = new Paragraph("Saldo:  $" + txtSaldo.getText(),
                FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK));
        pSaldo.setAlignment(Element.ALIGN_RIGHT);
        //se agregan paragraphs
        document.add(p);
        document.add(pNumero);
        document.add(pNombre);
        document.add(pSaldo);
        document.add(new Paragraph("\n"));
        document.add(pProductos);
        document.add(new Paragraph("\n"));

        //se agrega tabla productos
        PdfPTable pTablaProducto = new PdfPTable(4);

        float[] mediaCeldasProductos = { 3.30f, 3.50f, 3.50f, 3.70f };

        pTablaProducto.setWidths(mediaCeldasProductos);
        pTablaProducto.addCell(new Paragraph("Producto", FontFactory.getFont("Arial", 12)));
        pTablaProducto.addCell(new Paragraph("Cantidad", FontFactory.getFont("Arial", 12)));
        pTablaProducto.addCell(new Paragraph("Precio", FontFactory.getFont("Arial", 12)));
        pTablaProducto.addCell(new Paragraph("Total", FontFactory.getFont("Arial", 12)));

        ArrayList<Venta> listaProductos = ctrlVenta.listByCliente(Integer.parseInt(txtID.getText()));

        for (Venta v : listaProductos) {
            Producto prod = ctrlProducto.buscarPorID(v.getProducto().getIdProducto());

            pTablaProducto.addCell(new Paragraph(prod.getNombreProducto(), FontFactory.getFont("Arial", 10)));
            pTablaProducto.addCell(
                    new Paragraph(String.valueOf(v.getCantidadVenta()), FontFactory.getFont("Arial", 10)));
            pTablaProducto.addCell(new Paragraph("$" + String.valueOf(prod.getPrecioProducto()),
                    FontFactory.getFont("Arial", 10)));
            pTablaProducto.addCell(
                    new Paragraph("$" + String.valueOf(v.getMontoVenta()), FontFactory.getFont("Arial", 10)));

        }

        document.add(pTablaProducto);

        Paragraph pTotalCompra = new Paragraph("Total Compras: " + txtTotalCompras.getText(),
                FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK));
        pTotalCompra.setAlignment(Element.ALIGN_RIGHT);
        document.add(pTotalCompra);
        document.add(new Paragraph("\n"));

        Paragraph pAbonos = new Paragraph("Abonos: ",
                FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK));
        pAbonos.setAlignment(Element.ALIGN_CENTER);

        document.add(pAbonos);

        document.add(new Paragraph("\n"));
        PdfPTable tablaAbonos = new PdfPTable(3);

        float[] mediaCeldasAbonos = { 3.30f, 3.50f, 3.50f };

        tablaAbonos.setWidths(mediaCeldasAbonos);
        tablaAbonos.addCell(new Paragraph("Fecha", FontFactory.getFont("Arial", 12)));
        tablaAbonos.addCell(new Paragraph("Monto", FontFactory.getFont("Arial", 12)));
        tablaAbonos.addCell(new Paragraph("Saldo", FontFactory.getFont("Arial", 12)));

        ArrayList<Abono> listaAbonos = ctrlAbono.listByCliente(txtID.getText());
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

        if (listaAbonos.size() > 0) {
            for (Abono a : listaAbonos) {

                tablaAbonos.addCell(
                        new Paragraph(sdf.format(a.getFechaAbono()), FontFactory.getFont("Arial", 10)));
                tablaAbonos.addCell(new Paragraph("$" + String.valueOf(a.getMontoAbono()),
                        FontFactory.getFont("Arial", 10)));
                tablaAbonos.addCell(new Paragraph("$" + String.valueOf(a.getSaldoAbono()),
                        FontFactory.getFont("Arial", 10)));
            }

        }
        document.add(tablaAbonos);

        document.close();
        file.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        File file = new File("C:\\CuotaSoft\\Historial.pdf");
        Desktop.getDesktop().open(file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Visao.grafico.GraficoRelatorioEstoque.java

private void GerarPDF() throws DocumentException, FileNotFoundException {
    try {/*from w  w w  . j  av a  2 s .  c  o  m*/
        int linha = jTableRelatorioGrafico.getSelectedRow();
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        //System.out.println(new File(".").getAbsolutePath());
        String arquivo = new File("RelatorioFaz.").getAbsolutePath() + "pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(arquivo));
        document.open();
        Font font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        //String titulo = jTableRelatorioEstoquePrincipal.getValueAt(linha, 3).toString()+ " "+jTableRelatorioEstoquePrincipal.getValueAt(linha, 2).toString()+"-"+jTableRelatorioEstoquePrincipal.getValueAt(linha, 0).toString();
        String titulo = "Relatorio";
        Paragraph pgt = new Paragraph(titulo, font);
        pgt.setAlignment(Element.ALIGN_CENTER);
        document.add(pgt);
        document.add(new Paragraph(" "));
        PdfPTable table = new PdfPTable(colunas.length);
        // Definindo uma fonte, com tamanho 20 e negrito
        PdfPCell header = new PdfPCell(new Paragraph(titulo, font));
        header.setColspan(colunas.length);
        table.addCell(header);
        table.setWidthPercentage(100.0f);
        table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
        //System.out.println("Tamanho: "+linhas.size());
        font = new Font(Font.FontFamily.TIMES_ROMAN, 4, Font.NORMAL);
        for (String coluna : colunas) {
            table.addCell(new Paragraph(coluna, font));
        }

        //varias linhas
        for (int i = 0; i < linhas.size(); i++) {//linha
            for (int j = 0; j < colunas.length; j++) {//coluna
                table.addCell(new Paragraph(jTableRelatorioGrafico.getValueAt(i, j).toString(), font));
            }
        }

        document.add(table);

        document.add(new Paragraph(" "));

        font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        document.add(new Paragraph("Dados Totais", font));
        font = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL);
        document.close();
        JOptionPane.showMessageDialog(null, "PDF: " + arquivo + " gerado!");
    } catch (FileNotFoundException | DocumentException | HeadlessException ex) {
        Logger.getLogger(GerarRelatorioEstoqueBasico.class.getName()).log(Level.SEVERE, null,
                "Erro ao gerar pdf: " + ex);
        JOptionPane.showMessageDialog(null, "Erro ao gerar pdf: " + ex);
    }
}

From source file:Visao.Relatorio.GraficoPerCapta.java

public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException {
    Document document = null;/*from w w w . j a va  2 s .c  o  m*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        //add image
        int width = 500;
        int height = 400;

        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        document.add(image);

        Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
        String quebralinha = "\n\nPopulao dos Estados\n\n";
        Paragraph preface = new Paragraph(quebralinha, boldFont);
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);

        PdfPTable table = new PdfPTable(2);

        PdfPCell pdfWordCell = new PdfPCell();
        PdfPCell pdfWordCell1 = new PdfPCell();
        Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));
        Phrase secondLine = new Phrase("Populao", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));

        pdfWordCell.addElement(firstLine);
        pdfWordCell1.addElement(secondLine);

        table.addCell(pdfWordCell);
        table.addCell(pdfWordCell1);

        table.addCell("SP");
        table.addCell(String.valueOf(44396484));

        table.addCell("MG");
        table.addCell(String.valueOf(20869101));

        table.addCell("RJ");
        table.addCell(String.valueOf(16550024));

        table.addCell("BA");
        table.addCell(String.valueOf(15203934));

        table.addCell("RS");
        table.addCell(String.valueOf(11247972));

        table.addCell("PR");
        table.addCell(String.valueOf(11163018));

        table.addCell("PE");
        table.addCell(String.valueOf(9345173));

        table.addCell("CE");
        table.addCell(String.valueOf(8904459));

        table.addCell("PA");
        table.addCell(String.valueOf(8175113));

        table.addCell("MA");
        table.addCell(String.valueOf(6904241));

        table.addCell("SC");
        table.addCell(String.valueOf(6819190));

        table.addCell("GO");
        table.addCell(String.valueOf(6610681));

        table.addCell("PB");
        table.addCell(String.valueOf(3972202));

        table.addCell("AM");
        table.addCell(String.valueOf(3938336));

        table.addCell("ES");
        table.addCell(String.valueOf(3929911));

        table.addCell("RN");
        table.addCell(String.valueOf(3442175));

        table.addCell("AL");
        table.addCell(String.valueOf(3340932));

        table.addCell("MT");
        table.addCell(String.valueOf(3270973));

        table.addCell("PI");
        table.addCell(String.valueOf(3204028));

        table.addCell("DF");
        table.addCell(String.valueOf(2914830));

        table.addCell("MS");
        table.addCell(String.valueOf(2651235));

        table.addCell("SE");
        table.addCell(String.valueOf(2242937));

        table.addCell("RO");
        table.addCell(String.valueOf(1768204));

        table.addCell("TO");
        table.addCell(String.valueOf(1515126));

        table.addCell("AC");
        table.addCell(String.valueOf(803513));

        table.addCell("AP");
        table.addCell(String.valueOf(766679));

        table.addCell("RR");
        table.addCell(String.valueOf(505665));

        document.add(table);

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:Visao.Relatorio.Relatorio_Geral.java

public void create(OutputStream outputStream) throws DocumentException, IOException {
    Document document = null;/*from www .  j  a v  a 2s  .c  om*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        Paragraph paragraph = new Paragraph("\n\nRelatrio Geral\n\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD));
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);

        document.add(new Paragraph("Quantidade de Reclamaoes Cadastradas: " + quantidadeReclamacao + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de Empresas Cadastradas: " + quantidadeEmpresa + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de Regies Cadastradas: " + quantidadeRegiao + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de UFs Cadastrados: " + quantidadeUF + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de Cidades Cadastradas: " + quantidadeCidade + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Tempo Mdio de Resposta: " + decimalFormat.format(tempoMedio) + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Nota Mdia: " + decimalFormat.format(notamedia) + "\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph(
                "Quantidade de Reclamaes Resolvidas: " + resolvida + " - " + resolvidaPorcentagem + "%\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de Reclamaes No Resolvidas: " + naoresolvida + " - "
                + naoresolvidaPorcentagem + "%\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.add(new Paragraph("Quantidade de Reclamaes No Avaliadas: " + naoavaliada + " - "
                + naoavaliadaPorcentagem + "%\n", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)));
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesCidadeIntervalo.java

public void create(OutputStream outputStream) throws DocumentException, IOException {
    Document document = null;/*from  w ww.  ja v  a  2s .  com*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        Paragraph paragraph = new Paragraph("\n\nReclamaes\n\nCidade: " + cidade,
                new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD));
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);

        Paragraph paragraph1 = new Paragraph("\nMs Abertura: " + mes + "\nAno Abertura: " + ano,
                new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));

        document.add(paragraph1);

        document.add(new Paragraph("\n\n\n"));

        PdfPTable table = new PdfPTable(3);
        PdfPCell pdfWordCell = new PdfPCell();
        PdfPCell pdfWordCell1 = new PdfPCell();
        PdfPCell pdfWordCell2 = new PdfPCell();
        Phrase firstLine = new Phrase("Quantidade de reclamaes",
                new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
        Phrase secondLine = new Phrase("Nota mdia consumidor",
                new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
        Phrase thirdLine = new Phrase("Tempo mdio de resposta",
                new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

        pdfWordCell.addElement(firstLine);
        pdfWordCell1.addElement(secondLine);
        pdfWordCell2.addElement(thirdLine);

        table.addCell(pdfWordCell);
        table.addCell(pdfWordCell1);
        table.addCell(pdfWordCell2);

        table.addCell(String.valueOf(quantidade));
        table.addCell(decimalFormat.format(notamedia));
        table.addCell(decimalFormat.format(tempoResposta) + " dias");

        document.add(table);

        document.add(new Paragraph("\n\n\nEmpresas Reclamadas\n\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)));

        PdfPTable table1 = new PdfPTable(2);
        PdfPCell pdfWordCel3 = new PdfPCell();
        PdfPCell pdfWordCel4 = new PdfPCell();
        Phrase firstLine1 = new Phrase("Empresa", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
        Phrase secondLine1 = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

        pdfWordCel3.addElement(firstLine1);
        pdfWordCel4.addElement(secondLine1);

        table1.addCell(pdfWordCel3);
        table1.addCell(pdfWordCel4);

        String consulta = "Select e.nomefantasia, count(r.codigoreclamacao)" + " from Reclamacao r, Empresa e"
                + " where r.codempresa = e.codigoempresa and" + " r.cidade='" + cidade + "' and r.mesabertura="
                + mes + " and r.anoabertura=" + ano + " group by e.nomefantasia" + " order by e.nomefantasia";

        Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator();

        while (i.hasNext()) {
            Object[] reclamacaoEmpresa = (Object[]) i.next();
            table1.addCell(reclamacaoEmpresa[0].toString());
            table1.addCell(reclamacaoEmpresa[1].toString());
        }

        document.add(table1);

        document.add(new Paragraph("\n\n\nAssuntos Reclamados\n\n",
                new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)));
        PdfPTable table2 = new PdfPTable(2);
        PdfPCell pdfWordCel5 = new PdfPCell();
        PdfPCell pdfWordCel6 = new PdfPCell();
        Phrase firstLine5 = new Phrase("Assunto", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

        pdfWordCel5.addElement(firstLine5);
        pdfWordCel6.addElement(secondLine1);

        table2.addCell(pdfWordCel5);
        table2.addCell(pdfWordCel6);

        String consulta1 = "select assunto, count(codigoreclamacao)" + " from Reclamacao where cidade='"
                + cidade + "'" + " and mesabertura=" + mes + " and anoabertura=" + ano + " group by assunto "
                + " order by assunto";
        Iterator ii = dao.getSessao().createSQLQuery(consulta1).list().iterator();

        while (ii.hasNext()) {
            Object[] reclamacaoAssunto = (Object[]) ii.next();
            table2.addCell(reclamacaoAssunto[0].toString());
            table2.addCell(reclamacaoAssunto[1].toString());
        }

        document.add(table2);

        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesUF.java

public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException {
    Document document = null;/*from w w  w  .  ja v a2 s  .  c o m*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        //add image
        int width = 500;
        int height = 400;

        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        document.add(image);

        Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
        String quebralinha = "\n\nQuantidade de reclamaes por UF\n\n";
        Paragraph preface = new Paragraph(quebralinha, boldFont);
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);

        PdfPTable table = new PdfPTable(2);

        PdfPCell pdfWordCell = new PdfPCell();
        PdfPCell pdfWordCell1 = new PdfPCell();
        Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));
        Phrase secondLine = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));

        pdfWordCell.addElement(firstLine);
        pdfWordCell1.addElement(secondLine);

        table.addCell(pdfWordCell);
        table.addCell(pdfWordCell1);

        String consulta = "Select uf, count(codigoreclamacao) from "
                + "Reclamacao group by (uf) order by count(codigoreclamacao) desc";

        Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator();

        while (i.hasNext()) {
            Object[] reclamacao = (Object[]) i.next();
            table.addCell(reclamacao[0].toString());
            table.addCell(reclamacao[1].toString());
        }

        document.add(table);

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:Visao.relatorios.GerarRelatorioCarvao.java

private void GerarPDF() throws DocumentException, FileNotFoundException {
    try {/*from  w w w.j a  va  2 s. c o m*/
        int linha = jTableRelatorioCarvao.getSelectedRow();
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        //System.out.println(new File(".").getAbsolutePath());
        String arquivo = new File("Relatorio Carvo Praa.").getAbsolutePath() + "pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(arquivo));
        document.open();
        Font font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        //String titulo = jTableRelatorioEstoquePrincipal.getValueAt(linha, 3).toString()+ " "+jTableRelatorioEstoquePrincipal.getValueAt(linha, 2).toString()+"-"+jTableRelatorioEstoquePrincipal.getValueAt(linha, 0).toString();
        String titulo = "Relatorio Carvo Praa";
        Paragraph pgt = new Paragraph(titulo, font);
        pgt.setAlignment(Element.ALIGN_CENTER);
        document.add(pgt);
        document.add(new Paragraph(" "));
        /*if(!filtro_matgen.equals("")){
            titulo = "Material genetico "+filtro_matgen;
        }*/
        PdfPTable table = new PdfPTable(colunas.length);
        // Definindo uma fonte, com tamanho 20 e negrito
        PdfPCell header = new PdfPCell(new Paragraph(titulo, font));
        header.setColspan(colunas.length);
        table.addCell(header);
        table.setWidthPercentage(100.0f);
        table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
        //System.out.println("Tamanho: "+linhas.size());
        font = new Font(Font.FontFamily.TIMES_ROMAN, 4, Font.NORMAL);
        for (String coluna : colunas) {
            table.addCell(new Paragraph(coluna, font));
        }

        //varias linhas
        for (int i = 0; i < linhas.size(); i++) {//linha
            for (int j = 0; j < colunas.length; j++) {//coluna
                //table.addCell(jTableRelatorioEstoquePrincipal.getValueAt(i, j).toString());
                table.addCell(new Paragraph(jTableRelatorioCarvao.getValueAt(i, j).toString(), font));
            }
        }

        document.add(table);
        document.add(new Paragraph(" "));

        font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        document.add(new Paragraph("Dados Totais", font));
        font = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL);
        document.add(new Paragraph(jLabelInfo1.getText(), font));
        document.add(new Paragraph(jLabelVolumeMadeiraTotal.getText(), font));
        document.add(new Paragraph(jLabelVolumeCarvaoTotal.getText(), font));
        document.close();
        JOptionPane.showMessageDialog(null, "PDF: " + arquivo + " gerado!");
    } catch (FileNotFoundException | DocumentException | HeadlessException ex) {
        Logger.getLogger(GerarRelatorioEstoqueBasico.class.getName()).log(Level.SEVERE, null,
                "Erro ao gerar pdf: " + ex);
        JOptionPane.showMessageDialog(null, "Erro ao gerar pdf: " + ex);
    }

}

From source file:Visao.relatorios.GerarRelatorioCarvaoExpedido.java

private void GerarPDF() throws DocumentException, FileNotFoundException {
    try {//from   w w  w. ja v  a2s  . c o m
        int linha = jTableExpedirCarvao.getSelectedRow();
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        //System.out.println(new File(".").getAbsolutePath());
        String arquivo = new File("Relatorio Carvo Expedido.").getAbsolutePath() + "pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(arquivo));
        document.open();
        Font font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        //String titulo = jTableRelatorioEstoquePrincipal.getValueAt(linha, 3).toString()+ " "+jTableRelatorioEstoquePrincipal.getValueAt(linha, 2).toString()+"-"+jTableRelatorioEstoquePrincipal.getValueAt(linha, 0).toString();
        String titulo = "Relatorio Carvo Expedido";
        Paragraph pgt = new Paragraph(titulo, font);
        pgt.setAlignment(Element.ALIGN_CENTER);
        document.add(pgt);
        document.add(new Paragraph(" "));
        /*if(!filtro_matgen.equals("")){
            titulo = "Material genetico "+filtro_matgen;
        }*/
        PdfPTable table = new PdfPTable(colunas.length);
        // Definindo uma fonte, com tamanho 20 e negrito
        PdfPCell header = new PdfPCell(new Paragraph(titulo, font));
        header.setColspan(colunas.length);
        table.addCell(header);
        table.setWidthPercentage(100.0f);
        table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
        //System.out.println("Tamanho: "+linhas.size());
        font = new Font(Font.FontFamily.TIMES_ROMAN, 4, Font.NORMAL);
        for (String coluna : colunas) {
            table.addCell(new Paragraph(coluna, font));
        }

        //varias linhas
        for (int i = 0; i < linhas.size(); i++) {//linha
            for (int j = 0; j < colunas.length; j++) {//coluna
                //table.addCell(jTableRelatorioEstoquePrincipal.getValueAt(i, j).toString());
                table.addCell(new Paragraph(jTableExpedirCarvao.getValueAt(i, j).toString(), font));
            }
        }

        document.add(table);
        document.add(new Paragraph(" "));

        font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        document.add(new Paragraph("Dados Totais", font));
        font = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL);
        document.add(new Paragraph(jLabelInfo1.getText(), font));
        document.add(new Paragraph(jLabelPesoTotal.getText(), font));
        document.add(new Paragraph(jLabelVolumeTotal.getText(), font));
        document.close();
        JOptionPane.showMessageDialog(null, "PDF: " + arquivo + " gerado!");
    } catch (FileNotFoundException | DocumentException | HeadlessException ex) {
        Logger.getLogger(GerarRelatorioEstoqueBasico.class.getName()).log(Level.SEVERE, null,
                "Erro ao gerar pdf: " + ex);
        JOptionPane.showMessageDialog(null, "Erro ao gerar pdf: " + ex);
    }

}