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,
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,