My problem is two-fold. For one, my Word template contains many repeat controls, including nested ones, and apparently when applyBindings() is called only the first element's data is used in each iteration. Secondly, the template includes picture content controls, and applyBindings() leads to the Base64 encoding to appear as text rather than a picture in the output.
One thing that seems peculiar in my case is that the custom XML part isn't populated in the template. All the XPaths I define don't actually exist until my application dynamically generates the XML and saves it in the custom XML part. Here is the code that is executed at this point:
- Code: Select all
OpenDoPEHandler odh = new OpenDoPEHandler(wmlPackage);
odh.preprocess();
OpenDoPEIntegrity odi = new OpenDoPEIntegrity();
odi.process(wmlPackage);
// Apply the bindings
BindingHandler.applyBindings(wmlPackage.getMainDocumentPart());
// Remove controls and leave the contents
RemovalHandler rh = new RemovalHandler();
rh.removeSDTs(wmlPackage, Quantifier.ALL);
wmlPackage.save(new File(docxFilePath));
As I said above, the XPaths in the template don't point to any existing data, which means I don't get any CTDataBinding elements in document.xml; instead this is what a picture content control looks like:
- Code: Select all
<w:sdt>
<w:sdtPr>
<w:tag w:val="od:xpath=orgChartDiagram"/>
<w:id w:val="1900247006"/>
<w:showingPlcHdr/>
<w:picture/>
</w:sdtPr>
<w:sdtContent>
<w:p w:rsidR="00837201" w:rsidRDefault="00D873A9">
<w:r>
<w:rPr>
<w:noProof/>
</w:rPr>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="1905000" cy="1905000"/>
<wp:effectExtent l="0" t="0" r="0" b="0"/>
<wp:docPr id="3" name="Picture 3"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks noChangeAspect="1"/>
</wp:cNvGraphicFramePr>
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic>
<pic:nvPicPr>
<pic:cNvPr id="0" name="Picture 3"/>
<pic:cNvPicPr>
<a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
</pic:cNvPicPr>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId9">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi val="0"/>
</a:ext>
</a:extLst>
</a:blip>
<a:srcRect/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="1905000" cy="1905000"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln>
<a:noFill/>
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
Another important detail is the fact that I put the Base64 image content directly in the XML before it is saved in the package, which means I'm not using any calls to setNodeValueAtXPath(). I don't see how this would cause the binding to show up as text instead of the actual image, but maybe it is the cause here? I must admit I have tried taking the output document (which still contained the custom XML part) and binding a brand new picture content control to an existing XPath containing the Base64 image, but the picture doesn't show up, only a web-like missing image message saying "This image cannot currently be displayed."
Note that I'm using Docx4Java 2.7.1 and I created the template using the Word Add-In.
Many thanks for any support you may provide.
-Olivier