Example usage for com.itextpdf.text.pdf PdfPCell setUseBorderPadding

List of usage examples for com.itextpdf.text.pdf PdfPCell setUseBorderPadding

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setUseBorderPadding.

Prototype

public void setUseBorderPadding(boolean use) 

Source Link

Document

Adjusts effective padding to include border widths.

Usage

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private PdfPTable getTable(Map it) throws Exception {
    String ss = MapUtil.getStr(it, "widthList", "100");
    List<String> st = MapUtil.getSelectList(ss);
    float[] widths = new float[st.size()];
    for (int i = 0; i < st.size(); i++)
        widths[i] = LightUtil.decodeFloat(st.get(i));
    PdfPTable table = new PdfPTable(widths);
    table.setExtendLastRow(false, false);
    MapUtil.setIfFloat(it, "spacingAfter", table);
    MapUtil.setIfFloat(it, "spacingBefore", table);
    MapUtil.setIfInt(it, "headerRows", table);
    MapUtil.setIfInt(it, "footerRows", table);
    MapUtil.setIfBool(it, "skipFirstHeader", table);
    MapUtil.setIfBool(it, "skipLastFooter", table);
    MapUtil.setIfFloat(it, "widthPercentage", table);
    MapUtil.setIfBool(it, "splitRows", table);
    MapUtil.setIfBool(it, "splitLate", table);
    MapUtil.setIfBool(it, "extendLastRow", table);
    MapUtil.setIfBool(it, "keepTogether", table);
    List<Map> items = (List) it.get("items");
    if (items != null) {
        for (Map cell : items) {
            Element el = getElement(cell);

            PdfPCell pc = new PdfPCell();
            if (el != null)
                if (el instanceof Phrase)
                    pc = new PdfPCell((Phrase) el);
                else if (el instanceof Image)
                    pc = new PdfPCell((Image) el);
                else {
                    pc.addElement(el);//from   www . j a va  2  s. c  om
                }
            pc.setHorizontalAlignment(getAlignment(cell, "align"));
            pc.setVerticalAlignment(getVAlign(cell, "valign"));
            pc.setUseBorderPadding(true);
            MapUtil.setIfInt(cell, "rowspan", pc);
            MapUtil.setIfInt(cell, "colspan", pc);
            MapUtil.setIfInt(cell, "border", pc);
            MapUtil.setIfInt(cell, "rotation", pc);
            MapUtil.setIfFloat(cell, "borderWidth", pc);

            BaseColor color = getColor(cell, "bgColor");
            if (color != null)
                pc.setBackgroundColor(color);
            table.addCell(pc);
        }
    }
    return table;
}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public PdfPTable getShoppingBasketForAuthor(Author a, PdfContentByte cb) {
    int position = 0;
    float subtotal_CHF = 0.0f;
    float shipping_CHF = 0.0f;
    float vat25_CHF = 0.0f;
    float vat80_CHF = 0.0f;

    String author = a.getShortName();

    BarcodeEAN codeEAN = new BarcodeEAN();

    // Pos | Menge | Eancode | Bezeichnung | MwSt | Preis
    PdfPTable table = new PdfPTable(new float[] { 1, 2, 3, 6, 1, 2 });
    table.setWidthPercentage(100f);//from ww  w. ja  va  2 s  .  c o m
    table.getDefaultCell().setPadding(5);
    table.setSpacingAfter(5f);

    PdfPCell cell = new PdfPCell();

    table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("vat"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_RIGHT, 1));
    table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10,
            Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1));

    if (m_shopping_basket.size() > 0 && !author.isEmpty()) {
        for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) {
            Article article = entry.getValue();
            if (article.getAuthor().trim().toLowerCase().contains(author)) {
                String price_pruned = "";
                String total_price_CHF = "";
                if (article.getCode() != null && article.getCode().equals("ibsa")) {
                    float cr = article.getCashRebate();
                    if (article.getDraufgabe() > 0) {
                        price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f));
                        total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(0.0f));
                    } else {
                        price_pruned = String.format("%.2f", article.getBuyingPrice(cr));
                        total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(cr));
                    }
                } else {
                    price_pruned = article.getCleanExfactoryPrice();
                    total_price_CHF = String.format("%.2f", article.getTotExfactoryPrice());
                }

                if (!price_pruned.isEmpty() && !price_pruned.equals("..")) {
                    // Index
                    table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    // Anzahl
                    table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
                    // EAN code
                    codeEAN.setCode(article.getEanCode());
                    Image img = codeEAN.createImageWithBarcode(cb, null, null);
                    img.scalePercent(120);
                    cell = new PdfPCell(img);
                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    cell.setUseBorderPadding(true);
                    cell.setBorderWidth(5);
                    if (position == 1)
                        cell.setPaddingTop(8);
                    else
                        cell.setPaddingTop(0);
                    cell.setPaddingBottom(8);
                    table.addCell(cell);
                    // Artikelbezeichnung
                    table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    // MwSt                  
                    table.addCell(getStringCell(String.format("%.1f%%", article.getVat()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1));
                    // Preis (exkl. MwSt)
                    // float price_CHF = article.getQuantity()*Float.parseFloat(price_pruned);
                    table.addCell(getStringCell(total_price_CHF, font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_RIGHT, 1));
                }
            }
        }

        subtotal_CHF = a.getSubtotal();
        shipping_CHF = a.getShippingCosts();
        vat25_CHF = a.getVat25();
        vat80_CHF = a.getVat80() + a.getShippingCosts() * 0.08f;

        float fulltotal_CHF = subtotal_CHF + shipping_CHF + vat25_CHF + vat80_CHF;

        table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", subtotal_CHF), font_bold_10, Rectangle.TOP,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("shipping"), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", shipping_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", vat25_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (8.0%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", vat80_CHF), font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", fulltotal_CHF), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_RIGHT, 2));
    }
    return table;
}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public PdfPTable getFullShoppingBasket(PdfContentByte cb, String mode) {
    int position = 0;
    float sub_total_CHF = 0.0f;

    BarcodeEAN codeEAN = new BarcodeEAN();

    // Pos | Menge | Eancode | Bezeichnung | Preis
    PdfPTable table = new PdfPTable(new float[] { 1, 1, 3, 6, 2 });
    table.setWidthPercentage(100f);/*from   w ww. j  a v a2  s  .  c o m*/
    table.getDefaultCell().setPadding(5);
    table.setSpacingAfter(5f);

    PdfPCell cell = new PdfPCell();

    table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM,
            Element.ALIGN_MIDDLE, 1));
    table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10,
            Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1));

    if (m_shopping_basket.size() > 0) {
        for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) {
            Article article = entry.getValue();

            if (mode.equals("all") || (mode.equals("rest") && (m_map_of_authors == null
                    || !anyElemIsContained(m_map_of_authors, article.getAuthor().trim().toLowerCase())))) {
                String price_pruned = "";
                if (article.getCode() != null && article.getCode().equals("ibsa")) {
                    float cr = article.getCashRebate();
                    if (article.getDraufgabe() > 0)
                        price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f));
                    else
                        price_pruned = String.format("%.2f", article.getBuyingPrice(cr));
                } else {
                    price_pruned = article.getCleanExfactoryPrice();
                }

                if (!price_pruned.isEmpty() && !price_pruned.equals("..")) {
                    table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));
                    table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));

                    codeEAN.setCode(article.getEanCode());
                    Image img = codeEAN.createImageWithBarcode(cb, null, null);
                    img.scalePercent(120);
                    cell = new PdfPCell(img);
                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                    cell.setUseBorderPadding(true);
                    cell.setBorderWidth(5);
                    if (position == 1)
                        cell.setPaddingTop(8);
                    else
                        cell.setPaddingTop(0);
                    cell.setPaddingBottom(8);
                    table.addCell(cell);

                    table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER,
                            Element.ALIGN_MIDDLE, 1));

                    float price_CHF = article.getQuantity() * Float.parseFloat(price_pruned);
                    sub_total_CHF += price_CHF;
                    table.addCell(getStringCell(String.format("%.2f", price_CHF), font_norm_10,
                            PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1));
                }
            }
        }

        table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF), font_bold_10, Rectangle.TOP,
                Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 0.025f), font_norm_10,
                PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2));

        table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER,
                Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2));
        table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 1.025f), font_bold_10,
                PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2));
    }
    return table;
}

