Page 1 of 1

how to replace words with pictures in word07

PostPosted: Fri May 20, 2011 7:49 pm
by tosswang
hi,jason

i want to replace words with pictures in word07 and look for docx4j api,but i can't find solution,how can i do?
i spend much time on the issue, please help me .
thanks in advance
tosswang

Re: how to replace words with pictures in word07

PostPosted: Fri May 20, 2011 8:49 pm
by jason
data-binding-java-f16/binding-an-image-to-a-picture-element-t561.html is a good way.

If you don't want to use content controls, then you search for your words, and do something like AddImage sample to add the image.

Re: how to replace words with pictures in word07

PostPosted: Fri May 20, 2011 10:31 pm
by tosswang
jason wrote:http://dev.plutext.org/forums/data-binding-java-f16/binding-an-image-to-a-picture-element-t561.html is a good way.

If you don't want to use content controls, then you search for your words, and do something like AddImage sample to add the image.


oh,jason ,can you tell me how to search and delete word word that i wanted via api of docx4j,please forgive me,i use docx4j for the first time,

i'm not familiar with apis……

thanks in advance

tosswang

Re: how to replace words with pictures in word07

PostPosted: Sat May 21, 2011 2:47 am
by tinne
Kindly read about sdt images here ISO Standard 29500, Part I, chapters M.1 and 17.5.2.

In order to work with docx4j, you most of all need an understanding of JAXB-code, cf. eg. http://jaxb.java.net/tutorial/.

In case there are any questions left, please come back and ask (more specifically).

Re: how to replace words with pictures in word07

PostPosted: Mon May 23, 2011 7:31 pm
by tosswang
tinne wrote:Kindly read about sdt images here ISO Standard 29500, Part I, chapters M.1 and 17.5.2.

In order to work with docx4j, you most of all need an understanding of JAXB-code, cf. eg. http://jaxb.java.net/tutorial/.

In case there are any questions left, please come back and ask (more specifically).


thanks tinne,i will study jaxb's tutorial

Re: how to replace words with pictures in word07

PostPosted: Mon May 23, 2011 7:40 pm
by jason
As tinne suggests, you need to understand a bit about JAXB.

Then you'll be able to traverse the main document part, and looking at the org.docx4j.wml.Text objects

docx4j provides a couple of ways to help you to find the text you are looking for. (This is in the current English Getting Started guide; maybe not in the old Chinese translation.)

XPath

you can do use XPath to select JAXB nodes:
Code: Select all
   MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   String xpath = "//w:p";      
   List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, false);


These JAXB nodes are live, in the sense that if you change them, your document changes.
There is a limitation however: the xpath expressions are evaluated against the XML document as it was when first opened in docx4j. You can update the associated XML document once only, by passing true into getJAXBNodesViaXPath. Updating it again (with current JAXB 2.1.x or 2.2.x) will cause an error.

TraversalUtil

TraversalUtil is a general approach for traversing the JAXB object tree in the main document part. It can also be applied to headers, footers etc. TraversalUtil has an interface Callback, which you use to specify how you want to traverse the nodes, and what you want to do to them.

Re: how to replace words with pictures in word07

PostPosted: Mon May 23, 2011 9:59 pm
by tosswang
jason wrote:As tinne suggests, you need to understand a bit about JAXB.

Then you'll be able to traverse the main document part, and looking at the org.docx4j.wml.Text objects

docx4j provides a couple of ways to help you to find the text you are looking for. (This is in the current English Getting Started guide; maybe not in the old Chinese translation.)

XPath

you can do use XPath to select JAXB nodes:
Code: Select all
   MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   String xpath = "//w:p";      
   List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, false);


These JAXB nodes are live, in the sense that if you change them, your document changes.
There is a limitation however: the xpath expressions are evaluated against the XML document as it was when first opened in docx4j. You can update the associated XML document once only, by passing true into getJAXBNodesViaXPath. Updating it again (with current JAXB 2.1.x or 2.2.x) will cause an error.

TraversalUtil

TraversalUtil is a general approach for traversing the JAXB object tree in the main document part. It can also be applied to headers, footers etc. TraversalUtil has an interface Callback, which you use to specify how you want to traverse the nodes, and what you want to do to them.


thanks jason,i will study jaxb