PdfCell Object

Overview

PdfCell represents an individual cell of a table. A PdfCell object is obtainable via PdfTable's At property and the PdfCells collection returnable from PdfRow's Cells property. For more information, see Chapter 7 - Tables of User Manual.

Member List

Properties


object BgColor (Read/Write)

Returns or specifies the cell's background. The value can be a hexadecimal number or a string with a color name.

Usage:

Table[1, 2].BgColor = 0xFF0000;
Table[1, 2].BgColor = "red";

For more information, see Section 10.4 - Actions.


float Border (Read/Write)
Returns or specifies the cell's border width. Setting this property to 0 hides the cell border.ore information, see Section 10.4 - Actions.

object BorderColor (Read/Write)

Returns or specifies the cell's border color. The value can be a hexadecimal number or a string with a color name.

Usage:

Table.Rows[1].Cells[3].BorderColor = 0x0000FF;
Table.Rows[1].Cells[3].BorderColor = "blue";

PdfCanvas Canvas (Read-only)
Returns an instance of the PdfCanvas object associated with this cell. This property can be used to draw graphics, text and other tables inside this cell. For more information, see Section 7.1.4 - Drawing in a Cell.

float CellPadding (Read/Write)
Returns or specifies cell padding for this cell, which is the width of a margin to the left and above a text string drawn in this cell via the AddText method.

int ColSpan (Read/Write)
Returns or specifies the number of cells to its right it spans. Has the same effect as a <TD COLSPAN="..."> attribute in an HTML table. This property is 1 by default.

float Height (Read/Write)
Returns or specifies the cell height. Setting this property affects the heights of all the cells in the current row, and also the overall table height.

int Index (Read-only)
Returns the 1-based index of this cell within its row.

PdfRow Row (Read-only)
Returns an instance of the PdfRow object representing this cell's row.

int RowSpan (Read/Write)
Returns or specifies the number of rows this cell spans downwards. Has the same effect as a <TD ROWSPAN="..."> attribute in an HTML table. This property is 1 by default.

float Width (Read/Write)
Returns or specifies the cell width. Setting this property affects the widths of all cells above and below the current one, and also the overall table width.

float X (Read-only)
Returns the X coordinate of this cell's upper-left corner relative to the table's upper-left corner.

float Y (Read-only)
Returns the Y coordinate of this cell's upper-left corner relative to the table's upper-left corner. Since the Y-axis extends upwards, this value is always non-positive.

Methods


int AddText(string Text, object Param)
int AddText(string Text, object Param, PdfFont Font)

Adds a text string specified by Text to the cell using the font specified by Font (if present) or the table's default font specified upstream via the Table.Font property. More than one text string can be added to a cell via multiple calls to AddText.

This method's parameters are almost identical to that of Canvas.DrawText except that the X, Y, Width and Height paramaters are copied from this cell's respective properties. There are 4 extra parameters specific to AddText only and not used in Canvas.DrawText: IndentX, IndentY, VAlignment and Expand.

Param is a PdfParam object or parameter string specifying the following text drawing parameters.

  • IndentX, IndentY (optional) - the horizontal and vertical indents of the text relative to the cell's upper-left corner, 0 by default. As of version 1.6.0.7, IndentY is ignored if VAlignment is set to middle or bottom.
  • Expand (optional) - if set to True, the cell expands vertically to accommodate the entire string being added. Side effect: cell and overall table height may change. If set to False, the cell size is fixed and only a portion of the string that fits will be drawn. False by default.
  • Size (optional) - the font size, 10 by default.
  • Alignment (optional) - horizontal text alignment, left (0) by default, other valid values are right (1) and center (2).
  • VAlignment (optional) - vertical text alignment, top (0) by default, other valid values are bottom (1) and middle (2). If this parameter is present and set to middle or bottom, the IndentY parameter is ignored. This parameter requires version 1.6.0.7 or higher.
  • Rendering (optional) - font rendering, valid values described in Section 6.1.2 - Rendering Parameter.
  • Color (optional) - font color, black by default.
  • Angle (optional) - angle (in degrees) by which the text should be rotated counter-clockwise around the upper-left corner of the bounding box.
  • Spacing (optional) - the distance between individual lines of text, 1 by default.
  • Tab (optional) - the size of a tab indent, 10 "space" characters by default.
  • ReverseHebrewArabic (optional) - reverses the sequence of Hebrew and Arabic characters in a string if set to True.
  • Html (optional) - if set to True, the text string is to be treated as HTML. False by default. For more information on HTML support, see Section 6.4 - HTML Support. If this parameter is set to True, the Alignment, Tab and ReverseHebrewArabic parameters are ignored.
  • ColorSpace, c1, c2, ..., cN (optional) - introduced in Version 2.7 to enable colors in color spaces other than RGB or CMYK. For more information, see Section 15.4 - Using Color Spaces with PdfTable and Other Objects.

The method returns the number of printed characters. This number may be less than the length of the original text string if the entire string did not fit in the cell and Expand is set to False. If Expand is set to True, all characters are usually printed, except if the cell is too narrow even for a single character.

Usage:

objTable.Font = objFont;
objTable.[1, 2].AddText( "Hello World!", "expand=true" );

For more information on tables, see Chapter 7 - Tables. For more information on text and fonts, see Chapter 6 - Text and Fonts. For the full description of the DrawText method, see Section 6.1 - Overview of Canvas.DrawText method.


void ClearText()
Clears the cell of all text segments added by calls to AddText.

void SetBorderParams(object Param)

Sets visibility and color parameters for individual cell border sides.

Param is a PdfParam object or parameter string specifying color and visibility of the top, left, rigth, and bottom sides of a cell border rectangle individually. Parameters include:

  • Top, Bottom, Right, Left (optional) - if set to False, hide the top, bottom, right or left side of the cell border, respectively. True by default.
  • TopColor, BottomColor, RightColor, LeftColor (optional) - specify the line color for the top, bottom, right or left side, respectively. Cell.BorderColor by default.

void SetColor(object Param)

Specifies a border or background color for this cell in a color space other than RGB. Param is a PdfParam object or parameter string specifying various color parameters, including:

  • Type (required) - specifies which color is to be modified. The valid values are: 2 (cell border color) and 4 (cell background color).
  • ColorSpace (required) - specifies the color space index. This value should be obtained from the Index property of the PdfColorSpace object.
  • c1, c2, ..., cN (required) - specify the individual color components for the color. These values must be in the range [0, 1] and the number of color components must match the color space being used.
  • Top, Bottom, Left, Right (optional) - if set to True, specify which side(s) of the cell the specified border color should apply to. These parameters are only used if Type=2. If none of these are set to True, the color applies to the entire cell border.

This method was introduced in Version 2.7.

For more information, see Section 16.4 - Using Color Spaces with PdfTable and Other Objects.