Page 1 of 1

Inserting line breaks into MergeFields

PostPosted: Thu Jul 18, 2013 3:22 am
by northerner
I am successfully using org.docx4j.model.fields.merge.MailMerger.getConsolidatedResultCrude to replace MergeFields in my docx document.
My problem is that there are times when I need to append or prepend a newline (line break) to the MergeField.

I tried various hacks like "\r\n" and "<br/" and "<w:br/>", none of which worked of course.

Any idea of what I can do here?

Re: Inserting line breaks into MergeFields

PostPosted: Thu Jul 18, 2013 7:43 am
by jason
Now that you mention it, this ought to be possible, by creating a field result such as:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                    <w:r>
                        <w:fldChar w:fldCharType="separate"/>
                        <w:t>«Line 1</w:t>
                        <w:br/>
                        <w:t>Line 2»</w:t>
                        <w:fldChar w:fldCharType="end"/>
                    </w:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Sounds like the code may need to be enhanced to convert \n into a w:br.

I've created https://github.com/plutext/docx4j/issues/75 to track this

Re: Inserting line breaks into MergeFields

PostPosted: Sat Jul 27, 2013 10:50 am
by jason