Page 1 of 1

Replace text with image

PostPosted: Fri Aug 05, 2011 1:39 am
by swistakk
Hello Everyone,

I am new to docx4j, however I created some tests and I find it very useful.
I can not figure it out how to replace text in document with image from file:/

I am able to instert picture to the end of doc with: wordPackage.getMainDocumentPart().addObject(p).
I know how to replace text for other text using JAXBElement.
I also know how to replace image with other image using wordPackage.getParts() and then comparing name of PartName

Could someone please help me with replacing text with image or just help to insert picture to desired part of document?

Thanks in advance!

Re: Replace text with image

PostPosted: Fri Aug 05, 2011 7:58 pm
by tosswang
hi,swistakk:

i replaced text with ole a few days ago,I think that is the same approach to achieve replacing text with image.
docx-java-f6/document-occur-error-when-i-insert-more-than-one-ole-t802.html.

i hope it is useful to you.

i'm chinese.please pardon my poor english level. :D

tosswang

Re: Replace text with image

PostPosted: Sat Aug 06, 2011 3:28 am
by swistakk
Hello tosswang,

thanks a lot for you reply:) It works fine for me:)
I will test it more on the begining of next week and in case of any trubles I will let you know.

p.s. Your english is very good:)

Re: Replace text with image

PostPosted: Mon Aug 08, 2011 10:06 pm
by tosswang
hi,swistakk:
I am new to docx4j too,can you tell me how to replace image with other image?

thanks in advance!

tosswang

Re: Replace text with image

PostPosted: Wed Aug 10, 2011 12:33 am
by swistakk
Hello tosswang,

Look at this example:
http://kooroth.blogspot.com/2011/06/cha ... ocx4j.html

All should be clear after reading it:)

Re: Replace text with image

PostPosted: Fri Aug 12, 2011 6:04 am
by sanjeevkoppal
I have a scenario in which the doc is created from HTML using altChunk and AlternativeFormatInputPart.
I cannot use the xpath approach as this html is not from doc4jx generated doc.
I use the servlet reponse (basically html) to convert to doc using AlternativeFormatInputPart. save the file and load it again, but the xml generated doesn't have a way to navigate to the path i want to.

Any help highly appreciated...

Re: Replace text with image

PostPosted: Fri Sep 09, 2011 2:47 am
by swistakk
hi,swistakk:

i replaced text with ole a few days ago,I think that is the same approach to achieve replacing text with image.
docx-java-f6/document-occur-error-when-i-insert-more-than-one-ole-t802.html.

i hope it is useful to you.

i'm chinese.please pardon my poor english level.

tosswang
tosswang

Posts: 59
Joined: Wed May 18, 2011 8:04 pm


I have another issue..:/ Now after inserted images I need to insert one line of text...
My method looks like below:
Code: Select all
P pic1 = createPicture(fileListNew.get(i), word);
P pic2 = createPicture(fileListNew.get(i+1), word);
mainDocPart.getContent().add(index+i, pic1);
mainDocPart.getContent().add(index+i+1, pic2);


when I use:
Code: Select all
Text t = new Text();
t.setValue("test Text");
mainDocPart.getContent().add(index+i+2, sample);
'

It doesn't give me error however I can't open result docx file.

Does anyone have any ideas????
Thanks in advance:)

Re: Replace text with image

PostPosted: Fri Sep 09, 2011 2:49 am
by swistakk
Ups sorry I made mistake... Code should be like below. Result is of corse still the same:/

Code: Select all
Text t = new Text();
t.setValue("test Text");
mainDocPart.getContent().add(index+i+2, t);
'