From source file:net.digitstar.vanadio.helpers.PdfHelper.java

License:Apache License

public static PdfPCell newCell(CellStyle style) {
    PdfPCell cell = new PdfPCell();
    if (style != null) {
        if (style.getNestedTable() != null) {
            cell = new PdfPCell(style.getNestedTable());
            style.setNestedTable(null);/*  w  w w  .  ja  v a  2 s  .  co  m*/
        } else if (style.getImage() != null) {
            cell = new PdfPCell(style.getImage(), style.isFitImage());
            style.setImage(null);
        } else if (style.getText() != null) {
            cell = new PdfPCell(style.getText());
            style.setText((String) null);
        }

        cell.setColspan(style.getColspan());
        cell.setRowspan(style.getRowspan());

        cell.setMinimumHeight(style.getMinimumHeight());
        cell.setFixedHeight(style.getFixedHeight());

        cell.setNoWrap(style.isNoWrap());

        cell.setRotation(style.getRotation().getValue());

        style = Alignment.assign(style);

        cell.setHorizontalAlignment(style.getHorizAlign().getValue());
        cell.setVerticalAlignment(style.getVertAlign().getValue());

        cell.setUseVariableBorders(style.isUseVariableBorders());
        cell.setUseBorderPadding(style.isUseBorderPadding());

        if (!style.getBorderWidth().isAllSideEqual()) {
            cell.setBorderWidthBottom(style.getBorderWidth().getBottom());
            cell.setBorderWidthLeft(style.getBorderWidth().getLeft());
            cell.setBorderWidthRight(style.getBorderWidth().getRight());
            cell.setBorderWidthTop(style.getBorderWidth().getTop());
        } else {
            cell.setBorderWidth(style.getBorderWidth().getValue());
        }

        cell.setPaddingBottom(style.getPadding().getBottom());
        cell.setPaddingLeft(style.getPadding().getLeft());
        cell.setPaddingRight(style.getPadding().getRight());
        cell.setPaddingTop(style.getPadding().getTop());

        cell.setBorderColorBottom(style.getBorderColor().getBottom());
        cell.setBorderColorLeft(style.getBorderColor().getLeft());
        cell.setBorderColorRight(style.getBorderColor().getRight());
        cell.setBorderColorTop(style.getBorderColor().getTop());

        cell.setBorder(style.getBorder().getValue());

        cell.setBackgroundColor(style.getBackgroundColor());
        if (style.getGreyFill() >= 0) {
            cell.setGrayFill(style.getGreyFill());
        }
    }
    return cell;
}

