I am trying to merge text changes into headers/footers of a docx document (using version 3.3.0 of docx4j). Here is a code snippet where I am doing this:
- Code: Select all
RelationshipsPart rp = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
org.docx4j.relationships.Relationship hdrRelationship = rp.getRelationshipByType(Namespaces.HEADER);
HeaderPart hdrPart = (HeaderPart)rp.getPart(hdrRelationship);
HeaderPart newHdrPart = new HeaderPart();
newHdrPart.setContents(XmlUtils.deepCopy(hdrPart.getContents()));
wordMLPackage.getMainDocumentPart().addTargetPart(newHdrPart, RelationshipsPart.AddPartBehaviour.RENAME_IF_NAME_EXISTS);
content = newHdrPart.getContent();
mergeMSWordDocContentViaDocX4J(wordMLPackage, content, replacementMap);
The call to mergMSWordDocContentViaDocX4J() method is something that I created that just walks through the paragraphs/runs searching for text ...