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

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

Introduction

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

Prototype

public void setWidths(final int relativeWidths[]) throws DocumentException 

Source Link

Document

Sets the relative widths of the table.

Usage

From source file:com.coderbd.pos.pdf.BarcodePdf.java

public void generateBarcodePdf(int amount) throws UnsupportedEncodingException {
    try {/*w  w w .java  2 s  .c om*/
        String filename = directory + "\\" + barcodeData + ".pdf";
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(barcodeData);
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(3);
        float[] widths = { 0.45f, .10f, .45f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(shop.getShopName(), shop.getShopId(), amount);
        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Paragraph paragraph = new Paragraph(codeName);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                                                    -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);

            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.close();
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
    }
}

From source file:com.coderbd.pos.pdf.BarcodePdf.java

public void generateBarcodePdf(boolean fixedRate, Product p) throws UnsupportedEncodingException {
    try {//from  www .j a  v a2s  .c  o  m
        String filename = directory + "\\" + barcodeData + ".pdf";
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(barcodeData);
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(3);
        float[] widths = { 0.45f, .10f, .45f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(shop.getShopName(), shop.getShopId(), (int) p.getProductBuyRate());
        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Paragraph paragraph = new Paragraph(codeName);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                                                    -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);

            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.close();
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
    }
}

From source file:com.coderbd.pos.pdf.CodePDF.java

public boolean genCodeVer2Pdf() throws UnsupportedEncodingException {

    if (isFixedRated == true) {
        barcodeQuantity = 12;/* w  w  w .  ja  v  a2s  .  c  om*/
    } else {
        barcodeQuantity = 15;
    }

    try {
        String filename = "";

        if (isFixedRated) {
            filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf";
        } else {
            filename = directory + "\\" + product.getProductBarcode() + ".pdf";
        }

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(product.getProductBarcode());
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(7);
        pdfPTable.setWidthPercentage(98);
        float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(),
                (int) product.getProductBuyRate());

        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
        Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);

        Paragraph paragraph = new Paragraph(codeName, titleArialFont);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont);
        PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph);
        fixedRateCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                           -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            /**
             *
             */
            if (isFixedRated == true) {
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
            }
            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.add(new Paragraph(
                "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName()
                        + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(),
                titleArialFont));
        document.close();
        return true;
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
        return false;
    }
}

From source file:com.coderbd.pos.pdf.OrderReportPDF.java

public boolean genPdf() throws UnsupportedEncodingException {
    List<SupplierOrderProductReport> soprs = sor.getSupplierOrderProductReports();
    IDBuilder idBuilder = new IDBuilder();
    Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
    Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);
    try {/*from  w ww  .  j  a v a2s .c o m*/
        String timestamp = idBuilder.getUniqueTimeStampID();
        String filename = sor.getSupplier().getSupplierName() + "_O" + sor.getSupplierOrderId() + "_"
                + timestamp + ".pdf";
        String filePath = directory + "\\" + filename;

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
        document.open();

        PdfPTable pdfPTable = new PdfPTable(5);

        pdfPTable.setWidthPercentage(90);
        float[] widths = { 0.40f, 0.13f, 0.15f, 0.15f, 0.17f };
        pdfPTable.addCell(new Paragraph("Product Name", headerFont));
        pdfPTable.addCell(new Paragraph("Buy Rate", headerFont));
        pdfPTable.addCell(new Paragraph("Primary Qty", headerFont));
        pdfPTable.addCell(new Paragraph("Unsold Qty", headerFont));
        pdfPTable.addCell(new Paragraph("Unsold Amount", headerFont));

        pdfPTable.setWidths(widths);
        for (SupplierOrderProductReport sopr : soprs) {

            SupplierOrderProduct sop = sopr.getSupplierOrderProduct();
            String name = sop.getSupplierProductName();
            Double rate = sop.getSupplierRate();
            Integer pQty = sop.getSupplierProductQuantity();
            Integer unQty = sopr.getUnSoldProductQuantity();
            Double unAmount = sopr.getUnSoldProductAmount();

            Paragraph nameParag = new Paragraph(name, innerFont);
            Paragraph buyRateParag = new Paragraph(rate.toString(), innerFont);
            Paragraph primaryQuantityParag = new Paragraph(pQty.toString(), innerFont);
            Paragraph unsoldQuantityParag = new Paragraph(unQty.toString(), innerFont);
            Paragraph unsoldAmountParag = new Paragraph(unAmount.toString(), innerFont);

            PdfPCell nameCell = new PdfPCell(nameParag);
            PdfPCell buyRateCell = new PdfPCell(buyRateParag);
            PdfPCell primaryQuantityCell = new PdfPCell(primaryQuantityParag);
            PdfPCell unsoldQuantityCell = new PdfPCell(unsoldQuantityParag);
            PdfPCell unsoldAmountCell = new PdfPCell(unsoldAmountParag);

            pdfPTable.addCell(nameCell);
            pdfPTable.addCell(buyRateCell);
            pdfPTable.addCell(primaryQuantityCell);
            pdfPTable.addCell(unsoldQuantityCell);
            pdfPTable.addCell(unsoldAmountCell);
        }
        document.add(getHeader());

        document.add(pdfPTable);
        document.add(getFooter());
        document.add(new Paragraph("            Report Generated: " + new Date().toString(), innerFont));
        document.close();
        return true;
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
        return false;
    }
}

