Example usage for com.lowagie.text.pdf PdfPCell setPadding

List of usage examples for com.lowagie.text.pdf PdfPCell setPadding

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setPadding.

Prototype

public void setPadding(float padding) 

Source Link

Document

Sets the padding of the contents in the cell (space between content and border).

Usage

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

private List<ColumnText> fillTable(float height) {
    // copy text for simulation
    List<ColumnText> tt = null;
    if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
        // more column breaks than available column
        // we try not to lose content
        // but results may be different than in open office
        // anyway it is logical error made by document creator
        tt = new ArrayList<ColumnText>();
        ColumnText t = createColumnText();
        tt.add(t);//  w w w. j  a  va  2s.c o m
        for (int i = 0; i < texts.size(); i++) {
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100.0f);
            PdfPCell cell = new PdfPCell();
            cell.setBorder(Table.NO_BORDER);
            cell.setPadding(0.0f);
            cell.setColumn(ColumnText.duplicate(texts.get(i)));
            table.addCell(cell);
            t.addElement(table);
        }
    } else {
        tt = new ArrayList<ColumnText>(texts);
        for (int i = 0; i < tt.size(); i++) {
            tt.set(i, ColumnText.duplicate(tt.get(i)));
        }
    }
    // clear layout table
    clearTable(layoutTable, true);
    setWidthIfNecessary();

    // try to fill cells with text
    ColumnText t = tt.get(0);
    for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        cell.setColumn(ColumnText.duplicate(t));
        //
        t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(),
                height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
        int res = 0;
        try {
            res = t.go(true);
        } catch (DocumentException e) {
            throw new ODFConverterException(e);
        }
        if (!ColumnText.hasMoreText(res)) {
            // no overflow in current column
            if (tt.size() == 1) {
                // no more text
                return null;
            } else {
                // some text waiting for new column
                tt.remove(0);
                t = tt.get(0);
            }
        }
    }
    return tt;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static SectionPdfPTable createLayoutTable(float width, float height,
        List<StyleColumnProperties> columnPropertiesList) {
    // create one row table which will layout section text
    int colCount = columnPropertiesList.size();
    int relativeWidths[] = new int[colCount];
    SectionPdfPTable table = new SectionPdfPTable(colCount);
    // add cells/*from  w  w w .  j a va 2 s  .  c  o m*/
    for (int i = 0; i < colCount; i++) {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Table.NO_BORDER);
        cell.setPadding(0.0f);
        cell.setColumn(createColumnText());
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        // apply styles to cell
        StyleColumnProperties columnProperties = columnPropertiesList.get(i);
        relativeWidths[i] = columnProperties.getRelWidth();
        cell.setPaddingLeft(
                columnProperties.getStartIndent() != null ? columnProperties.getStartIndent() : 0.0f);
        cell.setPaddingRight(columnProperties.getEndIndent() != null ? columnProperties.getEndIndent() : 0.0f);
        table.addCell(cell);
    }
    replaceTableCells(table);
    // set width
    try {
        table.setWidths(relativeWidths);
    } catch (DocumentException e) {
        throw new ODFConverterException(e);
    }
    table.setTotalWidth(width);
    table.setLockedWidth(true);
    return table;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.elements.StylableDocumentSection.java

License:Open Source License

