Sorry I misread your question.
sirvera wrote: What im trying to do is to override a text what is already in the header, I try with unmarshallFromTemplate and Transverse example but it looks like this does not apply for text within the header or footer.
So you need to get the appropriate header, and then manipulate its contents.
The package has a method getDocumentModel(); you can do something like getDocumentModel().getSections().get(n).getHeaderFooterPolicy().getFirstHeader() to get at the header/footer part you want in section n of the document.
The HeaderPart's jaxbElement is Hdr; your existing text is in List<Object> getEGBlockLevelElts()
From there in its just like manipulating content in the main document part.
sirvera wrote:The second issue I have is that from a Word Template I need to process that and insert different JPG in specific places of the document. Every time I try to add an Image goes always to the end of the document, when I try to change the Image using the Transverse example I get an error.
Well, to insert an image in a specific place in the main document part, you first need to get a reference to that bit of content.
- Code: Select all
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
org.docx4j.wml.Document wmlDocumentEl = documentPart.getJaxbElement();
Body body = wmlDocumentEl.getBody();
List <Object> bodyChildren = body.getEGBlockLevelElts();
If the document contained 6 paragraphs, these would be the 6 items in the list bodyChildren.
So if you are inserting an image in the 3rd paragraph,
- Code: Select all
P p = bodyChildren.item(2)
That and the AddImage sample should be enough to get you started.