Rich Text Not Converted To HTML When InsertHtml is Used

We created a merge field in both the header and the body of a word document with the same name. After running InsertHtml, it appears to have inserted itself in the header once as plain text, and twice in the body as the expected converted HTML. When the file only has one merge field in the header, the output correctly converts the HTML in the field for the header. I’ve attached the input file (rich in header (1).docx) and the output file (rich in header_out.docx).
Code

var inputStream = System.IO.File.OpenRead(@"C:\Users\Dan\Downloads\rich in header (1).docx");
var document = new Aspose.Words.Document(inputStream);       
document.MailMerge.FieldMergingCallback = new HandleMergeField();
document.MailMerge.Execute(new string[] { 
    "Title:RichText"
}, new object[] { 
    "<p>Developer</p>"
});

Merge Field Handler

class HandleMergeField : IFieldMergingCallback
{
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        var builder = new DocumentBuilder(e.Document);

        if (e.FieldName.ToLower().Contains(":richtext"))
        {
            builder.MoveToMergeField(e.FieldName);
            builder.InsertHtml((string)e.FieldValue);
            return;
        }
    }

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
    }
}

Hi Brett,

Thanks for your inquiry. In your case, you need to move the cursor to the header of section as shown below. I have modified your code. Please check the following highlighted code snippet. Hope this helps you. Please let us know if you have any more queries.

class HandleMergeField : IFieldMergingCallback
{
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        var builder = new DocumentBuilder(e.Document);

        if (e.FieldName.ToLower().Contains(":richtext"))
        {
            if (e.Field.Start.GetAncestor(NodeType.HeaderFooter) != null)
                builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

            builder.MoveToMergeField(e.FieldName);
            builder.InsertHtml((string)e.FieldValue);
            e.Text = "";
        }
    }

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
    }
}