Different TextStates on Same Line in Table Cell

Aspose.PDF .NET 10.4


Why does this not work? I should have 2 different colors next to each other.

Table table = new Table();
Row row = table.Rows.Add();
Cell cell = row.Cells.Add();

TextSegment name = new TextSegment(“START”);
name.TextState.FontSize = 13.5f;
name.TextState.ForegroundColor = Color.White;

TextSegment rm = new TextSegment(“END”);
rm.TextState.FontSize = 10f;
rm.TextState.ForegroundColor = Color.Green;

TextFragment title = new TextFragment();
title.Segments.Add(name);
title.Segments.Add(rm);

cell.Paragraphs.Add(title);

Hi Dirk,


Thanks for your inquiry. I have tested the scenario at my end and it is working without any issue. We will appreciate it if you please share your complete code, so we will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Here’s a full example. I should have 2 lines in the cell. One as a title. And the second with 2 different colors and sizes in the same line.

string exportPath = Path.Combine(“c:\temp”, “TableStylesTest.pdf”);
Document doc = new Document();
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(10, 10, 10, 10);

Table table = new Table();
table.ColumnWidths = page.PageInfo.Width.ToString();
Row row = table.Rows.Add();
Cell cell = row.Cells.Add();

cell.Alignment = HorizontalAlignment.Left;
cell.VerticalAlignment = VerticalAlignment.Bottom;
cell.Margin = new MarginInfo(11, 11, 11, 0);
cell.IsWordWrapped = true;

var title = new TextFragment(“Title on it’s own line”);

title.TextState.FontStyle = FontStyles.Bold;
title.TextState.FontSize = 14;
title.TextState.ForegroundColor = Color.Black;
title.Margin = new MarginInfo(0, 4, 0, 0);
title.IsInLineParagraph = false;

cell.Paragraphs.Add(title);

TextSegment name = new TextSegment("hopefully a new line here and blue ");
name.TextState.FontSize = 13f;
name.TextState.ForegroundColor = Color.Blue;

TextSegment rm = new TextSegment(“should continue line in green, smaller font”);
rm.TextState.FontSize = 10f;
rm.TextState.ForegroundColor = Color.Green;

TextFragment list = new TextFragment();
list.IsInLineParagraph = false;
title.Segments.Add(name);
title.Segments.Add(rm);

cell.Paragraphs.Add(list);

page.Paragraphs.Add(table);

doc.Save(exportPath);
return exportPath;

Hi Dirk,


Thanks for sharing the details.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWNET-38776. We
will investigate this issue in details and will keep you updated on the status
of a correction. <o:p></o:p>

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNET-38776) have been fixed in Aspose.PDF for .NET 18.12.