Page 1 of 1

Text substitution resulting in trailing space

PostPosted: Tue Oct 23, 2012 12:55 am
by Robb2012
Hi everyone,
I am performing text substitution, by replacing existing text with new text. While doing so i am deleting existing text completely from a text run. This results into the text run ending with a space, example : <w:t>This is </w:t>
After the word "is" there is a space which does not get displayed in the resulting docx.
When i manually add the property, xml:space="preserve" to this text run, the space gets displayed.
How do i preserve this (leading or trailing) space using docx4j after substitution? How do i add the xml:space="preserve" property programmatically to the text run?

Thanks.

Re: Text substitution resulting in trailing space

PostPosted: Tue Oct 23, 2012 3:56 am
by jason
org.docx4j.wml.Text, which represents w:t, contains:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    /**
     * Sets the value of the space property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */

    public void setSpace(String value) {
        this.space = value;
    }
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


so once you have a reference to that object, the rest is easy...

Re: Text substitution resulting in trailing space

PostPosted: Tue Oct 23, 2012 8:22 am
by Robb2012
Hey Jason,
Thank you very much.
It was definitely easy, just set the string value to "preserve".