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

Free Support Forum - aspose.com

Using Div in InsertHtml sets SpaceAfterAuto to true

I am writing the following html in to a word document using builder.InsertHtml()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
    <div align="left"><font face="Arial"><span style="font-size:8pt">a</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">b</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">c</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">d</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">e</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">f</span></font></div>
    <div align="left"><font face="Arial"><span style="font-size:8pt">g</span></font></div>
    <div align="left">&nbsp;&nbsp;</div>
</body>
</html>

The problem is that the div element causes each paragraph that is created from this insert to have its ‘SpaceAfterAuto’ value set to true and the ‘SpaceAfter’ value set to 14.0.
This produces extra spacing between each line which is inconsistent with how this html is presented when opened in either IE / Microsoft Word.
I cannot edit/change the html as this is output from another third party html control.
Please advise how I can avoid this line spacing problem?

Hi
Thanks for your request. It seems the problem occurs because Aspose.Words writes automatic spacing after each paragraph. I linked your request to the appropriate issue. You will be notified as soon as the problem is resolved.
Best regards,

Please explain what you mean by ‘I linked your request to the appropriate issue.’ Is this a known issue? What other issues/threads are related to?
Please also advise on the timescales of this fix?
Please also advise if there is a workaround as our code base is entering code freeze end of Feburary?
Thanks and Regards
Daniel Finkelstein
Senior Software Engineer
HP Software

Hi

Thanks for your request. Yes, it is known issue. Our developers are currently working on this and other issues. But, unfortunately, I cannot provide you any reliable estimate regarding this issue. Please expect a reply before next hotfix (within 4-5 weeks). We might just fix the problem or provide you more information.
As a workaround, you can try performing post-processing after inserting HTML. For example, you can try using code like the following:

builder.InsertHtml(html);
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach(Paragraph paragraph in paragraphs)
{
    paragraph.ParagraphFormat.SpaceAfterAuto = false;
}
doc.Save(@"Test\out.doc");

Best regards,

Any update on resolving this issue? It certainly was not fixed in any hotfix, and it still occurs in the latest version 9.0.0 downloaded today?
This is now the most problematic outstanding issue we have with our use of Aspose.Words.
Your workaround cannot be used as the inserted html may be complex containing multiple lists and other more complex html. Manually setting the autospacing of each paragraph is no good as it may remove spacing (normally after a list) that is actually required.
Any update or further help on this issue would be appreciated.
Thanks
Daniel Finkelstein
Senior Developer, HP Software

Hi Daniel,
Thanks for your request. Unfortunately, the issue is still unresolved and currently I cannot provide you any additional information regarding this. I added your request into my monthly report; this will push the issue up in the priority list. We will let you know once the issue is resolved.
Best regards,

Hi
We had the same problem, and I was very grateful for fining this thread and the idea for a workaround.
So I thought I would share my Java version of the fix to help others out.
We use insertHtml to insert some externally generated html into a predefined word “template” with existing styled formatting, so I had find a targeted way of fixing only the inserted html-based paragraphs. Luckily I never use SpaceAfterAuto in my own styles, so I fixed the problem with the following code:

builder.insertHtml(htmlString);
// Here we fix the generated document.
NodeCollection paragraphs = builder.getDocument().getChildNodes(NodeType.PARAGRAPH, true);
Node[] array = paragraphs.toArray();
for (Node node: array)
{
    Paragraph p = (Paragraph) node;
    if (p.getParagraphFormat().getSpaceAfterAuto() == true)
    {
        p.getParagraphFormat().setSpaceAfterAuto(false);
        p.getParagraphFormat().setSpaceAfter(0);
    }
}

Hi Jan,
Thank you for sharing your experience.
Best regards,

Any Update or Progress with this fix?
The above solution does no help due to the following:
a) We do not control the other styles in the document or html and therefore we cannot take the approach of removing all SpaceAfterAuto.
b) Our documents are often very large (InsertHtml may be called 1000’s of times). Looping over the correct paragraphs each time we inserthtml is therfore likely to effect performance.
Thanks
Daniel Finkelstein
Senior Engineer, HP Software

Hi Daniel,
Thank you for additional information. Unfortunately, the issue is still unresolved. We will let you know once there is some progress with this issue. My apologizes for inconvenience.
Best regards,

The issues you have found earlier (filed as 17921) have been fixed in this update.

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