Free Support Forum - aspose.com

INCLUDEPICTURE associated with a MERGEFIELD

Hello,

I have a Word 2007 template (saved in Word 2003 format - .doc) on which I am trying to combine an INCLUDEPICTURE field with a MERGEFIELD. The objective of this is to include a relevent map in a letter depending on the content of a merge data field, e.g.,

{INCLUDEPICTURE
“{IF TRUE “C:\Maps\{MERGEFIELD MapName}.jpg”}” \d }



It appears that this nested approach does not work with Aspose. The MERGEFIELD command works but the INCLUDEPICTURE does not.

I have been told that … <!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}

<![endif]–><span style=“font-size: 12pt; font-family: “Times New Roman”,“serif”;”>Aspose.Words does support INCLUDEPICTURE fields but since
they are converted to a shape upon merging the reference to a textbox inside
the merge field is lost.


Could you give me an example of what I would have to do in code to make the map appear in the letter?

Thanks,
Mike

Hi Mike,

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

Thank you for reporting this problem to us. I managed to reproduce it on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

The problem occurs because fields nested into INCLUDEPICTURE field are broken upon loading.

Maybe as a workaround, you can try inserting embedded images upon mail merge. Please follow the link to learn how to achieve this:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-insert-images-from-a-database.html

Best regards,

I am trying the workaround that you suggested in:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-insert-images-from-a-database.html

I have a problem with this line:

doc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob();

The FieldMergingCallback property is not in the list of available properties. I am using
v9.1.0.0 of the Aspose.Words.dll.

Does the workaround use a different version of the dll?

Thanks,
Mike



Downloading the 9.2.0.0 dll, I see that there are changes around mail merging in this newer version, leave it with me I’ll see if I code the workaround against 9.2.0.0.

Hi

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

Thanks for your request. Yes, you are right, there were few breaking changes in API starting from 9.2.0 version Aspose.Words. Please let me know if you have any questions, I will be glad to help you.

Best regards,

Hi,

Still having problems …

My Word template has : {IncludePIcture “MERGEFIELD Image:textbox1}”}



The CSV merge data file has the data field: Image:textbox1


After including the suggested workaround code I’m getting “Buffer cannot be null. Paramater name: Buffer” from the line highlighted in red :

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
// The field value is a byte array, just cast it and create a stream on it.
MemoryStream imageStream = new MemoryStream((byte[])e.FieldValue);

// Now the mail merge engine will retrieve the image from the stream.

e.ImageStream = imageStream;
}

At this point e.FieldValue is empty.

Do you have any suggestions?

Thanks,
Mike





Hi Mike,

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

Thanks for your request. You do not need to use INCLUDEPICTURE field. In your template you should just have merge field like the following: { MERGEFIELD Image:textbox1 }

I created simple code and template, which shows how to achieve this:

[Test]

public void Test001()

{

// Open template document.

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

// Add mail merge callback.

doc.MailMerge.FieldMergingCallback = new MailMergeCallback();

// Execute mail merge.

doc.MailMerge.Execute(new string[] { "textbox1" }, new object[] { File.ReadAllBytes(@"C:\Temp\out.jpg") });

// Save output document.

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

}

private class MailMergeCallback : IFieldMergingCallback

{

public void FieldMerging(FieldMergingArgs args)

{

// Do nothing.

}

public void ImageFieldMerging(ImageFieldMergingArgs args)

{

// The field value is a byte array, just cast it and create a stream on it.

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

// Now the mail merge engine will retrieve the image from the stream.

args.ImageStream = imageStream;

}

}

Best regards,

Hi there,

The issue maybe occuring because name of the datafield in your CSV file is "Image:textbox1", it should just be "textbox1".

Thanks,

Hi,

Thanks for explaining what I needed to do.

I have now managed to use the suggested code and get the mail merge to work.

However it only works with very small images. I tried a 247Kb image, no errors were generated but when I tried to open the merged document (.doc) in Word 2007 I get “There is not enough memory or disk space to display or print the picture”.

My guess is that this is because the image is corrupt.

I found an old thread with a similar problem, which had been fixed:

http://www.aspose.com/community/forums/thread/93954/there-is-not-enough-memory-or-disk-space-to-display-or-print-the-picture-error-with-aspose.words-4.4.aspx

Do you have any suggestions?

Thanks,
Mike


Hi Mike,

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

Thanks for your inquiry. Could you please attach your template, image and output document here for testing? I will check the issue and provide you more information.

Best regards.

Hi Alexey,

Files attached as requested.

Mike

Hi Mike,

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

Thanks for your request. But I cannot see the image file you have attached. Could you please reattach it here in the forum?

Best regards,

Hi Alexy,

OK, tried again, hopefully the image is attached this time.

I have tried a few images, teh only one that worked was very small - 4Kb.

Thanks,
Mike

Hi

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

Thank you for additional information. It seems this image is broken; I cannot open the files you have attached. But I have tried with images with different size, and I cannot reproduce the problem.

Best regards,

Hello Andrey,

Thank you for trying to reproduce the problem, I am pleased to hear that you have been able to mailmerge merge large images.

I will get one of my colleagues to try and see how they get on.

Thanks,
Mike



Thank you. We will wait for your result.

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

Best regards,

Alexey,

Do you know when a fix will be available to this problem? If it is soon we will wait for the fix rather than coding a workaround for our customers.

Thanks,
Mike

Hi

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

Thanks for your inquiry. Currently I cannot provide you any reliable estimate regarding this issue. You will be notified as soon as it is resolved.

Best regards,

Hi Mike,

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

Thanks for your inquiry. The issue is not scheduled yet, so I cannot provide you any reliable estimate at the moment.

I would like to add that even MS Word cannot insert the images you attached. So I suppose even if you insert them into MS Word document using INCLUDEPICTURE field, MS Word will not display them.

Best regards.

Hi,

Thank you for your reply, I am sorry that the images I sent did not work.

I have tried using ImportPicture directly in Word:

{IMPORTPICTURE “c:\Toshiba0800x0600.bmp” * MERGEFORMAT}


This does import the picture successfully so there is nothing wrong with the image and large size images do work.

I have also experimented with mail merging images of different sizes using Aspose and found that images larger than around 300Kb produce the memory error problem.

So there is a difference between the results I get when doing an Aspose merge and the results you get. Maybe it is due to the patch level in software or the memory available on the PC?

I am using Microsoft Office Ultimate Word 2007 (12.0.6525.1000) SP2 for my templates.

Can you please tell me how large the images that you have successfully mail merged are and whether you have any other suggestions that I could try?

We have a customer who makes extensive use of merging images so this is a big problem to us.

Thanks,
Mike