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

Free Support Forum - aspose.com

How to keep paragraph format when using insertHtml method

Hi there

I'm trying to find a solution for a problem we've encountered within our implementation of Aspose.Words (Version:

The situation is as follows:

A user can create a Word Document which will be used as a template for a report within our application. Within the Template, the user can insert variables which should be replaced with content collected from the application, which matches the variable declaration. Upon generating a report, based on the previously mentioned template, the application will collect all user generated content from the application and inserts it at the designated position within the document. The content which needs to be inserted into the report, can contain HTML Code. In order to insert this particular type of content, we use the "DocumentBuilder.InsertHtml(strHTMLStringToInsert)" method.

The problem we're facing is that, once the HTML has been inserted into the DocumentBuilder, the paragraph format of the inserted content won't match the paragraph format defined within the Template document.

What would you suggest as an alternative means for solving this problem?

Many thanks.


Hi Hanh,

for your inquiry. 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

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.

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.

Please use DocumentBuilder.InsertHtml method with parameter (useBuilderFormatting) and set its value as true. If you still face problem, please share following detail for investigation purposes.

  • Please attach your input Word document and Html.
  • Please

    create a standalone/runnable simple application (for example a Console
    Application Project
    ) that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi guys,

Thanks for your feedback. I’ve already applied argument useBuilderFormating is true for my document. This code run correctly as my expert.

Many thanks for your solution :slight_smile:

Hi Hanh,

for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.