Dynamically insert an image to word


#1

Is it possible to dynamically insert an image into word from the web, if you know the path of the web.

For example, I have a page using Aspose.Chart which has a datagrid of data and then a chart below. I would like to be able to put this data and the chart into a word document. I know how to get the data into a table in word, but how can I get the image into word?

Thanks,
Joe


#2

Hi Joe,

I think it is better to physically put the image into the Word file. Is it okay with your project? It might also be possible to link the image, but we have not tried that here.

It is possible to insert an image into Word file, you need to create a mail merge field that has name “Image:MyImageFieldName”. This name instructs Aspose.Word to try to insert image into the mail merge field.

The image will automatically be inserted during mail merge if your data source has field MyImageFieldName and that field contains file name or byte array from which an image can be loaded.

To achieve greater control over how the image is inserted, you can provide MailMerge.MergeImageField event handler. Aspose.Word will call your handler and pass you the value of MyImageFieldName and you will be able to do whatever you want (say contact Aspose.Chart and generate the image) and return the image back to Aspose.Word.

For more details please check API documentation http://www.aspose.com/Products/Aspose.Word/Api/Aspose.Word.MergeImageFieldEventArgs.html
http://www.aspose.com/Products/Aspose.Word/Api/Aspose.Word.MailMerge.MergeImageField.html.

Also there is fully working example in Aspose.Word.Demos, it is available online too http://www.aspose.com/Products/Aspose.Word/Demos/Northwind.aspx?index=Employees.

Other discussions related to inserting images:
http://www.aspose.com/forums/ShowPost.aspx?PostID=5474
http://www.aspose.com/forums/ShowPost.aspx?PostID=5277