Bold and non-bold text on the same line

I have an ASP.NET 2.0 app using VB to create a PDF document using the API. I can not find any documentation which shows me how to write a line that contains both bold and non-bold text. All the documentation I see so far only show you how to write bolded text and non-bolded text on separate lines. Please help.

Hi,

Thank you for considering Aspose.

You can use multiple segments to attain your goal. Please refer to the following code:

Dim pdf1 As New Pdf()
Dim sec As Section = pdf1.Sections.Add()
Dim text As New Text()
sec.Paragraphs.Add(text)
Dim segment2 As Segment = text.Segments.Add("This is Bold ")
segment2.TextInfo.FontSize = 20
segment2.TextInfo.FontName = “Arial”
segment2.TextInfo.IsTrueTypeFontBold = True
Dim segment1 As Segment = text.Segments.Add("This is not Bold ")
segment1.TextInfo.FontSize = 20
segment1.TextInfo.FontName = “Arial”
pdf1.Save(“E:/AsposeTest/Bold.pdf”)

If you need more help, please do let us know.
Thanks.
Adeel Ahmad
Support Developer
Aspose Changsha Team

How do I do this using the new DOM api (instead of generator)?

Hi Dirk,


Thanks for your inquiry. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

var doc = new Document();<o:p></o:p>

var page = doc.Pages.Add();

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

Aspose.Pdf.Row row = table.Rows.Add();

Aspose.Pdf.Cell cell = row.Cells.Add();

TextSegment name = new TextSegment("START");

name.TextState.FontSize = 13.5f;

name.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;

name.TextState.ForegroundColor = Aspose.Pdf.Color.Yellow;

TextSegment rm = new TextSegment("END");

rm.TextState.FontSize = 10f;

rm.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Italic;

rm.TextState.ForegroundColor = Aspose.Pdf.Color.Green;

TextFragment title = new TextFragment();

title.Segments.Add(name);

title.Segments.Add(rm);

cell.Paragraphs.Add(title);

page.Paragraphs.Add(table);

doc.Save(myDir+"Different_textstates.pdf");


Please feel free to contact us for any further assistance.


Best Regards,