Free Support Forum - aspose.cloud

Merging images from Aspose storage into word document

Hi There,


Hoping someone can help. We’re having issues merging an image from the Aspose storage into a word document.

We’re currently using the technique described here:
http://www.aspose.com/docs/display/wordscloud/Execute+Mail+Merge+Template

At the bottom of that screen, it indicates that it should be possible to merge XML with images and gives the structure for the XML. It doesn’t however seem to work, or provide examples of how the merge field should be placed into the word document.

We can merge the data using this method, but not the image.

Any help would be greatly appreciated.

Many thanks

Hi there,

Thanks for your inquiry. I have tested the scenario and have not found any issue while using executeTemplate. Please check the following xml. The image file should be in folder1 at storage. Please upload the image file at storage and Execute Mail Merge Template.


<?xml version="1.0" encoding="utf-8"?>

<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

This is the first caption !!!

folder1\image1.jpg

This is the second caption !!!

folder1\image2.jpg



I suggest you please download the Aspose Cloud SDK and use following code example to check the executeTemplate. I have attached the intput/output and xml file with this post for your kind reference. Hope this helps you. Please let us know if you have any more queries.


try

{

string inputFile = @"C:\temp\TestExecuteTemplate.doc";

string xml = null;

using (System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\TestOrders.xml"))

{

xml = sr.ReadToEnd();

}

Aspose.Cloud.Storage.Folder folder = new Aspose.Cloud.Storage.Folder();

folder.UploadFile(inputFile, "");

string fileName = Path.GetFileName(inputFile);

Aspose.Cloud.Words.MailMerge mailMerge = new Aspose.Cloud.Words.MailMerge();

mailMerge.ExecuteTemplate(fileName, xml, SaveFormat.Docx, "c:\\temp\\Output.docx");

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

Console.ReadLine();

}

Hi,


Thanks for the reply. We’ve already had this information from another support staff member and are still having issues.

What we require (as asked for in the post) is an example of the word template merge field that is required using the above method. So exactly how should the merge field be formatted in the word document.

Our current word doc has the following fields in it:

{{#foreach Item}}<o:p></o:p>

{{Caption}}

{{Img}}

{{/foreach Item}}

And at the moment, it's just printing the name of the image in the document. There is obviously something I'm missing to get the word document to render the image.

Thanks

Dan

Hi Dan,

Thanks for your inquiry. Please check the input document in my previous post.

Please specify a field name prefix like Image:MyFieldName in the document to be able to directly merge images during Mail Merge. Please check the image merge field as shown below:

{{#foreach Item}}

{{Caption}}

{{Image:img}}

{{/foreach Item}}