I would like to insert several documents into another document during mail merge.
The documents are merged, but there is a break after each inserted document. How can I remove the break after inserting?
The expected result:
We would like this to be on the same line, with the other text right here and also this text.
But instead I get:
We would like this to be on the same line,
with the other text right here
and also this text.
I have followed the example from: Insert a Document During Mail Merge
Where I use builder.insertDocument(), instead of the insertDocument() method from the example. The insertDocument() method in the example inserts the documents in the wrong order and also creates breaks after each insert.
Can be reproduced with the attached Java project: AsposeTest.zip (30.3 KB)
Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. In your case, we suggest you following solution.
In InsertDocumentAtMailMergeHandler, insert the bookmark before inserting the document.
After mail merger, iterate over inserted bookmarks and merge the paragraphs nodes that contains the bookmark and its next sibling.
Following method shows how to merge two paragraphs.
public static void mergeParagraphs(Paragraph dstPar, Paragraph srcPar)
{
//move all content from source paragraph into the destination paragraph
while (srcPar.hasChildNodes())
dstPar.appendChild(srcPar.getFirstChild());
//Remove source paragraph
srcPar.remove();
}