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

Free Support Forum - aspose.com

Problem Aspose.Word MailMerge in case inserting HTML - it adds extra space after html

Hello.
Aspose.Words adds extra Paragraph after my HTML in case when we use MailMerge.ExecuteWithRegions with IFieldMergingCallback to insert html. And even if we use workaround suggested by your team long time ago - it doesn't help.

Hi

Thanks for your request. Please try adding the highlighted code:

public void FieldMerging(FieldMergingArgs args)

{

DocumentBuilder db = new DocumentBuilder(args.Document);

db.MoveToMergeField(args.DocumentFieldName);

db.InsertHtml(args.FieldValue.ToString());

Paragraph currentParagraph = db.CurrentParagraph;

bool KeepWithNext = db.ParagraphFormat.KeepWithNext;

Aspose.Words.Style parFrmtStyle = args.Document.Styles[db.ParagraphFormat.Style.Name];

if (currentParagraph != null && currentParagraph.ParentNode != null)

{

currentParagraph.ParagraphFormat.Style = parFrmtStyle;

currentParagraph.ParagraphFormat.KeepWithNext = KeepWithNext;

NodeCollection paragraphs = currentParagraph.ParentNode.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph p in paragraphs)

{

p.ParagraphFormat.Style = parFrmtStyle;

p.ParagraphFormat.KeepWithNext = KeepWithNext;

if (p.ParagraphFormat.SpaceAfterAuto == true)

{

p.ParagraphFormat.SpaceAfterAuto = false;

p.ParagraphFormat.SpaceAfter = 0;

}

}

}

if(currentParagraph !=null && !currentParagraph.HasChildNodes)

currentParagraph.Remove();

}

Hope this helps.

Best regards,

Thanks, seems it helps.
Will you ever fix this problem? because if you will then I will need to remove this workaround.

Hi

Thanks for your request. It is perfect that the workaround helped. Actually this is not a problem. This is expected behavior when you insert HTML block with paragraphs.

Best regards,