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

Free Support Forum - aspose.com

Aspose.Words Builder.InsertHtml behaviour

I have been working with the InsertHtml method of the DocumentBuilder class. I have found some strange behaviour since I upgraded to the recent version of Aspose.Words.

Depending on whether I concatenate html together, or call InsertHtml twice, I get different output shown here as additional spacing between two tables.

Can you please explain why I am getting this different output, and how I am able to remove the additional spacing when calling InsertHtml multiple times.

In an earlier version of Aspose.Words, this additional spacing was not present.


var myDir = "C:/Development/";
var html = @"

This is sample content

More Content

";

Aspose.Words.Document documentWithDuplicateHtml = new Aspose.Words.Document();
DocumentBuilder builderWithDuplicateHtml = new DocumentBuilder(documentWithDuplicateHtml);
builderWithDuplicateHtml.InsertHtml(string.Format("{0}{0}", html));
documentWithDuplicateHtml.Save(string.Format("{0}DuplicateHtml.doc", myDir));

Aspose.Words.Document documentWithDoubleInsert = new Aspose.Words.Document();
DocumentBuilder builderWithDoubleInsert = new DocumentBuilder(documentWithDoubleInsert);
builderWithDoubleInsert.InsertHtml(html);
builderWithDoubleInsert.InsertHtml(html);
documentWithDoubleInsert.Save(string.Format("{0}DoubleInsert.doc", myDir));

To clarify, I need to find out why the following:

builderWithDoubleInsert.InsertHtml(html);
builderWithDoubleInsert.InsertHtml(html);

generates a different output from this:

builderWithDuplicateHtml.InsertHtml(string.Format("{0}{0}", html));

I also need to know how I can achieve the same layout as a single InsertHtml statement, while using multiple InsertHtml calls.

The above is a simplified example, so concatenating my html and making a single call is not an option.

Please respond asap.



Hi,

Your HTML starts with a line break '
' which produces extra space. You can remove this line break in case of double calls to InsertHtml method.

Best Regards,

Thank you for your response.

As I have stated, the above is just an example to illustrate what I believe to be incorrect behaviour, and in no way resembles the system I am working on. So this is not an acceptable resolution.

My question (and issue) is that calls to InsertHtml seem to add an unnecessary line break which is adding extra space to my document where I do not need it.

Due to the nature of my system, I cannot make changes to my html, and need to understand how I can make multiple calls to InsertHtml and not have it automatically add and extra line, and only insert a new line where the Html contains a "
" tag.

Please reply asap

Hi,

This actually is not a bug. If you insert HTML without tables, you will not see this extra line but if you insert HTML with tables, it will print extra line.

The reason is that you cannot insert consecutive tables in MS Word. There must be an empty paragraph between two table in MS Word. This was a bug in older versions which was fixed and latest versions replicate the correct behavior you see in MS Word.

Best Regards,

I understand that you cannot have consecutive tables in ms word. However, in my examples, I have already entered a “
” tag between my two tables, to ensure that the tables render with a space between them.


So it seems incorrect to me, that InsertHtml would add an additional empty paragraph to prevent consecutive tables, when (as per my example) the tables are not consecutive.

It also seems counter-intuitive that:

builder.InsertHtml(html + html);

would ever have a different output from

builder.InsertHtml(html);
builder.InsertHtml(html);

Can you explain why there is a difference between the above code snippets?

Hi,

This issue has been logged into our issue tracking system as WORDSNET-11100. We will keep you updated on this issue in this thread. In the meantime, you can pass one less
tag when calling InsertHtml method consecutively.

Best Regards,

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


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