Question

Thanks to this excellent sample, I'm now familiar with the binding of values at runtime using docx4j from any well built xml file to a word template containing content controls. But I can't find a way to achieve the simular thing to inject a picture in my template.

I've tried to add a picture content control in my template using the Word developper ribbon, and bind it to a value in my xml input, value which is a 64bits encoded string of my picture. But when i'm performing the binding with docx4j, the generated doc file does not contains the picture, instead I get a weird result (see capture).

My binding method look like this :

// Process conditionals and repeats
OpenDoPEHandler odh = new OpenDoPEHandler(_document);
odh.preprocess();

OpenDoPEIntegrity odi = new OpenDoPEIntegrity();
odi.process(_document);

// Apply the bindings
// Convert hyperlinks, using this style
BindingHandler.setHyperlinkStyle("Hyperlink");
BindingHandler.applyBindings(_document);

// Strip content controls: you MUST do this
// if you are processing hyperlinks
RemovalHandler rh = new RemovalHandler();
rh.removeSDTs(_document, Quantifier.ALL);

The result after saving .docx result :

enter image description here

Am I missing something ? Can I find sample to do this properly somewhere ?

Thanks for your help ! CL

PS : I have created an equivalent post on docx4j forums : if a working solution is found there, i will report it here.

Était-ce utile?

La solution

That image is the one embedded in picture-bind.docx, via:

    <w:dataBinding w:xpath="/invoice[1]/items[1]/item[1]/name[1]" w:storeItemID="{3C1B665A-D738-4822-8EFB-14B133235CCB}"/>

You're not successfully altering that binding.

For docx4j / OpenDoPE purposes, I suggest you use the authoring add-in to create your content controls. If that tool detects that you are binding a base64 encoded image, it will create a picture content control automatically.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top