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:domain.reports.role.PDFReportRole.java

License:LGPL

/**
 * Return a report section formatted as a table
 * @param data/*w  w  w. j  av a 2s.c  om*/
 * @return
 */
PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable {

    //cols
    PdfPTable datatable = new PdfPTable(4);

    //header
    datatable.getDefaultCell().setPadding(1);
    int headerwidths[] = { 20, 20, 20, 20 }; // percentage
    datatable.setWidths(headerwidths);
    datatable.setWidthPercentage(100); // percentage
    datatable.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell c = null;
    String v = "";

    //encabezados de columnas
    c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setColspan(4);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Apellido", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Nombre", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    c = new PdfPCell(new Phrase("Email", tblHeaderFont));
    c.setGrayFill(0.95f);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    datatable.addCell(c);

    while (detail.next()) {
        v = detail.getString("userlogin");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("lname");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("fname");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);

        v = detail.getString("email");
        c = new PdfPCell(new Phrase(v, tblBodyFont));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(c);
    }

    datatable.setSpacingBefore(20);
    return datatable;

}

From source file:ec.edu.chyc.manejopersonal.managebean.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();
    }// w w  w  .  j a  v a2  s.  c o  m
    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 (column.isRendered() && column.isExportable()) {
                        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:ec.edu.chyc.manejopersonal.managebean.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();
    }/* w ww .  j a v  a2 s .c  o  m*/
    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:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Creates a header cell.//from   w  w w  .  j a  va 2  s .c o  m
 * 
 * @param text
 *            the header text
 * @param colspan
 *            the span of the header
 * @return the generated cell.
 */
private static PdfPCell createHeaderCell(String text, int colspan) {
    PdfPCell header = new PdfPCell(new Phrase(text, FontFactory.getFont(FontFactory.HELVETICA_BOLD)));
    header.setBorder(Rectangle.BOTTOM);
    header.setColspan(colspan);
    return header;
}

From source file:gov.medicaid.services.util.PDFHelper.java

License:Apache License

/**
 * Creates a header cell.// w  w  w  .  j a v  a  2 s  . c  o  m
 *
 * @param text the header text
 * @param colspan the span of the header
 * @return the generated cell.
 */
public static PdfPCell createHeaderCell(String text, int colspan) {
    PdfPCell header = new PdfPCell(new Phrase(text, FontFactory.getFont(FontFactory.HELVETICA_BOLD)));
    header.setBorder(Rectangle.BOTTOM);
    header.setColspan(colspan);
    return header;
}

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);/*  ww w.j  a va  2s .c  om*/

    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:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java

License:Mozilla Public License

/**
 * Builds the table for the crosstab//w  w w. j  a  v  a2 s . c  om
 * @param json the JSON representation of the crosstab
 * @param pdfDocument the pdf document that should contains the crosstab
 * @param numberFormat the formatter for the numbers
 * @throws JSONException
 * @throws BadElementException
 * @throws DocumentException
 */
