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

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

Introduction

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

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void exportRow(DataTable table, PdfPTable pdfTable, int rowIndex) {
    table.setRowIndex(rowIndex);/*  www . j  a v a 2 s .com*/

    if (!table.isRowAvailable()) {
        return;
    }

    exportCells(table, pdfTable);
    SummaryRow sr = table.getSummaryRow();

    if (sr != null && sr.isInView()) {
        for (UIComponent summaryComponent : sr.getChildren()) {
            UIColumn column = (UIColumn) summaryComponent;
            StringBuilder builder = new StringBuilder();

            for (UIComponent component : column.getChildren()) {
                if (component.isRendered()) {
                    String value = exportValue(FacesContext.getCurrentInstance(), component);

                    if (value != null) {
                        builder.append(value);
                    }
                }
            }
            int rowSpan = column.getRowspan();
            int colSpan = column.getColspan();
            PdfPCell cell = new PdfPCell(new Paragraph(builder.toString(), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }
            if (rowSpan > 1) {
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                cell.setRowspan(rowSpan);

            }
            if (colSpan > 1) {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(colSpan);

            }
            pdfTable.addCell(cell);
        }
    }
}

From source file:com.bytecode.customexporter.PDFCustomExporter.java

protected void exportCells(DataTable table, PdfPTable pdfTable) {
    for (UIColumn col : table.getColumns()) {

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }//from w ww. jav  a 2  s .c o m

        if (col.isRendered() && col.isExportable()) {
            if (col.getSelectionMode() != null) {
                pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont));
                continue;
            }
            addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data");
        }

    }
    pdfTable.completeRow();
    FacesContext context = null;
    if (table.getRowIndex() == 0) {
        for (UIComponent component : table.getChildren()) {
            if (component instanceof RowExpansion) {
                RowExpansion rowExpansion = (RowExpansion) component;
                if (rowExpansion.getChildren() != null) {
                    if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                        DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                        childTable.setRowIndex(-1);
                    }
                    if (rowExpansion.getChildren().get(0) instanceof DataList) {
                        DataList childList = (DataList) rowExpansion.getChildren().get(0);
                        childList.setRowIndex(-1);
                    }
                }

            }
        }
    }
    for (UIComponent component : table.getChildren()) {
        if (component instanceof RowExpansion) {
            RowExpansion rowExpansion = (RowExpansion) component;
            if (rowExpansion.getChildren() != null) {
                if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                    DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                    pdfTable.addCell(cell);
                }
                if (rowExpansion.getChildren().get(0) instanceof DataList) {
                    DataList list = (DataList) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-");
                    pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                }
            }

        }
        pdfTable.completeRow();
    }

}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

License:Open Source License

