Categories > OpenTBS with DOCX >

Preserve Whitespace

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Chris
Date: 2013-12-17
Time: 12:28

Preserve Whitespace

I've had some issues preserving whitespace in a docx merge, after modifying the XML as shown in the SO question below.

http://stackoverflow.com/q/20614608/1768779

My problem was, whilst I could add "xml:space="preserve"" to the tags I was adding, the open tags I was manually closing were losing their white space. I first tried strconv=no+wsp, however this didn't help.

I decided to look into the code base, to see if I could locate where tags were added, to force xml:space="preserve" onto them all. Instead I found the method MsWord_CleanSpacePreserve($Txt), which as far as I can tell, is completely unused. I added a call to it in MsWord_RenumDocPr(), which solved my whitespace problems perfectly.

What makes me nervous now, is why is this code unused, when I can find no reference to using it externally? Are there any negative side effects I should expect, or have I missed how I should be calling it more nicely, from outside the class?

Cheers for your help, as always!
By: Skrol29
Date: 2013-12-17
Time: 23:59

Re: Preserve Whitespace

Hi Chris,

I was hesitating to lead on this feature because the tip used is undocumented.
It consists in adding attribute xml:space="preserve" on the entity <w/document> instead of each <w:t> elements.
Thats actually works on Ms Word 2007, 2010, 2013 and LibreOffice (which in fact does ignore xml:space="preserve").
I found it on a forum and I cannot find any documentation about it.

By: Chris
Date: 2013-12-18
Time: 10:08

Re: Preserve Whitespace

Ah, ok, great to know! In that case, I'll keep it in on my own implementation, as I'm struggling to find any other workaround (and have no time to!) - and be sure to let you know of any issues I come across!

Cheers,
Chris