Page 1 of 1

Bookmarks and text with newline not showing

PostPosted: Thu Oct 02, 2014 5:02 am
by todd
I have a Docx4j Word Template using bookmarks to populate text when generating the document.
One of the bookmark fields is loaded with text that has new lines /r/n in the string which is supposed to print as new lines.
example:
<w:bookmarkStart w:name="distributionText_1" w:id="31" />
<w:r>
<w:t>cc: This is line 1 This is line 2 with more This is line 3</w:t>
</w:r>
<w:bookmarkEnd w:id="31" />

I can see the /r/n in the string (debug) but prints as;
cc: This is line 1 This is line 2 with more This is line 3

I want it to print as;
cc:
This is Line 1
This is Line 2
This is Line 3

It appears I need to convert the /r/n to a /b in the xml but not sure how to do this.
Code snippet of code I'm using to add to bookmark.
// now add a run
org.docx4j.wml.R run = wmlObjFactory.createR();
if (bmp.getrPr() != null)
run.setRPr(bmp.getrPr());
org.docx4j.wml.Text t = wmlObjFactory.createText();
run.getContent().add(t);
t.setValue(value);

Any code samples for this conversion?
Thanks
Todd

Re: Bookmarks and text with newline not showing

PostPosted: Thu Oct 02, 2014 8:31 am
by jason
Hi Todd, you need to create w:br elements; your resulting XML can look like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:r>
        <w:t>cc:</w:t>
        <w:br/>
        <w:t>This is line 1</w:t>
        <w:br/>
        <w:t>This is line 2 with more</w:t>
        <w:br/>
        <w:t>This is line 3</w:t>
    </w:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Use:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    Br br = wmlObjectFactory.createBr();
    run.getContent().add( br);
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4

Re: Bookmarks and text with newline not showing

PostPosted: Fri Oct 03, 2014 9:30 am
by todd
Thanks Jason,
That is what I needed and was able to get things to work.