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

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

Introduction

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

Prototype

public float getWidthPercentage() 

Source Link

Document

Gets the width percentage that the table will occupy in the page.

Usage

From source file:Control.ProcessaArq.java

public void gravaArquivoConsumoUsuarios(ArrayList<Usuario> lista, String caminho)
        throws IOException, DocumentException {

    Document doc = null;//from  ww w .jav  a2 s .  com
    OutputStream os = null;
    Paragraph p = new Paragraph();
    Tratamento tempo = new Tratamento();
    DecimalFormat df = new DecimalFormat("#####.##");
    String informacao, tipo = new String();
    Double soma, valorTotal = 0.0;

    PdfPTable table = new PdfPTable(5); //tabela com 5 colunas
    float[] headerwidths = { 30, 80, 35, 35, 25 }; // define a largura de cada coluna  
    table.setWidths(headerwidths);

    caminho = localizaArquivo(false) + ".pdf";
    try {//configuraes da pgina          
        float fntSize, lineSpacing;
        fntSize = 8f;
        lineSpacing = 8f;
        doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40);

        os = new FileOutputStream(caminho);
        PdfWriter.getInstance(doc, os);
        doc.open();

        //cabecalho da tabela
        table.getDefaultCell().setBorder(0);
        table.getWidthPercentage();

        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.getDefaultCell().setColspan(5);

        table.addCell(new Paragraph("CONSUMO POR USU?RIOS ") + banco.periodoFatura());

        table.getDefaultCell().setBorder(1);
        table.getDefaultCell().setColspan(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);

        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.getDefaultCell().setBorder(1);

        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(new Paragraph("Cidade"));
        table.addCell(new Paragraph("Usurio"));
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(new Paragraph("Nmero"));
        table.addCell(new Paragraph("Tipo"));
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(new Paragraph("Valor"));
        table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

        soma = 0.0;
        for (int a = 0; a <= lista.size() - 1; a++) {

            //cidade
            informacao = new String();
            informacao = lista.get(a).getCidade();
            //    table.setTotalWidth(80);
            table.addCell(new Paragraph(informacao));

            //Usurio
            informacao = new String();
            informacao = lista.get(a).getNome();
            //    table.setTotalWidth(200);
            table.addCell(new Paragraph(informacao));

            //Nmero
            informacao = new String();
            informacao = String.valueOf(lista.get(a).getLinha());
            //    table.setTotalWidth(10);
            table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            table.addCell(new Paragraph(informacao));

            //Tipo
            informacao = new String();
            informacao = lista.get(a).getTipo();
            //    table.setTotalWidth(10);
            table.addCell(new Paragraph(informacao));

            //Valor
            informacao = new String();
            soma += lista.get(a).getValor();
            informacao = "R$" + df.format(lista.get(a).getValor());
            //    table.setTotalWidth(10);
            table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            table.addCell(new Paragraph(informacao));
        }

        // Total
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        informacao = new String();
        informacao = "Total";
        table.addCell(informacao);

        // tempo                               
        table.addCell("");
        table.addCell("");
        table.addCell("");

        // valor
        informacao = new String();
        informacao = "R$" + df.format(soma);
        table.addCell(informacao);
        table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

        doc.add(table);
        // fim da pgina
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:Control.ProcessaArq.java

public void gravaArquivoServicos(ArrayList<Conta> lista, String caminho) throws IOException, DocumentException {
    ArrayList<String> listaTipos;
    String local[];//from  ww  w  .  j av a  2  s. c  om
    Document doc = null;
    OutputStream os = null;
    Paragraph p = new Paragraph();
    Tratamento tempo = new Tratamento();
    DecimalFormat df = new DecimalFormat("#####.##");
    String informacao, tempoServico, tempoSubTotal, tempoTotal, tipo = new String();
    Double soma, valorTotal = 0.0;

    PdfPTable table = new PdfPTable(3); //tabela com 3 colunas
    float[] headerwidths = { 85, 35, 25 }; // define a largura de cada coluna
    table.setWidths(headerwidths);

    caminho = localizaArquivo(false) + ".pdf";
    try {//configuraes da pgina          
        float fntSize, lineSpacing;
        fntSize = 10f;
        lineSpacing = 10f;
        doc = new Document(PageSize.A4.rotate(), 10, 10, 20, 10);

        os = new FileOutputStream(caminho);
        PdfWriter.getInstance(doc, os);
        doc.open();

        tempoTotal = "00:00:00";
        tempoServico = "00:00:00";
        tempoSubTotal = "00:00:00";
        listaTipos = new ArrayList<String>();

        //cabecalho da tabela
        table.getDefaultCell().setBorder(0);
        table.getWidthPercentage();

        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.getDefaultCell().setColspan(3);

        table.addCell(new Paragraph(tempo.verificaNomeServico(lista) + " " + banco.periodoFatura()));

        table.getDefaultCell().setBorder(1);
        table.getDefaultCell().setColspan(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);

        for (int a = 0; a < lista.size() - 1; a++) {
            System.out.println(a + " - " + lista.get(a).getTipo());

            if (!listaTipos.contains(lista.get(a).getTipo())) {

                listaTipos.add(lista.get(a).getTipo());
                soma = 0.0;
                tipo = new String();
                informacao = new String();

                informacao = "" + listaTipos.get(listaTipos.size() - 1) + "";
                table.getDefaultCell().setBorder(1);
                table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                table.getDefaultCell().setColspan(3);
                table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);

                table.addCell(new Paragraph(informacao));

                table.getDefaultCell().setBorder(1);
                table.getDefaultCell().setColspan(0);
                table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
                table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);

                // contedo da tabela
                for (int b = 0; b <= lista.size() - 1; b++) {
                    if (lista.get(b).getTipo().equals(listaTipos.get(listaTipos.size() - 1))) {

                        soma += lista.get(b).getValor();
                        tempoServico = tempo.somaTempo(lista.get(b).getDuracao(), tempoServico);
                        tempoSubTotal = tempo.somaTempo(tempoServico, tempoSubTotal);
                        tempoTotal = tempo.somaTempo(tempoServico, tempoTotal);
                        tipo = listaTipos.get(listaTipos.size() - 1);

                        informacao = new String();
                        informacao = lista.get(b).getDescricaoServico();
                        table.setTotalWidth(80);
                        table.addCell(new Paragraph(informacao));

                        informacao = new String();
                        informacao = tempoServico + " (" + tempo.conversaoHoraMinuto(tempoServico) + ")";
                        table.setTotalWidth(30);
                        table.addCell(new Paragraph(informacao));

                        informacao = new String();
                        informacao = "R$" + df.format(lista.get(b).getValor());
                        table.setTotalWidth(20);
                        table.addCell(new Paragraph(informacao));

                        tempoServico = "00:00:00";
                        //    System.out.println(informacao);                                 
                    }
                }
                //rodap da tabela
                listaTipos.add(tipo);
                valorTotal += soma;

                // subtotal
                table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
                informacao = new String();
                informacao = "Sub Total:";
                table.addCell(informacao);

                // tempo
                informacao = new String();
                informacao = tempoSubTotal + " (" + tempo.conversaoHoraMinuto(tempoSubTotal) + ")";
                table.addCell(informacao);

                // valor
                informacao = new String();
                informacao = "R$" + df.format(soma);
                table.addCell(informacao);
                table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

                // espao entre tabelas

                table.getDefaultCell().setBorder(1);
                table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                table.getDefaultCell().setColspan(3);
                table.addCell(new Paragraph("* * * * *"));
                table.getDefaultCell().setColspan(0);
                table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                table.getDefaultCell().setBorder(0);

                tempoSubTotal = "00:00:00";
                //    System.out.println(informacao);   
            }
        }
        // fim da pgina

        // valor total
        informacao = new String();
        informacao = "Total Geral:  ";
        table.getDefaultCell().setBorder(1);
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(informacao);
        table.getDefaultCell().setBorder(1);

        // tempo
        informacao = new String();
        informacao = tempoTotal + " (" + tempo.conversaoHoraMinuto(tempoTotal) + ")";
        table.addCell(informacao);

        //valor
        informacao = new String();
        informacao = "R$" + df.format(valorTotal);
        table.addCell(informacao);

        doc.add(table);
        //    System.out.println(informacao);

    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}