table.Rows[rowIndex].Cells[colIndex].DefaultCellTextState.ForegroundColor is Always #000000 After SetColumnTextState(colIndex, textState)

After calling SetColumnTextState() with a new TextState that has a ForegroundColor set, I am noticing that table.Rows[RowIndex].Cells[ColIndex].DefaultCellTextState.ForegroundColor is always #000000. It seems that table.Rows[r].Cells[c].DefaultCellTextState.ForegroundColor is never updated unless the ForegroundColor property is explicitly set at the cell level. The following code shows this:

        var doc = new Document();
        var page = doc.Pages.Add();
        //Instantiate a table object
        var asposeTable = new Table {Broken = TableBroken.Vertical};
        //Add the table in paragraphs collection of the desired section
        page.Paragraphs.Add(asposeTable);
        //Set with column widths of the table
        asposeTable.ColumnWidths = "100";

        //Add header Row
        var headerRow = asposeTable.Rows.Add();
        headerRow.Cells.Add("header 1").BackgroundColor = Color.LightCoral;

        for (var rowCounter = 0; rowCounter <= 5; rowCounter++)
        {
            //Create rows in the table and then cells in the rows
            var row1 = asposeTable.Rows.Add();
            row1.Cells.Add("col " + rowCounter.ToString() + ", 1");
        }

        var newTextState = new TextState();
        newTextState.ForegroundColor = Color.Aqua;

        asposeTable.SetColumnTextState(0, newTextState);

        Console.WriteLine("foreground color: " + asposeTable.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor);

        doc.Save("BrokenWideTableColSpans.pdf");

In this code, #000000 is always logged to the console for me, even though the actual PDF that is generated has Aqua text.

What is the recommended way to retrieve the true ForegroundColor of the DefaultCellTextState of a cell after SetColumnTextState() has been called? If there is no way to do so, could you please expose the true value of this property somehow?

@dfactset

Thank you for contacting support.

We would like to share with you that SetColumnTextState method sets the TextState but it does not set DefaultTextState unless set explicitly. DefaultCellTextState property is exposed by Table Class, Row Class as well as Cell Class. So, this property needs to be set at Table, Row or Cell level as in the code snippet below:

var doc = new Document();
var page = doc.Pages.Add();
//Instantiate a table object
var asposeTable = new Table { Broken = TableBroken.Vertical };
//Add the table in paragraphs collection of the desired section
page.Paragraphs.Add(asposeTable);
//Set with column widths of the table
asposeTable.ColumnWidths = "100";

//Add header Row
var headerRow = asposeTable.Rows.Add();
headerRow.Cells.Add("header 1").BackgroundColor = Color.LightCoral;

for (var rowCounter = 0; rowCounter <= 5; rowCounter++)
{
    //Create rows in the table and then cells in the rows
    var row1 = asposeTable.Rows.Add();
    row1.Cells.Add("col " + rowCounter.ToString() + ", 1");
}

var newTextState = new TextState();
newTextState.ForegroundColor = Color.Aqua;

asposeTable.DefaultCellTextState = newTextState;

Console.WriteLine("foreground color: " + asposeTable.DefaultCellTextState.ForegroundColor);

doc.Save( dataDir + "BrokenWideTableColSpans.pdf");

Alternatively, you can get the foreground color of any cell by using below code snippet in your environment.

var doc = new Document(dataDir + "BrokenWideTableColSpans.pdf");
TableAbsorber ta = new TableAbsorber();
ta.Visit(doc.Pages[1]);
Console.WriteLine(ta.TableList[0].RowList[0].CellList[0].TextFragments[1].TextState.ForegroundColor);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.