From source file:com.coderbd.pos.pdf.OrderReportPDF.java

public PdfPTable getFooter() throws DocumentException {
    Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
    Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);

    PdfPTable pdfPTableFooter = new PdfPTable(2);
    pdfPTableFooter.setWidthPercentage(90);
    float[] widthsFooter = { 0.80f, 0.20f };
    pdfPTableFooter.setWidths(widthsFooter);

    Paragraph totalSoldPara = new Paragraph("Total Sold: " + sor.getOrderTotalSoldAmount().toString(),
            headerFont);//from   ww w .  ja  va2s.c  o m
    PdfPCell totalSoldCell = new PdfPCell(totalSoldPara);
    totalSoldCell.setBorder(Rectangle.NO_BORDER);

    Paragraph totalUnSoldPara = new Paragraph("Total UnSold: " + sor.getOrderTotalUnsoldAmount().toString(),
            headerFont);
    PdfPCell totalUnSoldCell = new PdfPCell(totalUnSoldPara);
    totalUnSoldCell.setBorder(Rectangle.NO_BORDER);

    Paragraph blankPara = new Paragraph("");
    PdfPCell blankCell = new PdfPCell(blankPara);
    blankCell.setBorder(Rectangle.NO_BORDER);

    Double bill = sor.getTotalBill();
    Double paid = sor.getTotalPaid();
    Double due = bill - paid;

    Paragraph billPara = new Paragraph("BILL: " + bill.toString(), headerFont);
    PdfPCell billCell = new PdfPCell(billPara);
    billCell.setBorder(Rectangle.NO_BORDER);

    Paragraph paidPara = new Paragraph("PAID: " + paid.toString(), headerFont);
    PdfPCell paidCell = new PdfPCell(paidPara);
    paidCell.setBorder(Rectangle.NO_BORDER);

    Paragraph duePara = new Paragraph("DUE: " + due.toString(), headerFont);
    PdfPCell dueCell = new PdfPCell(duePara);
    dueCell.setBorder(Rectangle.NO_BORDER);

    pdfPTableFooter.addCell(totalSoldCell);
    pdfPTableFooter.addCell(billCell);
    pdfPTableFooter.addCell(totalUnSoldCell);
    pdfPTableFooter.addCell(paidCell);
    pdfPTableFooter.addCell(blankCell);
    pdfPTableFooter.addCell(dueCell);

    return pdfPTableFooter;
}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableDeItens(List<ItemDeVenda> itens) throws DocumentException {

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 5, 1, 1, 1 });
    table.setWidthPercentage(100f);/*from   w ww .  j  a v a2 s .c o m*/
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Produto");
    table.addCell("Quantidade");
    table.addCell("Valor UN");
    table.addCell("Total");
    table.getDefaultCell().setBackgroundColor(null);

    for (ItemDeVenda it : itens) {
        table.addCell(it.getDescricaoProduto());

        table.addCell(new DecimalFormat("0.000").format(it.getQuantidade()));
        table.addCell(new DecimalFormat("0.00").format(it.getValorProduto()));
        table.addCell(new DecimalFormat("0.00").format(it.getTotal()));
    }

    return table;

}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos) throws DocumentException {
    double total_requisitado = 381624.18;

    Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos);

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 5, 2, 1, 1 });
    table.setWidthPercentage(100f);// w ww . jav a  2 s  .c o m
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Produto");
    table.addCell("Quantidade em Estoque");
    table.addCell("Valor de Compra");
    table.addCell("SubTotal");
    table.getDefaultCell().setBackgroundColor(null);
    double quantidade = 0, total = 0;
    List<String> c = new ArrayList<String>();
    c.addAll(saida.keySet());
    Collections.sort(c);
    for (String produto : c) {

        Double[] val = saida.get(produto);

        double qt, vc, sub;
        qt = val[0];
        vc = val[1];
        sub = val[0] * val[1];

        if (qt > 0 && qt < 10000) {
            quantidade += qt;
            total += (qt * vc);
            table.addCell(produto);
            table.addCell(new DecimalFormat("0.000").format(qt));
            table.addCell(new DecimalFormat("0.00").format(vc));
            table.addCell(new DecimalFormat("0.00").format(qt * vc));
        } else {
            continue;
            //table.addCell(new DecimalFormat("0.00").format(val[1]));
            //table.addCell(new DecimalFormat("0.000").format(0));
            //table.addCell(new DecimalFormat("0.00").format(vc));
            //table.addCell(new DecimalFormat("0.00").format(0));
        }
        if (total_requisitado - 10 <= total && total <= total_requisitado + 10) {
            break;
        }

    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto(
    //       saida.size()) + " Produtos");

    //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade)
    //        + " Itens");

    String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(381624.18);
    PdfPCell cel2 = new PdfPCell(new Paragraph(tot));
    cel2.setColspan(2);
    cel2.setHorizontalAlignment(Element.ALIGN_CENTER);
    cel2.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cel2);

    //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total));
    //System.out.println(total);
    return table;
}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos, boolean paraLista,
        List<String> codigos_retirados, double total_requisitado) throws DocumentException {
    //double total_requisitado = 381624.18;

    Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos,
            codigos_retirados);/*from   w  w  w.  j  a v a2  s  .  c o m*/

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 5, 2, 1, 1 });
    table.setWidthPercentage(100f);
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Produto");
    table.addCell("Quantidade em Estoque");
    table.addCell("Valor de Compra");
    table.addCell("SubTotal");
    table.getDefaultCell().setBackgroundColor(null);
    double quantidade = 0, total = 0;
    List<String> c = new ArrayList<String>();
    c.addAll(saida.keySet());
    Collections.sort(c);
    for (String produto : c) {
        if (paraLista && total_requisitado <= total) {
            break;
        }

        Double[] val = saida.get(produto);

        double qt, vc, sub;
        qt = val[0];
        vc = val[1];
        sub = val[0] * val[1];

        if (qt > 0 && qt < 10000) {
            quantidade += qt;
            total += (qt * vc);
            table.addCell(produto);
            table.addCell(new DecimalFormat("0.000").format(qt));
            table.addCell(new DecimalFormat("0.00").format(vc));
            table.addCell(new DecimalFormat("0.00").format(qt * vc));
        } else {
            continue;
            //table.addCell(new DecimalFormat("0.00").format(val[1]));
            //table.addCell(new DecimalFormat("0.000").format(0));
            //table.addCell(new DecimalFormat("0.00").format(vc));
            //table.addCell(new DecimalFormat("0.00").format(0));
        }

    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto(
    //       saida.size()) + " Produtos");

    //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade)
    //        + " Itens");

    String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total_requisitado);
    PdfPCell cel2 = new PdfPCell(new Paragraph(tot));
    cel2.setColspan(2);
    cel2.setHorizontalAlignment(Element.ALIGN_CENTER);
    cel2.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cel2);

    //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total));
    //System.out.println(total);
    return table;
}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableBalancoProdutos(Date inicio, Date fim) throws DocumentException {
    Map<String, Double[]> saida = GeradorRelatorio.getRelatorioDetalhadoSaidaProduto(inicio, fim);

    PdfPTable table = new PdfPTable(5);
    table.setWidths(new int[] { 5, 1, 1, 1, 1 });
    table.setWidthPercentage(100f);//from w  w  w .  ja  v  a 2s.co  m
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Produto");
    table.addCell("Estoque");
    table.addCell("Compra");
    table.addCell("Venda");
    table.addCell("Lucro");
    table.getDefaultCell().setBackgroundColor(null);
    double compra = 0, venda = 0, lucro = 0, qt = 0;
    List<String> c = new ArrayList<String>();
    c.addAll(saida.keySet());
    Collections.sort(c);
    for (String produto : c) {
        table.addCell(produto);
        Double[] val = saida.get(produto);
        compra += val[0];
        venda += val[1];
        lucro += val[3];
        qt += val[2];
        table.addCell(new DecimalFormat("0.000").format(val[2]));
        table.addCell(new DecimalFormat("0.00").format(val[0]));
        table.addCell(new DecimalFormat("0.00").format(val[1]));
        table.addCell(new DecimalFormat("0.00").format(val[3]));
    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setColspan(5);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    table.addCell(saida.size() + " Produtos");

    table.addCell(new DecimalFormat("0.000").format(qt));
    table.addCell(new DecimalFormat("0.00").format(compra));
    table.addCell(new DecimalFormat("0.00").format(venda));
    table.addCell(new DecimalFormat("0.00").format(lucro));

    return table;
}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableDebitoClientes(double maiorQue) throws DocumentException {
    List<Object[]> debitos = GeradorRelatorio.getRelatorioClientesComDebitoMaiorQue(maiorQue);

    PdfPTable table = new PdfPTable(2);
    table.setWidths(new int[] { 5, 2 });
    table.setWidthPercentage(100f);/*from   w  ww.  j av a 2  s  .c  o m*/
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Cliente");
    table.addCell("Dbito");
    table.getDefaultCell().setBackgroundColor(null);
    double total = 0;
    for (Object[] d : debitos) {
        table.addCell((String) d[0]);
        double val = (double) d[1];
        table.addCell(OperacaoStringUtil.formatarStringValorMoedaEPonto(val));
        total += val;
    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total));

    table.addCell("Quantidade de Clientes");
    table.addCell(OperacaoStringUtil.formatarStringValorInteger(debitos.size()));

    return table;
}