private List<ColumnText> fillTable(float height) {
    // copy text for simulation
    List<ColumnText> tt = null;
    if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
        // more column breaks than available column
        // we try not to lose content
        // but results may be different than in open office
        // anyway it is logical error made by document creator
        tt = new ArrayList<ColumnText>();
        ColumnText t = createColumnText();
        tt.add(t);// www. ja  va  2s  .  c  o  m
        for (int i = 0; i < texts.size(); i++) {
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100.0f);
            PdfPCell cell = new PdfPCell();
            cell.setBorder(Table.NO_BORDER);
            cell.setPadding(0.0f);
            cell.setColumn(ColumnText.duplicate(texts.get(i)));
            table.addCell(cell);
            t.addElement(table);
        }
    } else {
        tt = new ArrayList<ColumnText>(texts);
        for (int i = 0; i < tt.size(); i++) {
            tt.set(i, ColumnText.duplicate(tt.get(i)));
        }
    }
    // clear layout table
    clearTable(layoutTable, true);
    setWidthIfNecessary();

    // try to fill cells with text
    ColumnText t = tt.get(0);
    for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        cell.setColumn(ColumnText.duplicate(t));
        //
        t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(),
                height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
        int res = 0;
        try {
            res = t.go(true);
        } catch (DocumentException e) {
            throw new XWPFConverterException(e);
        }
        if (!ColumnText.hasMoreText(res)) {
            // no overflow in current column
            if (tt.size() == 1) {
                // no more text
                return null;
            } else {
                // some text waiting for new column
                tt.remove(0);
                t = tt.get(0);
            }
        }
    }
    return tt;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.elements.StylableDocumentSection.java

License:Open Source License

public static SectionPdfPTable createLayoutTable(float width, float height,
        List<StyleColumnProperties> columnPropertiesList) {
    // create one row table which will layout section text
    int colCount = columnPropertiesList.size();
    int relativeWidths[] = new int[colCount];
    SectionPdfPTable table = new SectionPdfPTable(colCount);
    // add cells/*  www.  j  a  v  a 2 s  .  com*/
    for (int i = 0; i < colCount; i++) {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Table.NO_BORDER);
        cell.setPadding(0.0f);
        cell.setColumn(createColumnText());
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        // apply styles to cell
        StyleColumnProperties columnProperties = columnPropertiesList.get(i);
        relativeWidths[i] = columnProperties.getRelWidth();
        cell.setPaddingLeft(
                columnProperties.getStartIndent() != null ? columnProperties.getStartIndent() : 0.0f);
        cell.setPaddingRight(columnProperties.getEndIndent() != null ? columnProperties.getEndIndent() : 0.0f);
        table.addCell(cell);
    }
    replaceTableCells(table);
    // set width
    try {
        table.setWidths(relativeWidths);
    } catch (DocumentException e) {
        throw new XWPFConverterException(e);
    }
    table.setTotalWidth(width);
    table.setLockedWidth(true);
    return table;
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedChapter.java

License:Open Source License

private synchronized PdfPCell createPdfPCell() {
    if (cell != null) {
        return cell;
    }/*w  ww  .j a  v  a 2  s.c  o m*/
    PdfPCell cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setPadding(0);
    return cell;
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedParagraph.java

License:Open Source License

private PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setBorder(Table.NO_BORDER);//ww  w. j  ava 2  s  .c  o  m
    cell.setPadding(0.0f);
    cell.setUseBorderPadding(true);
    cell.getColumn().setAdjustFirstLine(false);
    return cell;
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java

License:Open Source License

private PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setBorder(Table.NO_BORDER);//  w w  w. ja  va  2 s  .c o m
    cell.setPadding(0.0f);
    cell.setUseBorderPadding(true);
    return cell;
}

From source file:ilarkesto.integration.itext.Cell.java

License:Open Source License

