Java Code Examples for com.lowagie.text.pdf.PdfPCell#setColspan()

The following examples show how to use com.lowagie.text.pdf.PdfPCell#setColspan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cell.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a PdfPCell based on this Cell object.
 * @return a PdfPCell
 * @throws BadElementException
 */
public PdfPCell createPdfPCell() throws BadElementException {
	if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
	if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
	PdfPCell cell = new PdfPCell();
	cell.setVerticalAlignment(verticalAlignment);
	cell.setHorizontalAlignment(horizontalAlignment);
	cell.setColspan(colspan);
	cell.setUseBorderPadding(useBorderPadding);
	cell.setUseDescender(useDescender);
	cell.setLeading(getLeading(), 0);
	cell.cloneNonPositionParameters(this);
	cell.setNoWrap(getMaxLines() == 1);
	for (Iterator i = getElements(); i.hasNext(); ) {
           Element e = (Element)i.next();
           if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) {
               Paragraph p = new Paragraph((Phrase)e);
               p.setAlignment(horizontalAlignment);
               e = p;
           }
		cell.addElement(e);
	}
	return cell;
}
 
Example 2
Source File: Cell.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a PdfPCell based on this Cell object.
 * @return a PdfPCell
 * @throws BadElementException
 */
public PdfPCell createPdfPCell() throws BadElementException {
	if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
	if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
	PdfPCell cell = new PdfPCell();
	cell.setVerticalAlignment(verticalAlignment);
	cell.setHorizontalAlignment(horizontalAlignment);
	cell.setColspan(colspan);
	cell.setUseBorderPadding(useBorderPadding);
	cell.setUseDescender(useDescender);
	cell.setLeading(leading(), 0);
	cell.cloneNonPositionParameters(this);
	for (Iterator i = getElements(); i.hasNext(); ) {
		cell.addElement((Element)i.next());
	}
	return cell;
}
 
Example 3
Source File: Cell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a PdfPCell based on this Cell object.
 * 
 * @return a PdfPCell
 * @throws BadElementException
 */
public PdfPCell createPdfPCell() throws BadElementException {
	if (rowspan > 1) {
		throw new BadElementException("PdfPCells can't have a rowspan > 1");
	}
	if (isTable()) {
		return new PdfPCell(((Table) arrayList.get(0)).createPdfPTable());
	}
	PdfPCell cell = new PdfPCell();
	cell.setVerticalAlignment(verticalAlignment);
	cell.setHorizontalAlignment(horizontalAlignment);
	cell.setColspan(colspan);
	cell.setUseBorderPadding(useBorderPadding);
	cell.setUseDescender(useDescender);
	cell.setLeading(getLeading(), 0);
	cell.cloneNonPositionParameters(this);
	cell.setNoWrap(getMaxLines() == 1);
	for (Iterator i = getElements(); i.hasNext();) {
		Element e = (Element) i.next();
		if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) {
			Paragraph p = new Paragraph((Phrase) e);
			p.setAlignment(horizontalAlignment);
			e = p;
		}
		cell.addElement(e);
	}
	return cell;
}
 