public void export(JSONObject json, Document pdfDocument, DecimalFormat numberFormat)
        throws SerializationException, JSONException, BadElementException, DocumentException {
    logger.debug("IN: exporting the crosstab");
    //prepare the crosstab for the export
    CrosstabExporterUtility.calculateDescendants(json);
    JSONObject columnsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_COLUMNS_HEADERS);
    JSONArray columnsRootChilds = columnsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS);
    JSONObject rowsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_ROWS_HEADERS);
    JSONArray rowsRootChilds = rowsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS);
    JSONArray rowHeadersDescription = json.getJSONArray(CrossTab.CROSSTAB_JSON_ROWS_HEADER_TITLE);
    JSONArray data = (JSONArray) json.get(CrossTab.CROSSTAB_JSON_DATA);
    measureMetadata = new MeasureFormatter(json, numberFormat, "##,##0.00");
    this.numberFormat = numberFormat;

    //build the matrix for the content
    dataMatrix = new Vector<List<PdfPCell>>();
    buildDataMatrix(data);

    //number of headers lavels
    int rowsDepth = CrosstabExporterUtility.getDepth(rowsRoot);
    int columnsDepth = CrosstabExporterUtility.getDepth(columnsRoot);

    //build the table
    PdfPTable table = new PdfPTable(rowsDepth + dataMatrix.get(0).size());

    //build the empty cell on the top left 
    PdfPCell topLeftCell = new PdfPCell(new Phrase(""));
    topLeftCell.setRowspan(columnsDepth - 1);//-1 because of the title of the rows header
    topLeftCell.setColspan(rowsDepth);
    topLeftCell.setBorderColor(Color.WHITE);
    table.addCell(topLeftCell);

    List<PdfPCell> cells = new ArrayList<PdfPCell>();

    //builds the headers
    int dataColumnNumber = ((JSONArray) data.get(0)).length();
    cells.addAll(buildColumnsHeader(columnsRootChilds, rowHeadersDescription, dataColumnNumber));
    cells.addAll(buildRowsHeaders(rowsRootChilds));

    logger.debug("Addign the content");
    //adds the headers
    for (int i = 0; i < cells.size(); i++) {
        table.addCell(cells.get(i));
    }

    table.setWidthPercentage(100);
    pdfDocument.add(table);
    logger.debug("IN: exported the crosstab");
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java

License:Mozilla Public License

/**
 * Builds cells for the column headers/*from   w  w w.j  a v  a  2  s . com*/
 * @param siblings the top level 
 * @return
 * @throws JSONException
 * @throws BadElementException
 */
private List<PdfPCell> buildColumnsHeader(JSONArray siblings, JSONArray rowHeadersDescription,
        int dataColumnNumber) throws JSONException, BadElementException {

    List<PdfPCell> cells = new ArrayList<PdfPCell>();

    List<JSONObject> columnNodes = getAllNodes(siblings);

    for (int i = 0; i < columnNodes.size(); i++) {
        //adds the row headers
        if (rowHeadersDescription != null && i == columnNodes.size() - dataColumnNumber) {
            for (int y = 0; y < rowHeadersDescription.length(); y++) {
                String text = rowHeadersDescription.getString(y);
                PdfPCell cell = new PdfPCell(new Phrase(text, cellFont));
                cell.setBorderColor(cellsBorderColor);
                cell.setBackgroundColor(headersBackgroundColor);
                cells.add(cell);
            }

        }
        JSONObject aNode = (JSONObject) columnNodes.get(i);
        String text = (String) aNode.get(Node.CROSSTAB_NODE_JSON_DESCRIPTION);
        int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER);

        PdfPCell cell = new PdfPCell(new Phrase(text, cellFont));
        cell.setBorderColor(cellsBorderColor);
        cell.setBackgroundColor(headersBackgroundColor);

        if (descendants > 1) {
            cell.setColspan(descendants);
        }
        cells.add(cell);
    }

    return cells;
}

From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java

License:Open Source License

