Free Support Forum - aspose.com

Query: Insert HTML method

Hello Team,


We are facing issue with builder.InsertHTML() method when formatting HTML tag

is used along with general Paragraph formatting. Formatting is not properly applied as expected.
Sample code is given for your consideration,

Document doc = new Document();
DocumentBuilder builder =
new DocumentBuilder(doc);
builder.ParagraphFormat.Alignment =
ParagraphAlignment.Center;
builder.InsertHtml("

Hi My name is
Amit.

");
//builder.InsertHtml(“Hi My name is
Amit.”);
builder.InsertBreak(BreakType.LineBreak);
builder.ParagraphFormat.Alignment
= ParagraphAlignment.Right;
//builder.InsertHtml(“end of th
text.”);
builder.InsertHtml("

end of th
text.

");
builder.InsertHtml(“For End of
doc”);
builder.Document.Save(“test.doc”);
StartWord(“test.doc”);

Also take a look at the attachment (output of the above code sample), and let us know.

best regards.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. During inserting HTML, HTML formatting overrides formatting defined in the document. This is correct behavior, I think, because in the other case formatting, defined in your HTML, will be lost.

Best regards.

Hello Team,

Thanks very much for your timely response. The issue with Paragraph is been solved.

We have one more doubt about the Font tag used in HTML rendering.

We are concerned about the size of the font. We have observed that the Font tag takes Size values from 1 to 6.

We are using following input text

documentbuilder.InsertHTML("This is test for font size");

when we observe this on the word document the font size is 13.5 (this we have verified from the Word Font drop down selector)

the query here is, is it possible to use actual values of the Font sizes like 8 to 72 (which are available in the word document with Font drop down selector) in the Font tag and will it work....meaning if user sets size="16"

documentbuilder.InsertHTML("This is test for font size");

the outputted text will have exact size of 16 for the text.

Kindly explain.

Best Regards.

Hello Dwarika!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for asking this.

Font size specified in the size attribute and without measurement units means so named HTML font size. It can be an integer number from 1 to 7 and maps to the real size in points as follows:

1 – 7.5pt

2 – 10pt

3 – 12pt

4 – 13.5pt

5 – 18pt

6 – 24pt

7 – 36pt

So you are getting 13.5 while specifying 4. To set font size in points, as it used to be in Microsoft Word, try this:

font-size:16pt">This fragment of text has font size 16

Regards,

Hello Team,


In continuation with the HTML formatting, we have one more query related to HTML List Tag

  • Attached is the output and description about the same. Take a look at the highlighted inputs.
    We would like to know why there is difference in the two outputs.

    Waiting for your reply.

    Regards,
    Dwarika

    Hi Dwarika,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    Thanks for your request. This occurs because in one case both items belong to the same list and in other case list items belong to different lists.

    Here is the first case:

    <ul>

    <li>first item</li>

    <li>second item</li>

    </ul>

    Here is the second case:

    <ul>

    <li>first item</li>

    </ul>

    <ul>

    <li>second item</li>

    </ul>

    Best regards.