I would like to know if it is possible to append a String rtf content to a docx ?
The code I'm currently using replace bookmarks with string and the rtf string I use to replace "DestAdresse3" do not conserve the formatting.
- Code: Select all
Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
map.put( new DataFieldName("DestAdresse1"), "test1");
map.put( new DataFieldName("DestAdresse2"), "test2");
map.put( new DataFieldName("DestAdresse3"), someRtfString);
WordprocessingMLPackage wordMLPackage = Docx4J.load(file);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart.getJaxbElement();
Body body = wmlDocumentEl.getBody();
BookmarksReplaceWithText bti = new BookmarksReplaceWithText();
bti.replaceBookmarkContents(body.getContent(), map);
wordMLPackage.save(new File("D:\\dotx2.dotx"));
Thanks,
Zeko