Page 1 of 1

How to add pictures in different parts of a document?

PostPosted: Mon Dec 28, 2015 11:33 pm
by PUE
Hi there.

Thanks for docx4j, I'm using it for a simple program so far and it work well.
Now it is time for slightly more complex program and a third project is in the pipeline.

The existing program was rather simple as I simply appended pictures and other content to the end of a template (actually a regular .docx).
For the second one I need to add pictures at various places inside a template document.
I already have the code to process the pictures and create paragraphs that contain pictures.

What is the sanest way to add those paragraphs to the various places inside the document?

Edit:
To elaborate further:
Simple text markers would be desirable because this would allow users to create the template file.
On the other hand they may or may not be a problem because simple replacing a marker with a picture will not be sufficient. The reason is that any given marker will be replaced by an arbitrary number of images.
Effectively I need something like the method that appends at the end of the document, except that it appends an arbitrary number of images at an arbitrary position within the document.

Re: How to add pictures in different parts of a document?

PostPosted: Thu Jan 07, 2016 5:48 pm
by jason
Well, adding a paragraph at a particular point in the main document part comes down to inserting at a particular position in the content list, which is straightforward.

If you want to insert at a position marked by a user, then the first step is to find that position...

There are a couple of alternative approaches you could consider:

1. content control data binding. You can XPath bind a content control to a base64 encoded picture. So, at authoring time, your user inserts the content control using an authoring tool. Then at runtime, you inject an XML data file containing the encoded pictures.

2. docx4j has simple text variable replacement. You could extend that to replace text with image.

Re: How to add pictures in different parts of a document?

PostPosted: Tue Jun 26, 2018 7:03 am
by Saranya
Hi Jason,

How can i extent text replace with an image inside existing pptx file. Could you please post an sample code here?
Say, text {Green} with green.gif inside PPT. Please help me out!

POsted same:https://www.docx4java.org/forums/pptx-java-f14/how-to-add-replace-image-in-an-existing-pptx-file-t2705.html#p9353

With Regards,
Saranya