Page 1 of 1

using docx4j w/ word 2003 merge fields

PostPosted: Thu Apr 07, 2011 1:23 am
by sledwich
Hi,

Reading through your posts - I just wanted to put down my experiences and feeling on this subject. I am currently using docx4j but only at a fairly basic level to extract and recompile the docx file.

We need a system for mail merge with the data coming from our package and need to perform the mail merge server side to improve performance. Currently we take the docx on the client side and use docx4j to strip out the document.xml and send this to the server, there we perform a straight search and replace on a series of SET fields in the document then reassemble the document and update bookmarks in the document.

At present it works very quickly thanks to the fast processing on the server side but we have hit a complete blocker in that this does not work for multi line merge fields. For example if we want to merge an address where we have:

1 High Street,
London
WM1 1ES


This shows as a single line and prints the carriage return and line feed characters as visible characters in a single line.


I see you talking about docx4j's data binding facilities and wonder if you have experienced a similar problem, also I like the sound of being able to bind the fields and scrip the bookmars all together as this would simply things a lot. Thanks for any help/comments.

PS when I talk about server side - our java app connects to a jboss server for application server processing - connected to a mysql database.

Re: using docx4j w/ word 2003 merge fields

PostPosted: Thu Apr 07, 2011 1:37 am
by jason
Without looking into it a bit, I'm not sure how best to deal with multi line merge fields. I guess you'd look for CR/LF, and if found, replace the single field with one for each line.

I can tell you the databinding stuff (svn head at least, if not 2.6.0) works with multiline data (w:sdtPr/w:text/@w:multiLine). See BindingHandler.xpathGenerateRuns for how this is done (much as suggested above).

Re: using docx4j w/ word 2003 merge fields

PostPosted: Thu Apr 07, 2011 10:21 pm
by sledwich
Thanks for your reply Jason,

Is there anywhere I can look at an example of going the data binding route as this sounds quite interesting. Is it possible to use this server side (ie, without ms-word present?

thanks

Re: using docx4j w/ word 2003 merge fields

PostPosted: Thu Apr 07, 2011 11:00 pm
by jason
Sure, it works without Word present.

See the 2 samples org/docx4j/samples/CustomXmlBinding.java and org/docx4j/samples/ContentControlBindingExtensions.java, and the documents in the sample-docs databinding directory.

Or for a working demo, http://www.fabdocx.com