Introduction I have uploaded a sample Word document with all this done. It can be found in the DocxImages\DocxImages\SampleTemplate folder. Implementation Details The source code of the whole process is uploaded with this article. Put the sample template document and the sample image in the bin/debug folder of the program, and execute it.
This article is about the details of adding an image to a Word document programmatically.
Background
Let us assume a sample document which contains an image placeholder with some tag value. For those who know how to add an image placeholder to a Word document, they can skip the next portion, and directly look at the implementation details.
How to Add an Image Placeholder to a Word Document
This will open up the window "Content Control Properties".ImagePlaceHolder1.
We now have a document with an image placeholder.
Now this is just a place holder. Our requirement is to embed an image (of our choice) at run time to this place holder. The remaining part of the article deals with this issue.
Embedding an Image to a Placeholder on the Fly
Now we have the template Word document. Assume that we have an image file already. For the sake of simplicity, I am assuming a static image file which is already available with me. In real time scenarios, it can be dynamically created images like charts, etc.
I have placed both the template and the sample image in the programs bin/debug folder.
Before going into the implementation details, let me give you some fundamentals.
With what is said above, embedding an image on the fly is a very easy process. It can be summarized in three points:
XPathNodeIterator
Loading

Join the conversation! Your thoughts help the community grow.