// We want to save images as they're created, so define our saver
File baseDir = new File(System.getProperty("user.dir") + "/OUT_unzipped");
baseDir.mkdir(); // TODO: directory should be empty, since old images won't get overwritten
UnzippedPartStore ups = new UnzippedPartStore(baseDir);
Save saver = new Save(wordMLPackage, ups);
// Apply the bindings
// if (hyperlinkStyle!=null) {
// BindingHandler.getHyperlinkResolver().setHyperlinkStyle(hyperlinkStyle);
// }
BindingHandler bh = new BindingHandler(wordMLPackage);
bh.applyBindings(wordMLPackage.getMainDocumentPart());
// If you inspect the output, you should see your data in 2 places:
// 1. the custom xml part
// 2. (more importantly) the main document part
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
);
// Strip content controls
// RemovalHandler rh = new RemovalHandler(); // NB: this only removes if OpenDoPE tags are present (they aren't in binding-simple.docx)
//wordMLPackage.save(new java.io.File(outputfilepath) );
saver.save(null);
// now zip up that dir, and rename to docx.
}