Append text in paragraph in C# using Aspose.PDF for .NET

Hi, I posted a question on stackoverflow regarding my issue here:

http://stackoverflow.com/questions/15298982/append-text-in-paragraph-using-aspose-pdf

but may be I will get better luck in this forums. Please reply if any interrogations.

Hi,

Thanks for using our products.

I have tested the scenario while using the following simple code with Aspose.Pdf for .NET 7.7.0 and as per my observations, Italic text is properly appearing and the whole string is in H1 formatting. Please note that when using IsHtmlTagSupported, it’s recommended to specify the text formatting (Bold, FontSize etc) using HTML Tags.

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Text title = new Text("<h1>What a nice <i>italic</i> freaking title</h1>");
var info = new TextInfo();
info.FontSize = 12;
//info.IsTrueTypeFontBold = true;
title.TextInfo = info;
title.IsHtmlTagSupported = true;
sec1.Paragraphs.Add(title);
pdf1.Save("c:/pdftest/PDF_From_HTML.pdf");

Furthermore, a Text paragraph can have one or more Segment object and you can specify different formatting for each segment. In order to fulfill your requirement, you may try using the following code snippet

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Text title = new Text("What a");
var info = new TextInfo();
info.FontSize = 12;
info.IsTrueTypeFontBold = true;
title.TextInfo = info;
Segment segment2 = new Segment(" italic ");
segment2.TextInfo.IsTrueTypeFontItalic = true;
title.Segments.Add(segment2);

Segment segment3 = new Segment("freaking title ");
segment3.TextInfo.IsTrueTypeFontBold= true;
title.Segments.Add(segment3);
sec1.Paragraphs.Add(title); //save the output document
pdf1.Save("c:/pdftest/PDF_with_Three_Segments.pdf");

For your reference, I have also attached the resultant PDF files generated with above code snippets. In the event of any further query, please feel free to contact. We are sorry for this inconvenience.