Aspose.Word for .net double quote in IF Condition

Hello Team,
We are using aspose.word 24.12.0 we are not able to print the double quote in the output. Kindly advise
Template file is
TestTemplateIFDoubleQuotes.docx (13.4 KB)

and our code is

using Aspose.Words;
using Aspose.Words.MailMerging;

string[] keys = ["TCW9", "TESTCOVER9"];
object[] values = ["True", "This Legal Condition “Some Important Text” Rest of the details."];
Document document = new("C:\\temp\\TestTemplateIFDoubleQuotes.docx");

document.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields
               | MailMergeCleanupOptions.RemoveEmptyParagraphs
               | MailMergeCleanupOptions.RemoveUnusedFields
               | MailMergeCleanupOptions.RemoveStaticFields;

document.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
document.MailMerge.Execute(keys, values);
document.Save("C:\\temp\\abc.pdf", SaveFormat.Pdf);
Console.WriteLine("Hello, World!");

public sealed class HandleMergeFieldInsertHtml : IFieldMergingCallback
{
    public void FieldMerging(FieldMergingArgs args)
    {
        DocumentBuilder builder = new(args.Document);
        builder.MoveToMergeField(args.DocumentFieldName);
        string value = Convert.ToString(args.FieldValue) ?? string.Empty;
        builder.InsertHtml(value, true);
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
        throw new NotImplementedException();
    }
}

the ouput file is
abc.pdf (46.3 KB)

Expected output is
expectedOutput.pdf (41.9 KB)

@CTGurpreet1 It is normally is not allowed to use double quotes in IF field values. And the only way to have a double quite in the IF field is using an embedded field like this { QUOTE 34 }. This is MS Word limitation. You can try using IFieldMergingCallback to resolve the problem. But you should wrap true and false values in your IF field into double quotes like in the attached template:
in.docx (14.0 KB)
out.docx (11.4 KB)

Document doc = new Document("C:\\Temp\\in.docx");
doc.MailMerge.UnconditionalMergeFieldsAndRegions = true;
doc.MailMerge.FieldMergingCallback = new QuoteResolver();
doc.MailMerge.Execute(new String[] { "ProdType", "Description1", "Description2" },
        new String[] { "ProdType", "The \"first\" description", "The \"second\" description" });
doc.Save("C:\\temp\\out.docx");
private class QuoteResolver : IFieldMergingCallback
{
    public void FieldMerging(FieldMergingArgs args)
    {
        string fieldValue = (string)args.FieldValue;
        if (!fieldValue.Contains("\""))
            return;

        String[] parts = fieldValue.Split("\"");
        DocumentBuilder builder = new DocumentBuilder(args.Document);
        builder.MoveToField(args.Field, false);
        for (int i = 0; i < parts.Length; i++)
        {
            builder.Write(parts[i]);
            if (i < parts.Length - 1)
                builder.InsertField("QUOTE 34");
        }
        args.Text = "";
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing.
    }
}

I forgot to mention that the values object has html tags

object[] values = ["<b>This Legal Condition “Some Important Text” Rest of the details.</b>"];

Now I tried your suggestion it is inserting the html as a text
abc.pdf (46.3 KB)
I tried builder.insertHTML but so it is inserting it is printing html as text also and output is
abc.pdf (87.8 KB)

Please advise

@CTGurpreet1 You can try modifying the code like this:

Document doc = new Document("C:\\Temp\\in.docx");
doc.MailMerge.UnconditionalMergeFieldsAndRegions = true;
doc.MailMerge.FieldMergingCallback = new QuoteResolver();
doc.MailMerge.Execute(new String[] { "ProdType", "Description1", "Description2" },
        new String[] { "<b>ProdType</b>", "<i>The \"first\" description</i>", "<u>The \"second\" description</u>" });
doc.Save("C:\\temp\\out.docx");
private class QuoteResolver : IFieldMergingCallback
{
    public void FieldMerging(FieldMergingArgs args)
    {
        // Put HTML into a separate document and replace double quotes with { QUOTE 34 } field.
        Document tmp = new Document();
        DocumentBuilder tmpBuilder = new DocumentBuilder(tmp);
        tmpBuilder.InsertHtml((string)args.FieldValue);

        string fieldPlaceholder = "[[QUOTE]]";
        tmp.Range.Replace("\"", fieldPlaceholder);
        foreach (Run r in tmp.GetChildNodes(NodeType.Run, true))
        {
            if (r.Text == fieldPlaceholder)
            {
                tmpBuilder.MoveTo(r);
                tmpBuilder.InsertField("QUOTE 34");
                r.Text = "";
            }
        }

        // Insert the resulting temporary document into the destination document.
        DocumentBuilder builder = new DocumentBuilder(args.Document);
        builder.MoveToField(args.Field, false);
        builder.InsertDocumentInline(tmp, ImportFormatMode.UseDestinationStyles, new ImportFormatOptions());
        args.Text = "";
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing.
    }
}