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

Free Support Forum - aspose.com

Text Formatting not working with IsHtmlTagSupported

Hello,

I am having problems getting Aspose.Pdf.Generator.Pdf (Version Aspose pdf 8.5) to recognise Text formatting with IsHtmlTagSupported .

I want to show HTML formatted data in a table cell.IsHtmlTagSupported is working , but other text properties stopped working once HTML is applied. Like I want to set textsize to Arial : 8 , but it is always showing larger font.

Tried these code:

Aspose.Pdf.Generator.Text Text1 = new Aspose.Pdf.Generator.Text("Description: " );

Aspose.Pdf.Generator.Segment TextSeg = new Aspose.Pdf.Generator.Segment("

[February 5, 2013]

In a February 4, 2013, Updated Urgent Device Field Correction letter submitted by Hospira, the firm notified its customers of additional recommendations to prevent the problem described below from occurring.

");

TextSeg.TextInfo.FontName = “Times New Roman”;
TextSeg.TextInfo.FontSize = 8;
TextSeg.TextInfo.IsTrueTypeFontBold = false;
Text1.Segments.Add(TextSeg);

Text1.IsHtmlTagSupported = true;

Aspose.Pdf.Generator.Cell RowCell = ActionRow.Cells.Add();
RowCell.Paragraphs.Add(Text1);

Another Example

string s = “
” + “This is a test for HTML </ support " + " in Text paragraph.” + "Search ";
string s2 = “This is a test for HTML with colored text.”;

Aspose.Pdf.Generator.Text Text1 = new Aspose.Pdf.Generator.Text("Description: " + s + s2);
Aspose.Pdf.Generator.Cell RowCell = ActionRow.Cells.Add();
RowCell.Paragraphs.Add(Text1);

Need your suggestion in this regard.


Hi Preeti,


Thanks
for using our products.
<o:p></o:p>

I
have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this issue as PDFNEWNET-36032 in
our issue tracking system. We will further look into the details of this problem
and will keep you updated on the status of correction. Please be patient and
spare us little time. We are sorry for this inconvenience.

Hello,

I´m facing the same problem.

What´s the status about this issue?

Hi Sallmutter,


The development team has been busy resolving other priority issues and I am afraid the earlier reported issue is not yet resolved. Nevertheless, I request you to please share the HTML which you are using so that we can also consider this scenario during the resolution of this problem. We apologize for this inconvenience.

Hi Nayyer,

thanks for your fast answer. :)

At the moment I´m not having a concrete formatting needed.

The problem occured when I was putting
tag in Text, activated IsHtmlTagSupported and then just tried to set the font size in the section object. I also tried to set font-size in Text-object. Here is the Code:

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(fs);
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
Text header = new Text("
Variable1: " + v1 + " " + "Variable2: " + v2 + "

");
header.IsHtmlTagSupported = true;
sec1.Paragraphs.Add(header);
sec1.TextInfo.FontSize = 10;

The Pdf is created correctly and looks like expected, only the font size is to big. I´m looking forward to the solution and will try to work around this issue by setting the font size by HTML.

Thanks in advance and best regards!

Hi Sallmutter,


Thanks for sharing the details.

I
have tested the scenario and have observed that when using
tag and setting
IsHtmlTagSupported to true, the text size is not getting changed. For the sake
of correction, I have logged this issue as
PDFNEWNET-36143 in our
issue tracking system. We will further look into the details of this problem and
will keep you updated on the status of correction. Please be patient and spare
us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNEWNET-36143) have been fixed in Aspose.Pdf for .NET 9.1.0.

For further details, you may check this blog post.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Sallmutter,


By default font sizes and styles are applied from HTML. When it is necessary to overwrite it with font information of Text itself, please use UseTextInfoStyle flag .Please check following code snippet for the purpose, It will help you to fix the issue.

Aspose.Pdf.Generator.Pdf pdf = new
Aspose.Pdf.Generator.Pdf();<o:p></o:p>

Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();

Text header = new Text("
Variable1: "
+ "v1" + " " + "Variable2: " + "v2" + "
"
);

header.IsHtmlTagSupported = true;

header.UseTextInfoStyle = true;

header.TextInfo.FontSize = 50;

sec1.Paragraphs.Add(header);

pdf.Save("HTMLFormatting.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36032) have been fixed in Aspose.Pdf for .NET 9.4.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Sallmutter,


In reference to above stated fix, please note when conversion from HTML of text fragment is in use (i.e when IfHtmlTagSupported set to ‘true’), two things occur:

  1. Text of all segments of Text that treated as HTML is concatenated before conversion
  2. HTML-produced style applied to result objects after conversion.

To get desirable behavior from conversion in this case You need :

  1. Don’t use TextInfoStyles of segments - they are just ignored.
  2. Use TextInfoStyle of Text to set font size(and maybe fontname) that must overwrite fontsizes and fontnames from HTML.
  3. Use parameters
Text.UseTextInfoStyle
Text.IfHtmlTagSupportedOverwriteHtmlFontSizes
Text.IfHtmlTagSupportedOverwriteHtmlFontNames
to enforce usage of that text-parameters from parameters of text block instead parameters specified in HTML - converter (or default parameters of HTML-converter).


Please find a sample code snippet for the reference, hopefully it will help you to accomplish the task.


Pdf pdf = new Pdf();<o:p></o:p>

Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();<o:p></o:p>

Aspose.Pdf.Generator.Text Text1 = new
Aspose.Pdf.Generator.Text(“Description: “);<o:p></o:p>

Text1.TextInfo.FontName = “Times New Roman”;<o:p></o:p>

Text1.TextInfo.FontSize = 3;<o:p></o:p>

Aspose.Pdf.Generator.Segment TextSeg = new
Aspose.Pdf.Generator.Segment(”[February 5, 2013] In a February 4, 2013,
Updated Urgent Device Field
Correction letter submitted by
Hospira
, the firm notified its customers of additional
recommendations to prevent the problem described below from occurring.”
);<o:p></o:p>

Text1.Segments.Add(TextSeg);<o:p></o:p>

Text1.IsHtmlTagSupported = true;<o:p></o:p>

//-----------------------------------------------------<o:p></o:p>

// this code added
to get required behaviour :
<o:p></o:p>

//-----------------------------------------------------<o:p></o:p>

Text1.UseTextInfoStyle = true;<o:p></o:p>

Text1.IfHtmlTagSupportedOverwriteHtmlFontSizes
= true;<o:p></o:p>

Text1.IfHtmlTagSupportedOverwriteHtmlFontNames
= true;<o:p></o:p>

//-----------------------------------------------------<o:p></o:p>

Aspose.Pdf.Generator.Table tab1 = new
Aspose.Pdf.Generator.Table();<o:p></o:p>

sec1.Paragraphs.Add(tab1);<o:p></o:p>

tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All,
0.5f, new Aspose.Pdf.Generator.Color(“Red”));<o:p></o:p>

Aspose.Pdf.Generator.Row row1 = new
Aspose.Pdf.Generator.Row(tab1);<o:p></o:p>

tab1.Rows.Add(row1);<o:p></o:p>

Aspose.Pdf.Generator.Cell RowCell = row1.Cells.Add();<o:p></o:p>

RowCell.Paragraphs.Add(Text1);<o:p></o:p>

pdf.Save(@“36032_out.pdf”);<o:p></o:p>

Please feel free to contact us for any further assistance.


Best Regards,