Applying css paragraph inline style with inserthtml

Hi,

I try to put a simple html paragraph with inline css style like that

string sHtml = "<p style='font-size: 18;text-align:center'>This is 18 and centered </p>"
builder.InsertHtml(html);

The result in the word docx is not well formated : The text is centered but the font size stays 12 that is the default one.

Can you help me to obtain the right font property ?

Hi

Thanks for your request. The problem occurs because, currently, Aspose.Words does not support inheriting styles from parent elements.
Currently, Aspose.Words expects that font formatting is set in <span> element, formatting of paragraph – in <p> or <h1><h6> elements etc…
I linked your request to the appropriate issue, you will be notified as soon as it is resolved.

In your case your HTML should look like the following:

string sHtml = "<p style='text-align:center'><span style='font-size: 18pt'>This is 18 and centered</span></p>";

Best regards.

Hi and thanks a lot, it works fine.
Now 3 questions :

  1. I was surprised that you choose to interprete some attributs of style in paragraph type tag and some others in span. For example, the text-decoration is well taken in span and text-align in paragraph.
    To help me to use InsertHtml method can you tell me if there is a logic behind ?
  2. My last problem (I hope) is about the margin. Can you tell me if there is a solution to use this from HTML using the InsertHtml method ?
  3. Can you give me limitations about what is not interpreted by InsertHtml method ?

Regards

Hi

Thanks for your request.

  1. You should note that Aspose.Words was originally designed to work with MS Word documents. HTML format very differs from MS Word documents format. That is why some things in HTML are difficult to map to the corresponding things in MS Word documents.
  2. You can set margins of paragraph in HTML. For instance:
<p style="margin-top:50pt; margin-bottom:50pt; margin-left:50pt;margin-right:50pt; ">test</p>
  1. Unfortunately, currently there is no list of HTMl features supports upon importing HTML. Currently there is a list of features supported upon exporting to HTML:
    https://docs.aspose.com/words/net/save-in-html-xhtml-mhtml-formats/

Most of features supported upon HTML export are also support upon importing HTML.
Best regards,

Thanks Alexey for your answers so quick and clear.

Reading the forum, I see that I’m not the first or the only one that use an Html rich editor like TinyMCE and be happy to produce Word document at the end for our customers. Do you think you will improve the InsertHTML function, like the possibility to use use external CSS classes ?
Again I can now go on to my dev according to your answers. The more I use Aspose Words the more I’m satisfied by it flexibility.

Regards

Hi

Thanks for your request. Sure, we are working on improving our HTML import module.
Regarding using external CSS file, you already can use it with InsertHtml method. However, since you insert HTML as a string, Aspose.Words does not know where to find CSS file if specified relative path to CSS. So, you should specify absolute path like shown below:

This should be red text.

Also, you can specify baseurl, like shown below:

This should be red text.

Hope this helps. Best regards,

The issues you have found earlier (filed as WORDSNET-2021) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(19)