Dynamically insert an image to word

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

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 https://reference.aspose.com/words/net/aspose.words.mailmerging/imagefieldmergingargs/
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/imagefieldmerging/.

Also there is fully working example in Aspose.Word.Demos, it is available online too https://demos.aspose.com/.

Other discussions related to inserting images:
https://forum.aspose.com/t/130668
https://forum.aspose.com/t/130668