private static String parseTable(WikiPDFContext context, Wiki wiki, String line, Document document,
        Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, BufferedReader in)
        throws Exception {
    if (line == null) {
        return null;
    }//from  w  w w  . j av  a 2 s . c o m
    PdfPTable pdfTable = null;
    int columnCount = 0;
    int rowCount = 0;

    // Keep track of the table's custom styles
    HashMap<Integer, String> cStyle = new HashMap<Integer, String>();

    while (line != null && (line.startsWith("|") || line.startsWith("!"))) {

        // Build a complete line
        String lineToParse = line;
        while (!line.endsWith("|")) {
            line = in.readLine();
            if (line == null) {
                // there is an error in the line to process
                return null;
            }
            if (line.startsWith("!")) {
                lineToParse += CRLF + line.substring(1);
            }
        }
        line = lineToParse;

        // Determine if the row can output
        boolean canOutput = true;

        ++rowCount;

        String cellType = null;
        Scanner sc = null;
        if (line.startsWith("||") && line.endsWith("||")) {
            cellType = "th";
            sc = new Scanner(line).useDelimiter("[|][|]");
            //        sc = new Scanner(line.substring(2, line.length() - 2)).useDelimiter("[|][|]");
        } else if (line.startsWith("|")) {
            cellType = "td";
            sc = new Scanner(line.substring(1, line.length() - 1)).useDelimiter("\\|(?=[^\\]]*(?:\\[|$))");
        }

        if (sc != null) {

            if (rowCount == 1) {
                // Count the columns, get the specified widths too...
                while (sc.hasNext()) {
                    ++columnCount;
                    sc.next();
                }
                // Reset the scanner now that the columns have been counted
                if (line.startsWith("||") && line.endsWith("||")) {
                    sc = new Scanner(line).useDelimiter("[|][|]");
                } else if (line.startsWith("|")) {
                    sc = new Scanner(line.substring(1, line.length() - 1))
                            .useDelimiter("\\|(?=[^\\]]*(?:\\[|$))");
                }

                // Start the table
                pdfTable = new PdfPTable(columnCount);
                //pdfTable.setWidthPercentage(100);
                pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
                pdfTable.setSpacingBefore(10);
                pdfTable.setWidthPercentage(100);
                pdfTable.setKeepTogether(true);
            }

            // Determine the column span
            int colSpan = 1;
            // Determine the cell being output
            int cellCount = 0;

            while (sc.hasNext()) {
                String cellData = sc.next();
                if (cellData.length() == 0) {
                    ++colSpan;
                    continue;
                }

                // Track the cell count being output
                ++cellCount;

                if (rowCount == 1) {
                    // Parse and validate the style input
                    LOG.debug("Checking style value: " + cellData);
                    if (cellData.startsWith("{") && cellData.endsWith("}")) {
                        String[] style = cellData.substring(1, cellData.length() - 1).split(":");
                        String attribute = style[0].trim();
                        String value = style[1].trim();
                        // Determine the width of each column and store it
                        if ("width".equals(attribute)) {
                            // Validate the width style
                            if (StringUtils.hasAllowedOnly("0123456789%.", value)) {
                                cStyle.put(cellCount, attribute + ": " + value + ";");
                            }
                        } else {
                            LOG.debug("Unsupported style: " + cellData);
                        }
                        canOutput = false;
                    }
                }

                // Output the header
                if (canOutput) {

                    PdfPCell cell = new PdfPCell();
                    cell.setPadding(10);
                    cell.setBorderColor(new Color(100, 100, 100));
                    if ("th".equals(cellType)) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
                    }
                    if (colSpan > 1) {
                        cell.setColspan(colSpan);
                    }

                    // Output the data
                    if (" ".equals(cellData) || "".equals(cellData)) {
                        // Put a blank space in blank cells for output consistency
                        cell.addElement(new Chunk(" "));
                        LOG.debug("   OUTPUTTING A BLANK");
                    } else {
                        // Output the cell as a complete wiki
                        float cellWidth = (100.0f / columnCount);
                        parseContent(context, wiki, cellData, document, cell, db, wikiListTodo, wikiListDone,
                                cellWidth);
                        LOG.debug("   OUTPUTTING CONTENT");
                    }
                    pdfTable.addCell(cell);
                }
            }
        }
        // read another line to see if it's part of the table
        line = in.readLine();
    }
    if (pdfTable != null) {
        LOG.debug("document.add(pdfTable)");
        document.add(pdfTable);
        //          document.add(Chunk.NEWLINE);
    }
    return line;
}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

License:Open Source License