Example 4
Source File: IncCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Creates a new instance of IncCell */
public IncCell(String tag, ChainedProperties props) {
    cell = new PdfPCell((Phrase)null);
    String value = props.getProperty("colspan");
    if (value != null)
        cell.setColspan(Integer.parseInt(value));
    value = props.getProperty("align");
    if (tag.equals("th"))
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (value != null) {
        if ("center".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        else if ("right".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        else if ("left".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        else if ("justify".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    }
    value = props.getProperty("valign");
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    if (value != null) {
        if ("top".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_TOP);
        else if ("bottom".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    }
    value = props.getProperty("border");
    float border = 0;
    if (value != null)
        border = Float.parseFloat(value);
    cell.setBorderWidth(border);
    value = props.getProperty("cellpadding");
    if (value != null)
        cell.setPadding(Float.parseFloat(value));
    cell.setUseDescender(true);
    value = props.getProperty("bgcolor");
    cell.setBackgroundColor(Markup.decodeColor(value));
}
 
Example 5
Source File: IncCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Creates a new instance of IncCell */
public IncCell(String tag, ChainedProperties props) {
    cell = new PdfPCell((Phrase)null);
    String value = props.getProperty("colspan");
    if (value != null)
        cell.setColspan(Integer.parseInt(value));
    value = props.getProperty("align");
    if (tag.equals("th"))
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (value != null) {
        if ("center".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        else if ("right".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        else if ("left".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        else if ("justify".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    }
    value = props.getProperty("valign");
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    if (value != null) {
        if ("top".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_TOP);
        else if ("bottom".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    }
    value = props.getProperty("border");
    float border = 0;
    if (value != null)
        border = Float.parseFloat(value);
    cell.setBorderWidth(border);
    value = props.getProperty("cellpadding");
    if (value != null)
        cell.setPadding(Float.parseFloat(value));
    cell.setUseDescender(true);
    value = props.getProperty("bgcolor");
    cell.setBackgroundColor(Markup.decodeColor(value));
}
 
Example 6
Source File: DefaultCellTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Demonstrates the use of getDefaultCell().
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("DefaultCell.pdf"));

	// step 3: we open the document
	document.open();

	PdfPTable table = new PdfPTable(3);
	PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
	cell.setColspan(3);
	table.addCell(cell);
	table.addCell("1.1");
	table.addCell("2.1");
	table.addCell("3.1");
	table.getDefaultCell().setGrayFill(0.8f);
	table.addCell("1.2");
	table.addCell("2.2");
	table.addCell("3.2");
	table.getDefaultCell().setGrayFill(0f);
	table.getDefaultCell().setBorderColor(new Color(255, 0, 0));
	table.addCell("cell test1");
	table.getDefaultCell().setColspan(2);
	table.getDefaultCell().setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
	table.addCell("cell test2");
	document.add(table);

	// step 5: we close the document
	document.close();
}
 
Example 7
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a cell.
 *
 * @param text            The text to include in the cell.
 * @param colspan         The column span of the cell.
 * @param font            The font of the cell text.
 * @param horizontalAlign The vertical alignment of the text in the cell.
 * @return A PdfCell.
 */
public static PdfPCell getCell( String text, int colspan, Font font, int horizontalAlign )
{
    Paragraph paragraph = new Paragraph( text, font );

    PdfPCell cell = new PdfPCell( paragraph );

    cell.setColspan( colspan );
    cell.setBorder( 0 );
    cell.setMinimumHeight( 15 );
    cell.setHorizontalAlignment( horizontalAlign );

    return cell;
}
 
Example 8
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an empty cell.
 *
 * @param colspan The column span of the cell.
 * @param height  The height of the column.
 * @return A PdfCell.
 */
public static PdfPCell getEmptyCell( int colSpan, int height )
{
    PdfPCell cell = new PdfPCell();

    cell.setColspan( colSpan );
    cell.setBorder( 0 );
    cell.setMinimumHeight( height );

    return cell;
}
 
Example 9
Source File: SimpleCell.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a PdfPCell with these attributes.
 * 
 * @param rowAttributes
 * @return a PdfPCell based on these attributes.
 */
public PdfPCell createPdfPCell(SimpleCell rowAttributes) {
	PdfPCell cell = new PdfPCell();
	cell.setBorder(NO_BORDER);
	SimpleCell tmp = new SimpleCell(CELL);
	tmp.setSpacing_left(spacing_left);
	tmp.setSpacing_right(spacing_right);
	tmp.setSpacing_top(spacing_top);
	tmp.setSpacing_bottom(spacing_bottom);
	tmp.cloneNonPositionParameters(rowAttributes);
	tmp.softCloneNonPositionParameters(this);
	cell.setCellEvent(tmp);
	cell.setHorizontalAlignment(rowAttributes.horizontalAlignment);
	cell.setVerticalAlignment(rowAttributes.verticalAlignment);
	cell.setUseAscender(rowAttributes.useAscender);
	cell.setUseBorderPadding(rowAttributes.useBorderPadding);
	cell.setUseDescender(rowAttributes.useDescender);
	cell.setColspan(colspan);
	if (horizontalAlignment != Element.ALIGN_UNDEFINED) {
		cell.setHorizontalAlignment(horizontalAlignment);
	}
	if (verticalAlignment != Element.ALIGN_UNDEFINED) {
		cell.setVerticalAlignment(verticalAlignment);
	}
	if (useAscender) {
		cell.setUseAscender(useAscender);
	}
	if (useBorderPadding) {
		cell.setUseBorderPadding(useBorderPadding);
	}
	if (useDescender) {
		cell.setUseDescender(useDescender);
	}
	float p;
	float sp_left = spacing_left;
	if (Float.isNaN(sp_left)) {
		sp_left = 0f;
	}
	float sp_right = spacing_right;
	if (Float.isNaN(sp_right)) {
		sp_right = 0f;
	}
	float sp_top = spacing_top;
	if (Float.isNaN(sp_top)) {
		sp_top = 0f;
	}
	float sp_bottom = spacing_bottom;
	if (Float.isNaN(sp_bottom)) {
		sp_bottom = 0f;
	}
	p = padding_left;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingLeft(p + sp_left);
	p = padding_right;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingRight(p + sp_right);
	p = padding_top;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingTop(p + sp_top);
	p = padding_bottom;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingBottom(p + sp_bottom);
	Element element;
	for (Iterator i = content.iterator(); i.hasNext();) {
		element = (Element) i.next();
		cell.addElement(element);
	}
	return cell;
}
 
Example 10
Source File: SimpleCell.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a PdfPCell with these attributes.
 * @param rowAttributes
 * @return a PdfPCell based on these attributes.
 */
public PdfPCell createPdfPCell(SimpleCell rowAttributes) {
	PdfPCell cell = new PdfPCell();
	cell.setBorder(NO_BORDER);
	SimpleCell tmp = new SimpleCell(CELL);
	tmp.setSpacing_left(spacing_left);
	tmp.setSpacing_right(spacing_right);
	tmp.setSpacing_top(spacing_top);
	tmp.setSpacing_bottom(spacing_bottom);
	tmp.cloneNonPositionParameters(rowAttributes);
	tmp.softCloneNonPositionParameters(this);
	cell.setCellEvent(tmp);
	cell.setHorizontalAlignment(rowAttributes.horizontalAlignment);
	cell.setVerticalAlignment(rowAttributes.verticalAlignment);
	cell.setUseAscender(rowAttributes.useAscender);
	cell.setUseBorderPadding(rowAttributes.useBorderPadding);
	cell.setUseDescender(rowAttributes.useDescender);
	cell.setColspan(colspan);
	if (horizontalAlignment != Element.ALIGN_UNDEFINED)
		cell.setHorizontalAlignment(horizontalAlignment);
	if (verticalAlignment != Element.ALIGN_UNDEFINED)
		cell.setVerticalAlignment(verticalAlignment);
	if (useAscender)
		cell.setUseAscender(useAscender);
	if (useBorderPadding)
		cell.setUseBorderPadding(useBorderPadding);
	if (useDescender)
		cell.setUseDescender(useDescender);
	float p;
	float sp_left = spacing_left;
	if (Float.isNaN(sp_left)) sp_left = 0f;
	float sp_right = spacing_right;
	if (Float.isNaN(sp_right)) sp_right = 0f;
	float sp_top = spacing_top;
	if (Float.isNaN(sp_top)) sp_top = 0f;
	float sp_bottom = spacing_bottom;
	if (Float.isNaN(sp_bottom)) sp_bottom = 0f;
	p = padding_left;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingLeft(p + sp_left);
	p = padding_right;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingRight(p + sp_right);
	p = padding_top;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingTop(p + sp_top);
	p = padding_bottom;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingBottom(p + sp_bottom);
	Element element;
	for (Iterator i = content.iterator(); i.hasNext(); ) {
		element = (Element)i.next();
		cell.addElement(element);
	}
	return cell;
}