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

Free Support Forum - aspose.com

Merge Image

I am evaluating your product for my needs and had a question about merging an image. I noticed from the tutorials I must add the prefix ‘Image:’ to my merge fields for images. My image is displayed when I execute the mail merge, but the field name also remains on the document. Why is this? I suspect it isn’t matching the name from my source and therefore is ignoring that MergeField. What can I do make the image display while still removing the MergeField?

Here is my section of code:

Dim doc As New Document(_settings.ReportPath & "\MAIN AND SERVICE LINE INSPECTION # 1.doc")

_dbase.Query = "Select * from Form" & Mid(ComboBox1.SelectedValue.ToString, 1, 8) & " where dtaID = ‘" & lstForms.SelectedValue.ToString & "’"
Dim CurRow As DataRow = _dbase.ExecuteSql(Dbase.AccType.Row)

' Set up the event handler for image fields.
doc.MailMerge.FieldMergingCallback = New HandleMergeImageFieldFromBlob()

This message was posted using Page2Forum from How-to: Insert Images from a Database - Aspose.Words for .NET

Hi Jacob,

Thanks for your inquiry.

Can you please attach your template here for testing as well? We will take a closer look into this issue for you.


Thanks. Here is my template. Many of my fields aren’t added yet, however the last field (Inspector Signature) is an image we store in a sql database.


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 10.8.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for inconvenience.

Best Regards,

I figured out a workaround. I use a textbox to display the image as discussed in the following article: https://docs.aspose.com/words/net/working-with-images/

If I insert the image using the DocumentBuilder class function ‘InsertImage’ as is done in this article, the field name does not show and I still get the results I need.


Thanks for your feedback. It is perfect that you managed to achieve what you were looking for; however, I can offer you another simple work around as follows :

private class HandleMergeImageFieldFromBlob : IFieldMergingCallback
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    { }
    public void ImageFieldMerging(ImageFieldMergingArgs args)
        if (args.FieldName.Equals("imgField"))
            DocumentBuilder builder = new DocumentBuilder(args.Document);
            builder.MoveToMergeField("imgField ");

            MemoryStream stream = new MemoryStream();
            using (Image img = Image.FromFile(@"c:\test\Chrysanthemum.jpg"))
                img.Save(stream, ImageFormat.Jpeg);


I hope, this will help.

Best Regards,

The issues you have found earlier (filed as WORDSNET-5747) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.