Html with sub and sup tags is printed in wrong front from Aspose 13.10 and newer (#36034)

Hi,

We have a html with some text in which a portion is marked with or tags to make text subscript or superscript. I attached the html to this post.

When we use insertHtml on the builder to insert the image and save it to .docx with Aspose version 13.9 the fontsize of the normal text and the sub and superscript text is 10pt. (I also tested with 13.6 which also worked ok)

However, when I use Aspose 13.10 or higher (also tested with latest release 14.12) the normal text is 10pt, and the subscript and superscript text is 14.5pt.

Can you reproduce and solve this issue?

Best regards,
Robert Wielink
Infoland BV

Hi Robert,

Thanks for your inquiry. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-11413. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Robert,

Thanks for your patience. It is to inform
you that the issue which are facing is actually not a bug in
Aspose.Words. So, we have closed this issue (WORDSNET-11413) as ‘Not a
Bug’.

By default, Aspose.Words adjusts font size of and elements to make visible size of imported text as large as in browsers. Please use use DocumentBuilder.InsertHtml with useBuilderFormatting=true in order to disable the font size adjustment.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(File.ReadAllText(MyDir + "subandsuperscript.html"), true);
doc.Save(MyDir + "Out.docx");

We introduced a new overload of DocumentBuilder.InsertHtml method which allows you to choose what formatting will be used as a base for inserted HTML fragments.

The new overload has an argument useBuilderFormatting which when is false,
formatting specified in DocumentBuilder is ignored, and formatting of inserted text is based on default HTML formatting. In this case, inserted text looks as in browsers.

When useBuilderFormatting is true, formatting of inserted text is based on formatting specified in DocumentBuilder. Note that useBuilderFormatting chooses only base formatting of inserted text, and do not affect formatting directly specified in the HTML fragment.

Hi,

I did some more testing, and the behaviour when using InsertHTML(strHTML, true) is now what we are expecting.

Is my assumption correct that when using InsertHTML(strHTML, true) the behaviour is the same as the default behaviour was in Aspose 13.9 and lower?

Or are there any other changes we should be aware of?

Best regards,
Robert Wielink
Infoland BV

Hi Robert,

Thanks for your inquiry.

The new
overload method of InsertHtml has an argument useBuilderFormatting which when is false,
formatting specified in DocumentBuilder is ignored, and formatting of
inserted text is based on default HTML formatting. In this case,
inserted text looks as in browsers.

When
useBuilderFormatting is true, formatting of inserted text is based on
formatting specified in DocumentBuilder. Note that useBuilderFormatting
chooses only base formatting of inserted text, and do not affect
formatting directly specified in the HTML fragment.

The following example illustrates the difference between the two modes:

DocumentBuilder builder = new DocumentBuilder();
builder.ParagraphFormat.LeftIndent = 72;
builder.Font.Name = "Arial";
builder.Font.Size = 24;
bool useBuilderFormatting = …
builder.InsertHtml("<b>Text</b>", useBuilderFormatting);

In this example, if useBuilderFormatting is false, the inserted paragraph will have no left indent and will use the ‘Times New Roman’ 12pt font, which is the default HTML font and indent. If useBuilderFormatting is true, the inserted paragraph will be indented by 1 inch (72 points) and will use the ‘Arial’ 24pt font, as specified in DocumentBuilder.
However, in both cases the inserted text will be bold and red, as specified in the HTML fragment.

So, please try using this method as follows:

builder.InsertHtml("Some text before ", true);

Hope this helps you. Please let us know if you have any more queries.