Hi,
I am also trying to replace picture with text from the template to the generated docx file. i am able to replace the text in the header but for the image say textbox with a text its not happening.
WordprocessingMLPackage template=WordprocessingMLPackage.load(new File("c:\\Sample.docx"));
RelationshipsPart rp = template.getMainDocumentPart().getRelationshipsPart();
Relationship relationship = rp.getRelationshipByType(Namespaces.HEADER);
org.docx4j.openpackaging.parts.Part p = rp.getPart(relationship);
Hdr header1 =((HeaderPart)p).getJaxbElement();
List<Object> paragraphs = (List<Object>) header1.getEGBlockLevelElts();
for(Object paragraph:paragraphs)
{
List<Object> paracontent=((P)paragraph).getParagraphContent();
for(Object run:paracontent)
{
List<Object> runcontent =((R)run).getRunContent();
for(Object runcontent1:runcontent)
{
//Set the new text value to the JAXBElement.
Text text = new Text();
text.setValue("hi");
((JAXBElement)run2).setValue(text);
}
}
}
Question is how to replace text box or any image with only text. I am able to get the Pict object and updating the JAXBelement with the text value but in the generated .docx file the text box dissappers but the text is not shown. Can you please help me out.