Page 1 of 1

header pic issues

PostPosted: Wed Mar 23, 2011 12:14 am
by suman
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.

Re: Replace text in Header

PostPosted: Wed Mar 23, 2011 11:55 pm
by suman
Hi jason,
I am able to replace header with pic from a template file to text or with another pic into another .docx file. But when i add pic to my header in the generated doc the header has some extra spaces which pushes my data down and another header in the next page along with the remaining data is coming up. can you please resolve me this issue. I dont want to change the format of the docx file.

thanks
Sumathy

Re: header pic issues

PostPosted: Thu Mar 24, 2011 12:05 am
by jason
Hi Sumathy

To get help, you'll need to post the input docx, replacement pic, and your code.

(Unless it is just a simple matter of removing empty paragraphs, or scaling your image. But it sounds like you have a first page header set, or different odd/even headers which you don't want?).

cheers .. Jason