How to access slide size from a PowerPoint .thmx file RRS feed

  • Question

  • Hello everyone,

    I would like to retrieve the slide size stored in a .thmx theme file produced by PowerPoint. If I try this for a .pptx presentation file all works well. Width and Height get correct values:

    string FullPathName = @"C:\Presentation.pptx";
    using (PresentationDocument Pres = PresentationDocument.Open(FullPathName, false))
      SlideSize SlSize = Pres.PresentationPart.Presentation.SlideSize;
      int Width = (int) SlSize.Cy;
      int Height = (int) SlSize.Cx;

    Unfortunately, it seems I cannot hand a .thmx file to PresentationDocument.Open( ... ). So although a .thmx file also contains the information (in /theme/presentation.xml rather than /ppt/presentation.xml) I cannot access it.

    Is there a good way to get to that?

    Thanks - any help highly appreciated!

    Wednesday, September 4, 2013 7:49 PM


  • For anyone who may need this: I found a workaround by opening the .thmx file as a System.IO.Packaging.Package and then reading a stream from the relevant file with the XML.

    See below. You may want to add error handling.


    string FullPathName = @"C:\somefile.thmx";
    using (Package ThemePackage = Package.Open(FullPathName, FileMode.Open, FileAccess.Read))
        // The page ratio must be calculated from the page width and height, which is stored in /theme/presentation.xml, tag p:sldSz, for any .thmx file.
        Uri XmlUri = PackUriHelper.CreatePartUri(new Uri(@"theme\presentation.xml", UriKind.Relative));
        PackagePart XmlFilePart = ThemePackage.GetPart(XmlUri);
        XmlDocument XmlFile = new XmlDocument();
        XmlFile.Load(XmlFilePart.GetStream(FileMode.Open, FileAccess.Read));
        XmlNodeList SlideSizeNodes = XmlFile.GetElementsByTagName("p:sldSz");
        int Cx = Int32.Parse(SlideSizeNodes[0].Attributes["cx"].Value);
        int Cy = Int32.Parse(SlideSizeNodes[0].Attributes["cy"].Value);
        //string Type = SlideSizeNodes[0].Attributes["type"].Value;

    • Edited by h-ruddi Friday, September 6, 2013 12:40 PM Included answer
    • Marked as answer by h-ruddi Friday, September 6, 2013 12:40 PM
    Friday, September 6, 2013 9:51 AM