Free Support Forum - aspose.com

Spacing of listitems on InsertHTML

When using InsertHTML on the DocumentBuilder, an extra line feed is entered between each list item if the list items are in an

    tag set. In browsers, there is no line feed separating each line, but after being imported into Word, there is. Is there a way to change a setting in Aspose.Words to rectify this, or is a fix required? This is impacting my users more than you might thing, because it makes their loan documents stretch to 3 printed pages rather than 2, which makes each loan officer have to do a lot of manual reformatting of the Word document. Any help you can provide would be much appreciated, as would a time estimated if a fix is required.

    Thanks,
    Chris

    Example code is below:

    <ol type="1">
    <li>The Royal Apartments will be built on the site of the existing store. This project will provide an additional 33 units of needed affordable housing. </li>
    <li>By moving to the new location SVdP will be moving into a neighborhood that will have a demand for SVdP’s product lines. SVdP will also build a larger store (19,500 SF) that will be able to operate more efficiently and profitably than the existing 6,000 SF building. </li>
    </ol>

I have tested DocumentBuilder.InsertHtml method with the provided html sample and there was no extra line feeds between list items. The resulting document is attached.

Please provide code sample or test project sufficient to reproduce this problem.

Best regards,

Ah, I see that you are correct. I've adjusted my testing, and also do not recieve the problem with that code snippet. There is a bug in the html editor that I am using, so that it showed me the code I posted before, but was actually sending your component the following code:


  1. The Royal Apartments will be built on the site of the existing store. This project will provide an additional 33 units of needed affordable housing.
  2. By moving to the new location SVdP will be moving into a neighborhood that will have a demand for SVdP’s product lines. SVdP will also build a larger store (19,500 SF) that will be able to operate more efficiently and profitably than the existing 6,000 SF building.

The only difference between the two is that there is no closing tag for the first li. When you run it using this html, it puts the extra line breaks in there. I am going to work with the vendor of the html editor to get their bug fixed, so this issue is effectively closed for me, but this minor display issue might be one that you want to address in a future release; the code appears correctly in IE and FireFox, even without the missing closing tag.

Thanks again for your help.

Still cannot reproduce it. Are you using the latest version of Aspose.Words?

I am using Aspose.Words 3.7.1.0, and I'm running .NET 2.0 with Visual Studio 2005. Visual Studio reports that the runtime version of your Aspose.Words.dll is 1.1.4322--that was the only version I saw on the website, and I don't know if that would cause any problems.

I have attached the template file I am using. Importing into the ProjectSummary or several other of the merge fields produces the issue (the issue has occurred on all the merge fields I have tested it with). I have reliably reproduced this on three different machines, two running Windows 2000 and one running Windows XP. It only occurs when the ending tag is missing. The code I am using is below (it is filled from a database table):

string templatePath = Configuration.Instance.EnterpriseFiles + @"StandardInstanceReportTemplates\" + row["OutputFilename"] + ".doc";

Document doct = new Document( templatePath );
DocumentBuilder builder = new DocumentBuilder( doct );

builder.MoveToMergeField( "ProjectSummary" );
builder.InsertHtml( data.ToString() );

MemoryStream stream = new MemoryStream();
doct.Save( stream, SaveFormat.FormatDocument );

byte[] data = stream.ToArray();
stream.Close();
return data;

Thanks for the additional info. Unfortunately, the attachment failed somehow. Pease reattach the file.

It was attached before–I could see it on the view page after uploading it. However, it’s definitely gone now. I edited my post after I submitted, and that must have dropped the file. I’ve uploaded the file again as an attachment to this reply.

The extra spacing after list items is caused by Paragraph Space After = 'Auto' setting. Normally it should be applied only to the last item of the list. If you copy your sample list from html to MS Word document using copy/paste you will see the exactly same behavior demonstrated by MS Word.

In your case the lack of closing cause Aspose.Words to set Space After 'Auto' also for the first item in the list.

To correct this please try the following code:

builder.MoveToMergeField("ProjectSummary");

Paragraph startingParagraph = builder.CurrentParagraph;

builder.InsertHtml(@"

  1. The Royal Apartments will be built on the site of the existing store. This project will provide an additional 33 units of needed affordable housing.
  2. By moving to the new location SVdP will be moving into a neighborhood that will have a demand for SVdP’s product lines. SVdP will also build a larger store (19,500 SF) that will be able to operate more efficiently and profitably than the existing 6,000 SF building.
");

Paragraph paragraph = builder.CurrentParagraph;

while (paragraph != startingParagraph)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

paragraph = (Paragraph)paragraph.PreviousSibling;

}

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

Best regards,