INCLUDEPICTURE width MERGEFIELD

Hello,

Is any way to use INCLUDEPICTURE width MERGEFILED like :

{ INCLUDEPICTURE “{ MERGEFIELD AVATAR}” \d }

Simple users of the application will create their own templates using INCLUDEPICTURE (with own demnsions for each image).

The idea is to merge the image respecting demensions put into the template.

I already try to use simple mergefield “Image:” (and i got the image in merged document) but it is a bit complicated for simple users

Thanks for your help

Hi,

Yes, you can do that. Check attached template as an example. Image dimensions set in the template will not be disturbed in output file. Do no forget to call Document.updateFields() after executing mail merge.

Best Regards,

Hi,

Tanks for your help. I’m using this template (template-avatar.docx).

Can I use stream instead of image path file?

What about java code, it’s the same like :

document.getMailMerge().execute(fields, values);
document.save(dstStream, SaveFormat.DOCX);

Or there is somthing specific to INCLUDEPICTURE?

When we use Document.updateFields() ?

Thanks.

Hi,

Yes, Java code is same. You can find this code at http://www.aspose.com/docs/display/wordsjava/How+to++Execute+Simple+Mail+Merge

As far as loading image from stream is concerned, you should use merge field in that case. If you want to use INCLUDEPICTURE in any case, then you will have to pass file name as this is a limitation imposed by MS Word.

Best Regards,

Hi,


Thanks for your inquiry. First off, please see attached modified template document. Secondly, please try using the following code:
LoadOptions options = new LoadOptions();
options.setLoadFormat(LoadFormat.DOCX);
options.setPreserveIncludePictureField(true);

Document doc = new Document(getMyDir() + “template-avatar.docx”, options);

doc.getMailMerge().execute(new String[]{“AVATAR”}, new Object[]{“D:\\temp\\aspose.words.jpg”});

doc.save(getMyDir() + “15.7.0.docx”);

In this case, you don’t need to explicitly call Document.UpdateFields method because MailMerge.Execute method internally calls it.

I hope, this helps.

Best regards,

Hello,

As include picture can’t use byte[] (word limitation), I think to stock picture in a shared directory and reference the full path of each image. (Also I must replace “” by “\\” :s )

Thanks for your Help.

Hi,


It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,