protected static String parseForm(WikiPDFContext context, Connection db, BufferedReader in, String line,
        Document document, PdfPCell cell) throws Exception {
    if (line == null) {
        return line;
    }//from  www .jav  a  2 s  .c  om
    CustomForm form = WikiToHTMLUtils.retrieveForm(in, line);
    LOG.debug("parseForm");
    for (CustomFormGroup group : form) {
        LOG.debug(" group...");
        // Start the table

        PdfPTable pdfTable = new PdfPTable(2);
        pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
        pdfTable.setSpacingBefore(10);
        //      pdfTable.setWidthPercentage(100);
        pdfTable.setKeepTogether(true);

        if (group.getDisplay() && StringUtils.hasText(group.getName())) {
            // output the 1st row with a colspan of 2
            if (StringUtils.hasText(group.getName())) {
                Paragraph groupParagraph = new Paragraph(group.getName());
                PdfPCell groupCell = new PdfPCell(groupParagraph);
                groupCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                groupCell.setColspan(2);
                groupCell.setPadding(20);
                groupCell.setBorderColor(new Color(100, 100, 100));
                groupCell.setBackgroundColor(new Color(200, 200, 200));
                groupCell.setNoWrap(true);
                pdfTable.addCell(groupCell);
            }
        }
        for (CustomFormField field : group) {
            LOG.debug("  field...");
            if (field.hasValue()) {
                // output the row (2 columns: label, value)
                Paragraph fieldLabelParagraph = new Paragraph(field.getLabel());
                PdfPCell fieldLabelCell = new PdfPCell(fieldLabelParagraph);
                fieldLabelCell.setPadding(20);
                fieldLabelCell.setBorderColor(new Color(100, 100, 100));
                //          fieldLabelCell.setNoWrap(true);
                pdfTable.addCell(fieldLabelCell);

                Paragraph fieldValueParagraph = new Paragraph(getFieldValue(context, field));
                PdfPCell fieldValueCell = new PdfPCell(fieldValueParagraph);
                fieldValueCell.setPadding(20);
                fieldValueCell.setBorderColor(new Color(100, 100, 100));
                //          fieldValueCell.setNoWrap(true);
                pdfTable.addCell(fieldValueCell);
            }
        }
        LOG.debug("document.add(pdfTable)");
        document.add(pdfTable);

    }
    return null;
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableFacet(FacesContext context, PdfPTable pdfTable, DataTable table, int columnCount,
        String facetType) {/*from  w  w w.j a v a 2  s  .  c  o  m*/
    Map<String, UIComponent> map = table.getFacets();
    UIComponent component = map.get(facetType);
    if (component != null) {
        String headerValue = null;
        if (component instanceof HtmlCommandButton) {
            headerValue = exportValue(context, component);
        } else if (component instanceof HtmlCommandLink) {
            headerValue = exportValue(context, component);
        } else if (component instanceof UIPanel || component instanceof OutputPanel) {
            String header = "";
            for (UIComponent child : component.getChildren()) {
                headerValue = exportValue(context, child);
                header = header + headerValue;
            }

            PdfPCell cell = new PdfPCell(new Paragraph((header), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            //addColumnAlignments(component,cell);
            cell.setColspan(columnCount);
            pdfTable.addCell(cell);
            pdfTable.completeRow();

            return;
        } else {
            headerValue = exportFacetValue(context, component);
        }

        PdfPCell cell = new PdfPCell(new Paragraph((headerValue), this.facetFont));
        if (facetBackground != null) {
            cell.setBackgroundColor(facetBackground);
        }

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        //addColumnAlignments(component,cell);
        cell.setColspan(columnCount);
        pdfTable.addCell(cell);
        pdfTable.completeRow();
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableFacet(FacesContext context, PdfPTable pdfTable, SubTable table, int columnCount,
        String facetType) {/*  w ww  .  ja va  2 s  .  c  om*/
    Map<String, UIComponent> map = table.getFacets();
    UIComponent component = map.get(facetType);
    if (component != null) {
        String headerValue = null;
        if (component instanceof HtmlCommandButton) {
            headerValue = exportValue(context, component);
        } else if (component instanceof HtmlCommandLink) {
            headerValue = exportValue(context, component);
        } else if (component instanceof UIPanel || component instanceof OutputPanel) {
            String header = "";
            for (UIComponent child : component.getChildren()) {
                headerValue = exportValue(context, child);
                header = header + headerValue;
            }

            PdfPCell cell = new PdfPCell(new Paragraph((header), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            //addColumnAlignments(component,cell);
            cell.setColspan(columnCount);
            pdfTable.addCell(cell);
            pdfTable.completeRow();

            return;
        } else {
            headerValue = exportFacetValue(context, component);
        }

        PdfPCell cell = new PdfPCell(new Paragraph((headerValue), this.facetFont));
        if (facetBackground != null) {
            cell.setBackgroundColor(facetBackground);
        }

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        // addColumnAlignments(component,cell);
        cell.setColspan(columnCount);
        pdfTable.addCell(cell);
        pdfTable.completeRow();
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableColumnGroup(PdfPTable pdfTable, DataTable table, String facetType) {
    ColumnGroup cg = table.getColumnGroup(facetType);
    List<UIComponent> headerComponentList = null;
    if (cg != null) {
        headerComponentList = cg.getChildren();
    }/*from   w  w w.j  av a 2s  .c  om*/

    if (headerComponentList != null) {
        for (UIComponent component : headerComponentList) {
            if (component instanceof Row) {
                Row row = (Row) component;
                for (UIComponent rowComponent : row.getChildren()) {
                    UIColumn column = (UIColumn) rowComponent;
                    String value = null;
                    if (facetType.equalsIgnoreCase("header")) {
                        value = column.getHeaderText();
                    } else {
                        value = column.getFooterText();
                    }

                    int rowSpan = column.getRowspan();
                    int colSpan = column.getColspan();
                    PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont));
                    if (facetBackground != null) {
                        cell.setBackgroundColor(facetBackground);
                    }

                    if (rowSpan > 1) {
                        cell.setVerticalAlignment(Element.ALIGN_CENTER);
                        cell.setRowspan(rowSpan);
                    }

                    if (colSpan > 1) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setColspan(colSpan);
                    }

                    // addColumnAlignments(component,cell);
                    if (facetType.equalsIgnoreCase("header")) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    }

                    pdfTable.addCell(cell);
                }
            }
        }
    }

    pdfTable.completeRow();
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableColumnGroup(PdfPTable pdfTable, SubTable table, String facetType) {
    ColumnGroup cg = table.getColumnGroup(facetType);
    List<UIComponent> headerComponentList = null;
    if (cg != null) {
        headerComponentList = cg.getChildren();
    }//from   ww w. j a va  2s . c om

    if (headerComponentList != null) {
        for (UIComponent component : headerComponentList) {
            if (component instanceof Row) {
                Row row = (Row) component;
                for (UIComponent rowComponent : row.getChildren()) {
                    UIColumn column = (UIColumn) rowComponent;
                    String value = null;
                    if (facetType.equalsIgnoreCase("header")) {
                        value = column.getHeaderText();
                    } else {
                        value = column.getFooterText();
                    }

                    int rowSpan = column.getRowspan();
                    int colSpan = column.getColspan();
                    PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont));
                    if (facetBackground != null) {
                        cell.setBackgroundColor(facetBackground);
                    }

                    if (rowSpan > 1) {
                        cell.setVerticalAlignment(Element.ALIGN_CENTER);
                        cell.setRowspan(rowSpan);
                    }

                    if (colSpan > 1) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setColspan(colSpan);
                    }

                    // addColumnAlignments(component,cell);
                    if (facetType.equalsIgnoreCase("header")) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    }

                    pdfTable.addCell(cell);
                }
            }
        }
    }

    pdfTable.completeRow();
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void exportRow(DataTable table, PdfPTable pdfTable, int rowIndex) {
    table.setRowIndex(rowIndex);//from  www  .  java 2  s  . co  m

    if (!table.isRowAvailable()) {
        return;
    }

    exportCells(table, pdfTable, rowIndex);
    SummaryRow sr = table.getSummaryRow();

    if (sr != null && sr.isInView()) {
        for (UIComponent summaryComponent : sr.getChildren()) {
            UIColumn column = (UIColumn) summaryComponent;
            StringBuilder builder = new StringBuilder();

            for (UIComponent component : column.getChildren()) {
                if (component.isRendered()) {
                    String value = exportValue(FacesContext.getCurrentInstance(), component);

                    if (value != null) {
                        builder.append(value);
                    }
                }
            }

            int rowSpan = column.getRowspan();
            int colSpan = column.getColspan();
            PdfPCell cell = new PdfPCell(new Paragraph(builder.toString(), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            if (rowSpan > 1) {
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                cell.setRowspan(rowSpan);
            }

            if (colSpan > 1) {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(colSpan);
            }

            pdfTable.addCell(cell);
        }
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void exportCells(DataTable table, PdfPTable pdfTable, int rowIndex) {
    for (UIColumn col : table.getColumns()) {
        UIComponent component = (UIComponent) col;

        ////Adding RowIndex for custom Export
        if (component.getId().equalsIgnoreCase("subject")) {
            int value = rowIndex;
            PdfPCell cell = new PdfPCell(new Paragraph(value + ""));
            //addColumnAlignments(component, cell);

            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }//w  ww  .jav a  2 s. com

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            System.out.println("value is" + value);
            pdfTable.addCell(cell);
        }

        if (!col.isRendered()) {
            continue;
        }

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyModel();
        }

        if (col.isExportable()) {
            if (col.getSelectionMode() != null) {
                pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont));

                continue;
            }

            addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data");
        }
    }

    pdfTable.completeRow();
    FacesContext context = null;
    if (table.getRowIndex() == 0) {
        for (UIComponent component : table.getChildren()) {
            if (component instanceof RowExpansion) {
                RowExpansion rowExpansion = (RowExpansion) component;
                if (rowExpansion.getChildren() != null) {
                    if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                        DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                        childTable.setRowIndex(-1);
                    }

                    if (rowExpansion.getChildren().get(0) instanceof DataList) {
                        DataList childList = (DataList) rowExpansion.getChildren().get(0);
                        childList.setRowIndex(-1);
                    }
                }
            }
        }
    }

    table.setRowIndex(table.getRowIndex() + 1);
    for (UIComponent component : table.getChildren()) {
        if (component instanceof RowExpansion) {
            RowExpansion rowExpansion = (RowExpansion) component;
            if (rowExpansion.getChildren() != null) {
                if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                    DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                    pdfTable.addCell(cell);
                }

                if (rowExpansion.getChildren().get(0) instanceof DataList) {
                    DataList list = (DataList) rowExpansion.getChildren().get(0);
                    PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-");
                    pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                    PdfPCell cell = new PdfPCell();
                    cell.addElement(pdfTableChild);
                    cell.setColspan(pdfTable.getNumberOfColumns());
                }
            }
        }

        pdfTable.completeRow();
    }
}