by jason » Mon Aug 29, 2011 10:39 am
At the highest level, you can choose between 2 approaches.
Approach 1: Do it yourself
On this approach, you search for the keyword, then do the replacement.
You can do the search via TraversalUtil, or via XPath. See Getting Started for more details.
Once you've found the keyword, adding an image is a simple matter (see the AddImage sample).
One problem with this approach is that Word may split your keyword into several elements, making it hard to search for.
Approach 2: Content control binding
On this approach, you use Word to insert a picture content control into your source document, and bind it to a custom xml part. You'll find it easier if you use the OpenDoPE Word Add-In, or the content control toolkit.
At run time, you inject your image into the custom xml part, and then have docx4j resolve the binding (ie place the image into the table). Again, see Gettting Started, and the content control sub-forum, for more on this.
I'd recommend approach 2, since docx4j does most of the work for you, and it supports repeats and conditionals (if you require these).