From source file:org.jaqpot.core.service.data.ReportService.java

/** helper function to add logo image in header*/
public static PdfPCell createImageCell(String path) throws DocumentException, IOException {
    Image img = Image.getInstance(path);
    img.scaleToFit(120f, 120f);/*w  ww.ja  v  a 2  s.c  o m*/
    PdfPCell cell = new PdfPCell(img, false);
    cell.setPaddingBottom(5f);
    cell.setUseBorderPadding(true);
    cell.setBorder(Rectangle.BOTTOM);
    return cell;
}

From source file:printers.AbstractHorariosPrinter.java

License:Open Source License

private PdfPCell createCeldaHorarioItem(HorarioItem h, int fila, int columna, int numColumnas, int numFilas) {
    Paragraph p;/*ww  w  .j  a  v  a  2s .com*/
    PdfPCell c;
    if (!h.isHuecoLibre()) {

        p = getParagraphForAsignatura(h);
        c = new PdfPCell(p);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        //Color col = h.getAsignatura().getColorEnTablaDeHorarios();
        Color col = h.getTramo().getColorEnTablaDeHorarios();
        c.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));
        c.setPadding(5);
        c.setBorderColor(BaseColor.BLACK);
        c.setBorderWidth(1);
        c.setUseBorderPadding(false);
        c.setUseVariableBorders(true);

    } else {
        p = new Paragraph("");//"C"+h.getNumcasilla()+" D"+h.getDiaSemana()+" "+h.getRangoHoras().getInicio());
        c = new PdfPCell(p);
        c.setUseVariableBorders(true);
        c.setBorderColor(BaseColor.LIGHT_GRAY);
        c.setBorderWidth(.3F);
        //            c.setBorder(Rectangle.NO_BORDER);
        if (columna == numColumnas - 1) {
            c.setBorderColorRight(BaseColor.BLACK);
        }
        //            if (fila == numFilas - 1) {
        //                c.setBorder(Rectangle.BOTTOM);
        //            }
        //            if ((columna == numColumnas - 1) && (fila == numFilas - 1)) {
        //                c.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
        //            }
    }

    if (h.getNumeroDeCasillasQueOcupa() > 1) {
        c.setRowspan(h.getNumeroDeCasillasQueOcupa());

    }

    return c;
}