none
How to preserve white spaces in Presentation RRS feed

  • Question

  • I am working on issue that, in my opinion, renders Open XML SDK absolutely useless at least when it comes to working with Presentations. Here is my issue. I have a text box in which text is split to multiple runs.

    Run 1: "Some Text"

    Run 2: "          "

    Run 3: "Some more text"

    If I open this presentation using SDK, make any modification to the slide, and save all spaces in the run 2 disappear. I was trying to figure out if I can use xml:space attribute of the text property but it seems that it is not supported by the Presentation.Text object.

    My goal is to completely preserve white spaces. I would greately appreciate any help on this matter.

    Thank You.

    Thursday, June 14, 2012 6:01 PM

Answers

All replies

  • Hi

    Assuming you're with latest Open XML SDK 2.0.  When I try to reproduce the problem, it doesn't reproduce. Unlike Word document, without xml:space attribute, presentation xml keeps the space very well. Below is from PowerPoint presentation, note that there're three spaces in <a:t> element:

    <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>
                  <a:t>   </a:t>
                  </a:r>
                <a:endParaRPr lang="en-US" dirty="0" smtClean="0"/>
              </a:p>

    If possible, would you share the code that generates presentation, and a sample presentation that missing space?

    Skydrive is ideal place for sharing.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, June 18, 2012 3:16 AM
    Moderator
  • Thank You so much for your reply.  I really hope that it is something that I am doing wrong on my end.  Otherwise I would have to write my own SDK.  Here is the solution that reproduces my problem:

    WhiteSpaceRepro.zip

    Basically I have a text box on a single Presentation Slide.  This text box contains a text line full of spaces (just like in my initial post).  Then I add a tag to my slide and save.  After openning modified Presentation all spaces are gone.


    • Edited by Vic76 Monday, June 18, 2012 1:03 PM
    Monday, June 18, 2012 12:43 PM
  • Would you please check your url? the url is broken to me.

    thank,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, June 18, 2012 12:58 PM
    Moderator
  • Hi,

    I could reproduce what you described with the sample project, but I cannot explain how tags affect the document. I'll try to get other people help on this query, please wait some time.

    with regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, June 18, 2012 2:21 PM
    Moderator
  • Thank You!
    Monday, June 18, 2012 2:37 PM
  • Hello Vic,

    Using your zip, running the code in the VB project, when I opened the presentation “New_Modified.pptx” in PowerPoint the slide showed the blank line in the textbox, as below:

    The XML in the slide showed double paragraph tags instead of the run of blank space – the salient xml is this

    <p:sp>

            <p:nvSpPr>

              <p:cNvPr id="4" name="TextBox 3" />

              <p:cNvSpPr txBox="1" />

              <p:nvPr />

            </p:nvSpPr>

            <p:spPr>

              <a:xfrm>

                <a:off x="1752600" y="2209800" />

                <a:ext cx="4724400" cy="923330" />

              </a:xfrm>

              <a:prstGeom prst="rect">

                <a:avLst />

              </a:prstGeom>

              <a:noFill />

              <a:ln>

                <a:solidFill>

                  <a:schemeClr val="accent1" />

                </a:solidFill>

              </a:ln>

            </p:spPr>

            <p:txBody>

              <a:bodyPr wrap="square" rtlCol="0">

                <a:spAutoFit />

              </a:bodyPr>

              <a:lstStyle />

              <a:p>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0" />

                  <a:t>Some Text</a:t>

                </a:r>

              </a:p>

              <a:p>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0" />

                  <a:t></a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0" />

                  <a:t></a:t>

                </a:r>

              </a:p>

              <a:p>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0" />

                  <a:t>Some more text</a:t>

                </a:r>

                <a:endParaRPr lang="en-US" dirty="0" />

              </a:p>

            </p:txBody>

          </p:sp>

    What do you see when you open New_Modified.pptx?

    If you see the actual, intended space do you have another example that does not show the intended space? If you do have a repro that demonstrates the issue your problem can be explored further.  Please let us know.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Monday, June 18, 2012 7:15 PM
    Moderator
  • Try running this PowerPoint example through the code above.  I think it should demonstrate the problem better:

    https://skydrive.live.com/redir?resid=6D7BF9F1F673B509!119&authkey=!AFIXHV_HKma1GBM

    Monday, June 18, 2012 7:30 PM
  • Hi Vic,

    Your last post said :”Try running this PowerPoint example through the code above. I think it should demonstrate the problem better:

    https://skydrive.live.com/redir?resid=6D7BF9F1F673B509!119&authkey=!AFIXHV_HKma1GBM

    The only thing I found at the SkyDrive site at the link was another “New.pptx” file. When I double-clicked it the text box had 3 lines. The 3<sup>rd</sup> one said the words should have white spaces between the words.

    The XML for that slide showed the following, salient xml:

    <a:p>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>Thi</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>s</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>line</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>should</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>have</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>white</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>spaces</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>between</a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0">

                    <a:solidFill>

                      <a:srgbClr val="FF0000"/>

                    </a:solidFill>

                  </a:rPr>

                  <a:t> </a:t>

                </a:r>

                <a:r>

                  <a:rPr lang="en-US" dirty="0" smtClean="0"/>

                  <a:t>words</a:t>

                </a:r>

                <a:endParaRPr lang="en-US" dirty="0"/>

              </a:p>

    Other than that, the SkyDrive link led to no other content. Was there a revised project that I should have found?


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Monday, June 18, 2012 9:02 PM
    Moderator
  • I just re-uploaded the solution that better reproduces the issue.

    https://skydrive.live.com/redir?resid=6D7BF9F1F673B509!118&authkey=!ACYtn_lbpJPTRyA

    When you run it modified PPT file looses all spaces between words in in the last sentnce.

    Monday, June 18, 2012 9:12 PM
  • Hi Vic,

    I see the problem presentation, and I am confronted with another problem. When you first posted the VB project and New.pptx on SkyDrive the textbox had two lines, the second had spaces between the <a.t>   </a:t> tags.

    I compared the code in your VB project in that SkyDrive download to the VB project in the most recent SkyDrive download. The projects and the code are the same. I ran the code for the most recent download and generated the problem.

    The original download code didn’t generate the problem.

    I edited the textbox from the early New.pptx slide, adding a third line of text with spaces. Then  I  ran the VB code (in the early project – identical to the code in the more recent project.).

    The new third line, in the New_Modified.pptx file has the spaces.

    Here is a screen shot of the slide.

    I repeated the exercise two more times without a change in the results. Do you remember what you did to make the modified textbox or the VB project to show the problem?


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, June 20, 2012 8:41 PM
    Moderator
  • Chris,

    Thank you so much for looking into this problem.  Here are the steps to reproduce this issue:

    - Download WhiteSpaceReprro solution:

    https://skydrive.live.com/redir?resid=6D7BF9F1F673B509!118&authkey=!ACYtn_lbpJPTRyA

    - Unzip it and open it in Visual Studio

    - Solution will contain unmodified New.pptx presentation.  This is my original that does not have any problems.

    - Run this solution.  This will open New.pptx using Open XML SDK v2.0, tag first slide, save result as New_Modified.pptx in the bin\Debug folder.

    - After it is complete navigate to the bin\Debug directory and open New_Modified.pptx presentation.  This presentation is a result of my test.

    - Note that the last sentence has no spaces between words.  All spaces that were there before got removed.

    Basically anytime you have a text run like this <a:t> </a:t> it will be converted to this <a:t></a:t> by the SDK loosing all white spaces.  

    NOTE: PowerPoint user can insert white spaces as separate runs in the presentation by highliting a white space space or group of white spaces and change some sort of property on it (for example font, or font size, font color, language and so on)

    Hope this helps.

    Thanks again,

    Vic

    Thursday, June 21, 2012 12:09 PM
  • Hi Vic,

    Back to square one. Please make the following change to 'New.pptx' - i.e. add a fourth line in the text box so it says

    Some Text                                    

    Some more text

    This line should have white spaces between words.

    A fourth line.

    Then run the code in your VB project. The result of my test is:

    Some Text

    Some more text

    Thislineshouldhave whitespacesbetweenwords.

    A fourth line.

    As you can see - the new last line didn't lose its white space.


    I tried your suggestion on the 3rd line, and selected each space, changing an attribute. Only one was effective. The issue looks like a possible one in the XML parser but I haven't found any report of this happening. I'll pursue that and other sources to see if there is an existing resolution to the whitespace issue.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Thursday, June 21, 2012 9:54 PM
    Moderator
  • Hello Vic,

    I modified the fourth line to make it longer. It extended beyond the right side of the textbox, and wrapped. In this longer format it still retained the white spaces..

    Some Text

    Some more text

    Thislineshouldhave whitespacesbetweenwords.

    A fourth line. The line has white spaces between words.

    The XML has no <a:t>  </a:t> tags delineating white spaces All of the white spaces are retained within the text runs of strings. There is no clue as to why the runs are different in the third line. Here is the xml:

    <p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
      <p:cSld>
        <p:spTree>
          <p:nvGrpSpPr>
            <p:cNvPr id="1" name="" />
            <p:cNvGrpSpPr />
            <p:nvPr />
          </p:nvGrpSpPr>
          <p:grpSpPr>
            <a:xfrm>
              <a:off x="0" y="0" />
              <a:ext cx="0" cy="0" />
              <a:chOff x="0" y="0" />
              <a:chExt cx="0" cy="0" />
            </a:xfrm>
          </p:grpSpPr>
          <p:sp>
            <p:nvSpPr>
              <p:cNvPr id="4" name="TextBox 3" />
              <p:cNvSpPr txBox="1" />
              <p:nvPr />
            </p:nvSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="1905000" y="2198767" />
                <a:ext cx="5105400" cy="2585323" />
              </a:xfrm>
              <a:prstGeom prst="rect">
                <a:avLst />
              </a:prstGeom>
              <a:noFill />
              <a:ln>
                <a:solidFill>
                  <a:schemeClr val="accent1" />
                </a:solidFill>
              </a:ln>
            </p:spPr>
            <p:txBody>
              <a:bodyPr wrap="square" rtlCol="0">
                <a:spAutoFit />
              </a:bodyPr>
              <a:lstStyle />
              <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>Some Text</a:t>
                </a:r>
              </a:p>
              <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t></a:t>
                </a:r>
              </a:p>
              <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>Some more text</a:t>
                </a:r>
              </a:p>
              <a:p>
                <a:endParaRPr lang="en-US" dirty="0" smtClean="0" />
              </a:p>
              <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>This</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" sz="1600" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:srgbClr val="FFFF00" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>line</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:srgbClr val="FFFF00" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>should</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:schemeClr val="bg1" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>have white</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:srgbClr val="FF0000" />
                    </a:solidFill>
                    <a:latin typeface="Aharoni" pitchFamily="2" charset="-79" />
                    <a:cs typeface="Aharoni" pitchFamily="2" charset="-79" />
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>spaces</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:schemeClr val="bg1" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>between</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0">
                    <a:solidFill>
                      <a:srgbClr val="FF0000" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t></a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>words.</a:t>
                </a:r>
              </a:p>
              <a:p>
                <a:endParaRPr lang="en-US" dirty="0" />
              </a:p>
              <a:p>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>A fourth line</a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" dirty="0" smtClean="0" />
                  <a:t>. The line has white spaces </a:t>
                </a:r>
                <a:r>
                  <a:rPr lang="en-US" smtClean="0" />
                  <a:t>between words. </a:t>
                </a:r>
                <a:endParaRPr lang="en-US" dirty="0" smtClean="0" />
              </a:p>
              <a:p>
                <a:endParaRPr lang="en-US" dirty="0" />
              </a:p>
            </p:txBody>
          </p:sp>
        </p:spTree>
        <p:custDataLst>
          <p:tags r:id="Rf33109adb4d24a4a" />
        </p:custDataLst>
      </p:cSld>
      <p:clrMapOvr>
        <a:masterClrMapping />
      </p:clrMapOvr>
      <p:timing>
        <p:tnLst>
          <p:par>
            <p:cTn id="1" dur="indefinite" restart="never" nodeType="tmRoot" />
          </p:par>
        </p:tnLst>
      </p:timing>
    </p:sld>

    Could your presentation carry as much punch if you replaced the text box with lines of text in the slide, using a blank slide template?

    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Tuesday, June 26, 2012 6:29 PM
    Moderator
  • Chris,

    Thank You for looking into this issue.  My main use of the Open XML SDK is to tag slides of any presentations even those that I did not create myself (all or in part) and do it automatically.  Running this automated process, I need to be absolutely sure that Open XML SDK is not modifying underlying XML of the text runs, which it clearly does.  It removes the white spaces if they exist as standalone runs.  It is also clear that user can create those standalone empty runs by selecting the white space only without text and change property on it (in my example font color, but I've seen white space runs with different language property than the rest of the sentence), which should rightfully create a separate run.  This is exactly what runs are for. 

    It seems that, as long as user can create white space runs and make it a valid Presentation, Open XML SDK should be able to preserve them. 

    Am I wrong thinking that?  This looks like a bug (kind of substantial one too), is it not?  SDK potentially does something totally unexpected.  White spaces existed before tagging and disappear after.  As a SDK user I may not even realize this is happening.  I would not expect my text to change if all I do is tagging my slide.

    Thank You,

    Victor

    Tuesday, June 26, 2012 7:10 PM
  • I suppose a workaround maybe to eliminate all white spaces in the slide by shifting them to the text run before or after, but this could be pretty messy.  Not to mention it will not do anything good to the performance.
    Tuesday, June 26, 2012 7:13 PM
  • Hi Vic76,

    Your experience and your meticulous demonstration project, and my follow-up show two problems.

    • Open Office XML SDK strips white spaces. It should at least provide a setting to control whitespace handling.
    • The Open XML specification itself does not offer a way to say whether the space needs to be preserved in DrawingML’s text runs. Note the Word Open XML spec(17.3.3.31) does allow specifying whether the space needs to be preserved for the Word text run.

    A bug report on the Open Office XML SDK has been filed. The DrawingML’s schema needs to be updated.

    A workaround for your application is to use System.IO.Packaging. You have greater control over XML whitespace handling.

    Please refer to the following content for information about programming XML editing with the System.IO.Packaging framework.

    What is the Difference between the System.IO.Packaging and ...
    http://blogs.msdn.com/b/ericwhite/archive/2007/12/20/what-is-the-difference-between-the-system-io-packaging-and-microsoft-office-documentformat-openxml-packaging-namespaces.aspx

    Comparison of Navigating Parts between System.IO.Packaging and the ...
    http://blogs.msdn.com/b/ericwhite/archive/2009/05/11/comparison-of-navigating-parts-between-system-io-packaging-and-the-open-xml-sdk.aspx

    Office Open XML Formats: Inserting Values into Excel 2007 Cells
    http://msdn.microsoft.com/en-us/library/bb508943(v=office.12).aspx

     (Note the reference to WindowsBase.dll in this Forum thread..)
    Import System.IO.Packaging into Visual Basix 2008 program
    http://social.msdn.microsoft.com/Forums/en/vbide/thread/16707708-56db-4a51-94ed-618e55bc1777

    Query bing using this string “Office Open XML Formats: Retrieving Excel 2007 Cell Values” for links to more content about using System.IO.Packaging.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    • Proposed as answer by cjatmsModerator Friday, June 29, 2012 12:58 PM
    • Marked as answer by Vic76 Friday, June 29, 2012 1:28 PM
    Wednesday, June 27, 2012 8:39 PM
    Moderator