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

Free Support Forum - aspose.com

IMailMergeDataSource - Insert Image/ Value Of Merged Field


I’m using IMailMergeDataSource to produce a mail merge. I use merge fields in a word document.

Everything is working fine except I need to be able to add an image to the word document.

I have a space in the word document to display an image. The image is not saved in the database.

Is it possible to add an image to the word document using IMailMergeDataSource?

Also is it possible to get a value of a merged field?

Thanks in advance

Hi Roslyn,

Thanks for your inquiry. I have attached a template Word document that contains a sample Image MERGEFIELD here for your reference. You can implement IFieldMergingCallback interface, get the value of MERGEFIELD and add an image by placing/running the following code inside IFieldMergingCallback.ImageFieldMerging event:

private class HandleImageMergeField : IFieldMergingCallback
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
        // Do nothing.
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
        e.ImageFileName = e.FieldValue.ToString();

I hope, this helps.

Best regards,