We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF > Text Segment > FontStyle not working

I have been attempting to build 2 text segments into a text fragment, and I’d like to bold the 1st segment only. (The resultant segment should be thus; Label: Data ) When applying bold to a segment as such, it is not working on output. And if I apply bolding to the fragment, it will bold both segments in the fragment, which is not the desired output.

                        var labelAndValueFragment = new TextFragment();
                        TextSegment firstSegment = new TextSegment();
                        labelAndValueFragment.Segments.Add(firstSegment);
                        firstSegment.Text = stackedColumnProperty.ColumnText.Trim() + ": ";
                        firstSegment.TextState.ForegroundColor = Color.Parse("#000000");
                        firstSegment.TextState.FontStyle = FontStyles.Bold;
                        labelAndValueFragment.Margin.Bottom = 2;

                        TextSegment secondSegment = new TextSegment(propertyValue.Text);
                        labelAndValueFragment.Segments.Add(secondSegment);


                        cell.Paragraphs.Add(labelAndValueFragment);

@michael.dixon

I have tested it with the following code using Aspose.PDF for .NET 21.5 and the output looks fine. I suggest you to upgrade to latest version and share your feedback.

Document document = new Document();
var page = document.Pages.Add();
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "100";
Aspose.Pdf.Row row = table.Rows.Add();
row.FixedRowHeight = 15;
Aspose.Pdf.Cell cell1 = row.Cells.Add();            
var labelAndValueFragment = new TextFragment();
TextSegment firstSegment = new TextSegment();
labelAndValueFragment.Segments.Add(firstSegment);
firstSegment.Text = "Label:";// stackedColumnProperty.ColumnText.Trim() + ": ";
firstSegment.TextState.ForegroundColor = Aspose.Pdf.Color.Parse("#000000");
firstSegment.TextState.FontStyle = FontStyles.Bold;
labelAndValueFragment.Margin.Bottom = 2;
TextSegment secondSegment = new TextSegment("123");// propertyValue.Text);
labelAndValueFragment.Segments.Add(secondSegment);
cell1.Paragraphs.Add(labelAndValueFragment);
page.Paragraphs.Add(table);
document.Save(dataDir + "MultipleFragments1.pdf");