Hi,
For our current use-case we allow attributes to be set in an Aspose.PDF table using TextStates. Further, we might want to later override the TextStates at the column level by TextFragment at the cell level. However, it seems Aspose doesn’t support this override.
Our use-case is such that we would want to have multiple styles to a single piece of text in a cell. Currently, we use TextFragments to achieve this. The text is broken into parts and each of them is attributed with some styles using TextSegments. These segments are then bundled to make a TextFragment which we add to our cell.
It looks like once we set the table styles using TextStates we can’t really override them later using Fragments. However, TextStates at cell level do override TextStates at column level. We would like to allow multiple styles to a text which is only possible through Fragments.
ActualOutput.pdf (35.3 KB)
ExpectedOutput.pdf (35.4 KB)
Do let us know how to generate the expected output using fragments.
Following is a reproducer for the same.
static void columnStates()
{
Document doc = new Document();
Page page = doc.Pages.Add();
var table = new Table
{
ColumnAdjustment = ColumnAdjustment.Customized,
ColumnWidths = "50 50",
};
page.Paragraphs.Add(table);
var row1 = table.Rows.Add();
var row2 = table.Rows.Add();
var r1c1 = row1.Cells.Add("R1C1");
var r1c2 = row1.Cells.Add("R1C2");
var r2c1 = row2.Cells.Add("R2C1");
var r2c2 = row2.Cells.Add("R2C2");
var columnTextState = new TextState(System.Drawing.Color.Green, 10);
table.SetColumnTextState(0, columnTextState);
table.SetColumnTextState(1, columnTextState);
var cellTextFragment = new TextFragment("Fragment Override");
cellTextFragment.TextState.FontSize = 20;
cellTextFragment.TextState.ForegroundColor = Color.AliceBlue;
r2c1.Paragraphs.Clear();
r2c1.Paragraphs.Add(cellTextFragment);
var cellTextState = new TextState(System.Drawing.Color.DarkRed);
r2c2.DefaultCellTextState = cellTextState;
doc.Save("fragment.pdf");
}