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

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

Introduction

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

Prototype

public void setUseDescender(boolean useDescender) 

Source Link

Document

Setter for property useDescender.

Usage

From source file:org.areasy.common.doclet.utilities.PDFUtility.java

License:Open Source License

/**
 * Create a cell element./*from  w  w  w.  j  a  va 2s. c  om*/
 */
public static PdfPCell createElementCell(int padding, int alignment, Element[] elements) {
    Element mainElement;

    // If there are no nested tables in content
    if (!hasTablesOrLists(elements)) {
        Paragraph para = new Paragraph();
        para.setAlignment(alignment);

        for (int i = 0; i < elements.length; i++) {
            try {
                para.add(elements[i]);
            } catch (Exception e) {
                String msg = "Failed to add element to paragraph: " + e.toString();
                DocletUtility.error(msg);
            }
        }

        mainElement = para;

    } else {

        PdfPTable cellTable = new PdfPTable(1);
        Paragraph currInnerPara = null;

        for (int i = 0; i < elements.length; i++) {

            Element element = elements[i];

            /* Check for special element created by TagTABLE */
            if (element instanceof TableParagraph)
                element = ((TableParagraph) elements[i]).getTable();

            if (element instanceof PdfPTable || element instanceof List) {

                if (currInnerPara != null) {
                    PdfPCell innerCell = createElementCell(0, alignment, currInnerPara);
                    innerCell.setUseDescender(true); // needs newer iText
                    innerCell.setUseAscender(true); // needs newer iText
                    innerCell.setPaddingBottom(2.0f);
                    cellTable.addCell(innerCell);
                }

                currInnerPara = null;
                cellTable.addCell(createElementCell(0, alignment, element));

            } else {
                if (currInnerPara == null) {
                    currInnerPara = new Paragraph();
                    currInnerPara.setAlignment(alignment);
                }

                try {
                    currInnerPara.add(element);
                } catch (Exception e) {
                    String msg = "Failed to add element to inner paragraph: " + e.toString();
                    DocletUtility.error(msg);
                }
            }
        }

        if (currInnerPara != null)
            cellTable.addCell(createElementCell(0, alignment, currInnerPara));

        mainElement = cellTable;
    }

    return createElementCell(padding, alignment, mainElement);
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

private PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setBorder(Table.NO_BORDER);/*ww  w  .ja v  a  2 s .com*/
    cell.setPadding(0.0f);
    cell.setUseBorderPadding(true);
    cell.getColumn().setAdjustFirstLine(false);
    cell.setUseDescender(true);
    return cell;
}

From source file:questions.tables.TableHeaderAlternateBackground.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4.rotate());
    try {//from  w  w  w  . j a v a  2  s . c  om
        // step 2:
        // we create a writer
        PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a table to the document
        PdfPTable datatable = new PdfPTable(10);
        datatable.setTableEvent(new AlternateBackground());
        int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 };
        datatable.setWidths(headerwidths);
        datatable.setWidthPercentage(100);
        datatable.getDefaultCell().setPadding(5);

        // The header starts with a cell that spans 10 columns
        PdfPCell cell = new PdfPCell(new Phrase("Administration - System Users Report",
                FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2);
        cell.setColspan(10);
        cell.setBackgroundColor(Color.YELLOW);
        cell.setUseDescender(true);
        datatable.addCell(cell);
        // We need 4 cells with rowspan 2
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setBackgroundColor(Color.YELLOW);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell("User Id");
        datatable.addCell("Name\nAddress");
        datatable.addCell("Company");
        datatable.addCell("Department");
        datatable.getDefaultCell().setBackgroundColor(null);
        // we use a nested table to fake this
        PdfPTable permissions = new PdfPTable(6);
        permissions.getDefaultCell().setBackgroundColor(Color.YELLOW);
        permissions.getDefaultCell().setBorderWidth(2);
        permissions.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        permissions.getDefaultCell().setColspan(6);
        permissions.addCell("Permissions");
        permissions.getDefaultCell().setColspan(1);
        permissions.addCell("Admin");
        permissions.addCell("Data");
        permissions.addCell("Expl");
        permissions.addCell("Prod");
        permissions.addCell("Proj");
        permissions.addCell("Online");
        PdfPCell permission = new PdfPCell(permissions);
        permission.setColspan(6);
        datatable.addCell(permission);
        // this is the end of the table header
        // as far as PdfPTable is concerned there are 2 rows in the header
        datatable.setHeaderRows(2);

        // we add the data to the table
        datatable.getDefaultCell().setBorderWidth(1);
        for (int i = 1; i < 50; i++) {
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell("myUserId");
            datatable.addCell("Person " + i);
            datatable.addCell("No Name Company");
            datatable.addCell("D" + i);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            for (int j = 0; j < 6; j++)
                datatable.addCell(Math.random() > .5 ? "Yes" : "No");
        }
        document.add(datatable);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}