question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lost whitespace in power point

See original GitHub issue

Hi, I encountered the following issue using the OpenXML SDK

Description I am reading in a simple pptx file (see the resource in the repro section) using the OpenXML SDK (code provided in the repro section). First opening the file and then reading the slide part with the OpenXMLReader. The text element containing only white spaces is trimmed and after reading contains no characters. This behaviour destroys the layout of manually indented content if the file would be saved after reading it.

Similar reports: https://stackoverflow.com/questions/6106044/missing-whitespace-within-pptx-paragraphs-using-openxmlsdk?rq=1 https://stackoverflow.com/questions/7153387/powerpoint-openxml-whitespace-is-disappearing?rq=1

Information

  • .NET Target: .NET Core
  • DocumentFormat.OpenXml Version: 2.11.3

Repro I have created a small example using an example pptx file with one slide https://github.com/lklein53/openxmlsdk-whitespace

Observed

The xml reader used internally is configured to ignore insignificant whitespaces which results in the removal of the whitespaces in the text element. I haven’t seen the possibility to change that behaviour. For word documents there is the xml:space=preserve attribute added to such text nodes which seems to be not the case for power point files.

Expected

It would be nice if it would be possible to configure the current behaviour to explicitly keep insignificant whitespaces if that is desired by the user of the SDK. I could implement this functionality if you think it should be added.

Please let me know if I am using the OpenXMLReader wrong and there is another way to read in the slide part.

Thanks for your help and kind regards, Lars

(edit by @twsouthwick)

using System;
using System.Linq;
using System.Reflection;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using Xunit;
using Path = System.IO.Path;

namespace TestProject1 {
public class UnitTest1 {
  [Fact]
  public void Test1() {
    const string fileName = "Resources/example.pptx";
    var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException(), fileName);
    using var doc = PresentationDocument.Open(path, false);
    var slide = doc.PresentationPart.SlideParts.First();
    var reader = OpenXmlReader.Create(slide);
    reader.Read();
    var element = reader.LoadCurrentElement();
    var text = element.Descendants<Text>().First();
    Assert.Equal(" ", text.Text);
  }
}
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
lklein53commented, Jan 19, 2021

Hi, Thanks for your reply. I will create a PR with the changes

0reactions
twsouthwickcommented, Jan 22, 2021

Fixed in #857. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change text alignment, indentation, and spacing in ...
To change the spacing above or below a paragraph, type or click the arrows next to Before or After. · To change the...
Read more >
White Space at Bottom of PowerPoint Slide
With your presentation open, choose DESIGN>Slide Size>Custom Slide Size... · Change Slides from Portrait to Landscape. · OK out. PowerPoint will ...
Read more >
I've lost the white space between pages option on some ...
In one of the problem documents and try going to the File tab > Options > Display. Check the box to display white...
Read more >
Workaround for printing slides without white edges
Unfortunately, it's a bit time-intensive and requires some trial and error. Go to Design > Slide Size > Custom Slide Size.
Read more >
Powerpoint displays "squished together" text
Powerpoint displays "squished together" text · Open File>Options>Advanced. · Scroll down to the Display section. · Check Disable hardwares graphics ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found