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

Free Support Forum - aspose.com

Additional WordWraps


I have a document which contains 5 mergefields in one line inside a table-field, no spaces or linebreakes between the mergefields. this fields are filled with the content of 5 small word-documents. I save the small documents as html and after that i’m executing the MailMerge.Execute with the html strings.

now i have a problem, because there are occuring additional wordwraps / linebreaks after SOME of the included text blocks. first i thought that there are some differences inside the small documents, but than Itested it using the same small document for all five mergefields and there are still UNWANTED linebreaks after the 2nd and 4th text block.

this is a big problem for me because this negative layout-effect is not tollerable in a contract-document.

best regards


Thanks for your request. Could you please attach your template, output and expected output documents, code and sample data here for testing? I will check the issue on my side and provide you more information.

Best regards.

Hello again,

so i found out what the problem is but i have no idea how to resolve it.
It seems to be a problem of order of document merges. When I execute MailMerges for the single documents in the same order like they appear inside the document, everything is all right. but when I execute the merges with an other ordering, there apperar additional line breaks.

I suppose this to be an error in Apose. I can’t post the complete code for legal causes.
But I will show you how I use Aspose in this case.

I do the following steps for each MergeField in a RANDOM order.

1.convert sub-document to HTML
docTemp.Save(memStreamHtml, SaveFormat.Html);
2. start MailMerge for the converted document
Text.MailMerge.Execute(new string[] { key }, new List[] { list });
3. put the HTML inside the parent-document (Eventhandler)
DocumentBuilder docBuilder = new DocumentBuilder(e.Document);
e.Text = string.Empty;

I attached the used files, so you can test it.
How can I resolve this? Is there a way to fix this? Because of dynamic sub-document-selection it’s not possible to use a special order…

result_corresct - correct Output (order single MailMerges for subfiles: Fahrraddiebstahl, Element1, Element2, Element3, Haushaltsglas)
result_false - Output Containing additional line breaks (Fahrraddiebstahl, Element2, Haushaltsglas, Element3, Element1)
main - document with mergefields

best regards


Thank you for additional information. I suppose you use code like the following:

// Open source document.

Document doc1 = new Document(@“Test001\Fahrraddiebstahl.doc”);

Document doc2 = new Document(@“Test001\Elementar1.doc”);

Document doc3 = new Document(@“Test001\Elementar2.doc”);

Document doc4 = new Document(@“Test001\Elementar3.doc”);

Document doc5 = new Document(@“Test001\Haushaltsglas.doc”);

// Prepare datasource for mail merge.

string[] names = { “tb_Elementarschaden1”, “tb_Fahrraddiebstahl”, “tb_Elementarschaden2”, “tb_Elementarschaden3”, “tb_Haushaltsglas” };

// Plrepare array with data.

object[] values = { ConvertDocumentToHtml(doc1),




ConvertDocumentToHtml(doc5) };

// Open template document.

Document doc = new Document(@“Test001\main.doc”);

// Add MergeField event handler

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_InsertHtml);

doc.MailMerge.RemoveEmptyParagraphs = true;

// Execute mail merge

doc.MailMerge.Execute(names, values);

// Save output docuemnt



void MailMerge_InsertHtml(object sender, MergeFieldEventArgs e)


// Create document builder

DocumentBuilder builder = new DocumentBuilder(e.Document);

// Move builder cursor to the mergefield


// Insert HTML


e.Text = string.Empty;



public string ConvertDocumentToHtml(Document doc)


string html = string.Empty;

// Save docuemnt to MemoryStream in Hml format

using (MemoryStream htmlStream = new MemoryStream())


doc.Save(htmlStream, SaveFormat.Html);

// Get Html string

html = Encoding.UTF8.GetString(htmlStream.GetBuffer(), 0, (int)htmlStream.Length);


// There could be BOM at the beggining of the string.

// We should remove it from the string.

while (html[0]!=’<’)

html = html.Substring(1);

return html;


This code works correctly on my side. I tried different order of fields. Could you please check this code on your side and let me know if it works fine?

Best regards.


I compaired your code to mine and I found one significant difference. In my code MailMerge.Execute is executed seperatly for each inserted text block. After changing this to a single execution some of the additional word wraps disappeared. Never

the less, it would be very interesting to know, why several executes have this side-effect.

After the last text block one addional word wrap is left.
When i put an new carriage return as last sign inside the last text block, in front of the inserted text-block-line-break there is shown the following sign: °

so it’s a little confusing.

best regards


Hi Andreas,

Could you please show me your current output document? I will check it and provide you more information. Also, you can modify the code I provided in my previous post, so it look similar to your code and attach it here. I will also check the code.

Best regards.


the zip file contains actual files including the changed input (element1 includes additional new line) and the current result file. Prblems are: the sign after “Text2” and the formatting of the last word-wrap (large gap to next line - you can see it clearly after an “enter” in the last line)

best regards


Thank you for additional information. This occurs because empty paragraph in a Word document is exported to HTML as a paragraph with non-breaking space. This is invisible character, and if you disable “Show/Hide” option in MS Word (¶ button) you will not see it.

Best regards.


the last problem ist the large gap after the last word-wrap - why is the “gap after” set to “auto” instead 0? so there is a larger gap than disired…

best regards


Thanks for your request. As I can see Spacing After and Spacing Before that paragraphs are correct (0 pt). I think spacing between lines Test2 and Test3 is bigger than needed because font size of inserted non-breaking space is 10, and paragraph break font size is 6.

Best regards.


The issues you have found earlier (filed as WORDSNET-1077) have been fixed in this Aspose.Words for .NET 17.10 update and this Aspose.Words for Java 17.10 update.