private static void createInfospcoopTable(Section subCatPart, Infospcoop infospcoop)
        throws BadElementException {

    PdfPTable table = new PdfPTable(2);

    PdfPCell c1 = new PdfPCell(new Phrase("Infospcoop"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setColspan(2);
    table.addCell(c1);/*from  w  w w.  ja v  a2  s .co m*/
    table.setHeaderRows(1);

    //riga 1
    table.addCell(new Phrase("IdEgov"));
    table.addCell(new Phrase(infospcoop.getIdEgov()));
    // riga 2
    table.addCell(new Phrase("Soggetto Erogatore"));
    table.addCell(new Phrase(infospcoop.getTipoSoggettoErogatore() + "/" + infospcoop.getSoggettoErogatore()));
    // riga 3
    table.addCell(new Phrase("Soggetto Fruitore"));
    table.addCell(new Phrase(infospcoop.getTipoSoggettoFruitore() + "/" + infospcoop.getSoggettoFruitore()));
    // riga 4
    table.addCell(new Phrase("Servizio"));
    table.addCell(new Phrase(infospcoop.getTipoServizio() + "/" + infospcoop.getServizio()));
    // riga 5
    table.addCell(new Phrase("Azione"));
    table.addCell(new Phrase(infospcoop.getAzione()));

    subCatPart.add(table);

}

From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java

License:Open Source License

private static void createEventoTable(Section subCatPart, Evento evento) throws BadElementException {

    PdfPTable table = new PdfPTable(2);

    PdfPCell c1 = new PdfPCell(new Phrase("Evento Id[" + evento.getId() + "]"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setColspan(2);
    table.addCell(c1);//from   w w w.  ja  va  2  s .c  o  m
    table.setHeaderRows(1);

    //riga 1
    if (evento.getData() != null) {
        table.addCell(new Phrase("Data registrazione"));
        table.addCell(new Phrase("" + evento.getData()));
    }
    //riga 1
    if (evento.getDominio() != null) {
        table.addCell(new Phrase("Id Dominio"));
        table.addCell(new Phrase(evento.getDominio()));
    }
    //riga 1
    if (evento.getIuv() != null) {
        table.addCell(new Phrase("IUV"));
        table.addCell(new Phrase(evento.getIuv()));
    }
    //riga 1
    if (evento.getCcp() != null) {
        table.addCell(new Phrase("CCP"));
        table.addCell(new Phrase(evento.getCcp()));
    }
    //riga 1
    if (evento.getPsp() != null) {
        table.addCell(new Phrase("Id PSP"));
        table.addCell(new Phrase(evento.getPsp()));
    }
    //riga 1
    if (evento.getTipoVersamento() != null) {
        table.addCell(new Phrase("Tipo Versamento"));
        table.addCell(new Phrase(evento.getTipoVersamento()));
    }
    //riga 1
    if (evento.getComponente() != null) {
        table.addCell(new Phrase("Componente"));
        table.addCell(new Phrase(evento.getComponente().toString()));
    }
    //riga 1
    if (evento.getCategoria() != null) {
        table.addCell(new Phrase("Categoria Evento"));
        table.addCell(new Phrase(evento.getCategoria().toString()));
    }
    //riga 1
    if (evento.getTipo() != null) {
        table.addCell(new Phrase("Tipo Evento"));
        table.addCell(new Phrase(evento.getTipo()));
    }
    //riga 1
    if (evento.getSottoTipo() != null) {
        table.addCell(new Phrase("Sottotipo Evento"));
        table.addCell(new Phrase(evento.getSottoTipo().toString()));
    }
    //riga 1
    if (evento.getFruitore() != null) {
        table.addCell(new Phrase("Id Fruitore"));
        table.addCell(new Phrase(evento.getFruitore()));
    }
    //riga 1
    if (evento.getErogatore() != null) {
        table.addCell(new Phrase("Id Erogatore"));
        table.addCell(new Phrase(evento.getErogatore()));
    }
    //riga 1
    if (evento.getStazioneIntermediarioPA() != null) {
        table.addCell(new Phrase("Id Stazione Intermediario PA"));
        table.addCell(new Phrase(evento.getStazioneIntermediarioPA()));
    }
    //riga 1
    if (evento.getCanalePagamento() != null) {
        table.addCell(new Phrase("Canale Pagamento"));
        table.addCell(new Phrase(evento.getCanalePagamento()));
    }
    //riga 1
    if (evento.getParametri() != null) {
        table.addCell(new Phrase("Parametri Specifici Interfaccia"));
        table.addCell(new Phrase(evento.getParametri()));
    }

    if (evento.getEsito() != null) {
        table.addCell(new Phrase("Esito"));
        table.addCell(new Phrase(evento.getEsito()));
    }

    subCatPart.add(table);

}