Free Support Forum - aspose.com

Bold text in cell

Any code examples of how I can get bold text in a table cell.

Dear Stukka,

Thank you for considering Aspose.

If you are using Truetype fonts, you can set the TextInfo.IsTrueTypeFontBold to true. Otherwise you should specify a bold font such as “Times-Bold”.

If you want to set text in all cells to be bold, use the Table.DefaultCellTextInfo. If you want to set text in one cell to be bold, you can set like the following:

[C#]
Text text1 = cell1.paragraphs[0] as Text;
text1.Segments[0].TextInfo.FontName = “Times-Bold”;

[VisualBasic]
Dim text1 As Text = cell1.paragraphs[0]
text1.Segments(0).TextInfo.FontName = “Times-Bold”

Hi,

How will I make part of the text bold in a cell.

e.g:

Degree
Master


above text, I want to disply degree in bold letter.

I am using following code, but this will disply all cell text in bold letter.

Dim cell1 As Cell = row1.Cells.Add("Degree #$NL " & txtdegree)

Dim text1 As Text = cell1.Paragraphs(0)

text1.Segments(0).TextInfo.FontName = “Times-Bold”

-Sundaram

Dear Sundaram,

Thank you for considering Aspose.

You need to use multiple segments instead of single segment. For example:

Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text

Dim segment1 As Segment = New Segment(text1)
text1.Segments.Add(segment1)
segment1.Content = "Degree"
segment1.TextInfo.FontName = "Times-Bold"

Dim segment2 As Segment = New Segment(text1)
text1.Segments.Add(segment1)
segment1.Content = "#$NL " & txtdegree

cell1.Paragraphs.Add(text1)

Thanks for your reply.

As per your post, I have change following line.

row1.Cells.Add("Company #$NL " & txtcompany)

======================

Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text

Dim segment1 As Segment = New Segment(text1)

text1.Segments.Add(segment1)

segment1.Content = “Company”

segment1.TextInfo.FontName = “Times-Bold”

segment1.TextInfo.Color = New Aspose.Pdf.Color(“Blue”)

Dim segment2 As Segment = New Segment(text1)

text1.Segments.Add(segment1)

segment1.Content = " #$NL " & txtcompany

row1.Cells.Add().Paragraphs.Add(text1)
============

But PDF out is not displaying segment1 text properly.

Here is the sample text with above code.

http://sfg.homeunix.com/public/PDFReport.pdf

Am I doing something wrong here.

Thanks

Sorry for the error. The last two “segment1” should be “segment2”.

Thanks,

the following code is working.

Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text

Dim segment1 As Segment = New Segment(text1)

text1.Segments.Add(segment1)

segment1.Content = "Company"

segment1.TextInfo.FontName = "Times-Bold"

segment1.TextInfo.Color = New Aspose.Pdf.Color("Blue")

Dim segment2 As Segment = New Segment(text1)

text1.Segments.Add(segment2)

segment2.Content = " #$NL " & txtcompany

row1.Cells.Add().Paragraphs.Add(text1)