Lost whitespace in power point
See original GitHub issueHi, 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:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
Hi, Thanks for your reply. I will create a PR with the changes
Fixed in #857. Thanks!