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

Free Support Forum - aspose.com

Mail Merge with Image problem

Hello,

We are using Aspose 9.2.0.0 to perform mail merges.

Sometimes a merge field contains a URL to an image and we need the image to be shown rather than the URL.

You suggested that we need edit the Word template by prefixing merge fields that are to contain images with "image:" . We have done this and the images do appear in the document after the merge.

However if a merge data field contains a URL and its corresponding template document field does not have an "image:" prefix the resulting merged document sometimes shows "System.Byte[]" rather than the actual URL.

Do you have any ideas?

Thanks,

Mike

Hello,

The problem seems to occur when a merge data field occurs twice in a template, one with an image: prefix and without, for example:

URL: «image:URL1»<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

URL Again: «URL1»

After the merge, the URL Again: field becomes URL Again: System.Byte[] rather than showing the URL value.

Hope this helps,

Mike

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I cannot reproduce the problem on my side. I used the following code for testing:

Document doc = new Document(@"Test001\in.doc");

doc.MailMerge.Execute(new string[] { "url" }, new object[] { "http://www.aspose.com/images/aspose-logo.gif" });

doc.Save(@"Test001\out.doc");

My template looks like the following:

Image: «Image:url»

Text: « url»

I used the latest version of Aspose.Words for testing. You can download the latest version from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

If the problem still occurs on your side even with the latest version, please create a simple application, which will allow me to reproduce the problem on my side.

Best regards,

Hi Alexy,

I tried the latest 9.4.0.0 and got the same problem. However I then wrote a simple test harness like the one you used and it worked fine.

In our application I had incorporated some code which I think you or one of your colleagues suggested. It involved looking for fields prefixed with image: and then reading in the image file to a byte[]. An event handler then used the byte[] in the merge, i.e.,

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)

{

MemoryStream imageStream = new MemoryStream((byte[])e.FieldValue);

e.ImageStream = imageStream;

}

When I took out all this it worked OK - presumably 9.4 has fixed whatever necessitated this?

Thanks,

Mike

Hi Mike,

I don't think there is any problem with the fields as my colleagues were unable to reproduce the issue. You may find that your URL field in your template has not been changed properly and the field code (can be viewed by pressing ALT+F9 in MS Word) still has the Image: tag which may be the cause of the issue.

If you are able to attach your template and code here we will be glad to take a closer look for you.

Thanks,