@Override
public Element getITextElement() {
    PdfPCell cell = new PdfPCell();

    cell.setBorderColorTop(getBorderTopColor());
    cell.setBorderColorBottom(getBorderBottomColor());
    cell.setBorderColorLeft(getBorderLeftColor());
    cell.setBorderColorRight(getBorderRightColor());
    cell.setBorderWidthTop(APdfBuilder.mmToPoints(getBorderTopWidth()));
    cell.setBorderWidthBottom(APdfBuilder.mmToPoints(getBorderBottomWidth()));
    cell.setBorderWidthLeft(APdfBuilder.mmToPoints(getBorderLeftWidth()));
    cell.setBorderWidthRight(APdfBuilder.mmToPoints(getBorderRightWidth()));
    cell.setUseBorderPadding(false);//from  www  .j a  v  a 2  s  . co m

    cell.setPadding(0);
    cell.setPaddingTop(APdfBuilder.mmToPoints(getPaddingTop()));
    cell.setPaddingBottom(APdfBuilder.mmToPoints(getPaddingBottom()));
    cell.setPaddingLeft(APdfBuilder.mmToPoints(getPaddingLeft()));
    cell.setPaddingRight(APdfBuilder.mmToPoints(getPaddingRight()));

    cell.setBackgroundColor(getBackgroundColor());
    cell.setExtraParagraphSpace(0);
    cell.setIndent(0);

    cell.setColspan(getColspan());
    for (ItextElement element : elements)
        cell.addElement(element.getITextElement());
    return cell;
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col)
        throws BadElementException, IOException, SaveReportException {

    CellStyle style = model.getStyles(srcCell.getStyleId());

    java.awt.Rectangle rect = model.getCellRect(row, col, true, true);

    float h = Math.round((float) Units.PT.setYPixels((int) rect.getHeight()));
    float w = Math.round((float) Units.PT.setXPixels((int) rect.getWidth()));

    PdfPCell pdfCell = null;

    if (srcCell.getPicture() != null) {
        java.awt.Image awtImage = srcCell.getPicture().getImage();
        com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h);
        pdfCell = new PdfPCell(image);
    } else {//w  ww.  ja  v  a2s  .  c  om

        String text = null;

        if (srcCell.getValue() instanceof CellValue<?>) {

            StringWriter strWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(strWriter);

            if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this,
                    ReportBook.PDF)) {
                java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col);
                if (awtImage != null) {
                    com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h);
                    pdfCell = new PdfPCell(image);
                }
            } else {
                text = strWriter.getBuffer().toString();
            }

        } else {
            if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) {
                pdfCell = new PdfPCell();
                writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell);
            } else {
                text = model.getCellText(srcCell);
            }
        }

        if (pdfCell == null) {
            pdfCell = new PdfPCell();
        }

        if (text != null && text.length() > 0) {
            com.lowagie.text.Font font;
            if (fonts.containsKey(style.getId())) {
                font = fonts.get(style.getId());
            } else {
                font = getFontMapper().styleToPdf(style);
                fonts.put(style.getId(), font);
            }
            Paragraph p;
            if (font != null) {
                p = new Paragraph(text, font);
            } else {
                p = new Paragraph(text);
            }
            pdfCell.setPhrase(p);
            pdfCell.setPadding(1);
            pdfCell.setLeading(0f, 1.1f);
        } else {
            pdfCell.setPadding(0);
        }
    }

    pdfCell.setFixedHeight(h);
    pdfCell.setBackgroundColor(style.getBackground());
    pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment()));
    pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment()));

    if (style.getAngle() != 0) {
        pdfCell.setRotation(roundAngle(style.getAngle()));
    }

    assignBorders(style, pdfCell);
    pdfCell.setNoWrap(!style.isWrapLine());
    if (srcCell.getColSpan() > 0) {
        pdfCell.setColspan(srcCell.getColSpan() + 1);
    }
    if (srcCell.getRowSpan() > 0) {
        pdfCell.setRowspan(srcCell.getRowSpan() + 1);
    }

    return pdfCell;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setCeldaPDF(String texto, int tipo, int tamanio, int estilo, int alineacion, int borde,
        int padding) {
    PdfPCell celda = new PdfPCell(new Paragraph(texto, new Font(tipo, tamanio, estilo)));
    celda.setHorizontalAlignment(alineacion);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    celda.setBorderColor(Color.LIGHT_GRAY);
    celda.setBorderWidth(borde);//from ww  w . java 2 s.c om
    celda.setPadding(padding);
    return celda;
}