Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

Cannot open presentation theme (.thmx) file

Open d3fr0g opened this issue 5 years ago • 5 comments

Is this a:

  • [x] Issue with the OpenXml library
  • [ ] Question on library usage

Description

Trying to preserve themes and and generate presentations with specific themes (with slidelayouts). The logical way to store themes seemed like the thmx. It cannot be opened with OpenXML SDK.

Information

  • .NET Target: .NET Framework 4.7.2
  • DocumentFormat.OpenXml Version: 2.10

Repro

Open a presentation with the desired theme. Go to Design tab, open Themes and "Save current theme..."

Write a simple code that tries to open it: using (PresentationDocument themeDocument = PresentationDocument.Open(@"d:\temp\OfficeTheme.thmx", false)){}

Observed

Exception is thrown: DocumentFormat.OpenXml.Packaging.OpenXmlPackageException HResult=0x80131500 Message=The specified package is not valid. Source=DocumentFormat.OpenXml StackTrace: at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load() at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode) at DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(String path, Boolean isEditable, OpenSettings openSettings) at DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(String path, Boolean isEditable)

The MainPartContentType will be "application/vnd.openxmlformats-officedocument.themeManager+xml" which is not a valid content type.

Expected

PresentationDocument is loaded.

d3fr0g avatar Jun 15 '20 09:06 d3fr0g

@d3fr0g The issue here is that the .thmx file type is actually not a PresentationDocument. It's an Office Theme package which is different. A .pptx has a bunch of other parts that .thmx is missing and hence the exception. There is an article which demonstrates how to manipulate theme parts and information that exist in the PresentationDocument. This is probably a better way to deal with themes but I'm not sure what your goals are.

tomjebo avatar Jun 29 '20 22:06 tomjebo

@d3fr0g does the link @tomjebo gave help with it?

twsouthwick avatar Jul 08 '20 18:07 twsouthwick

My actual goal was to separate the content from the layout. Create a presentation by using slide masters and merge them with the content. From a quick glance themes seemed like a good idea. After a while it turned out that the ECMA doesn't even specify themes (thmx) (at least I couldn't find it), and to add to the confusion Word can export a theme file which of course will be a different theme. I ended up experimenting with an empty presentation as the master theme (I think originally I was using the above article as a base), but there are a lot of caveats there as well. E.g. any minor deviation from the master will copy over the relevant parts (expected but need to be handled). So it would be good to have and open themes but in the end it is not the blocker part.

d3fr0g avatar Jul 10 '20 16:07 d3fr0g

This seems like something we may want to include, but not sure if we'll have time to investigate. However, we'd be happy to accept PRs for this.

I'd suggest to derive from OpenXmlPackage similar to PresentationDocument. You may be able to reuse parts already defined that are needed in the theme package. You may also need to make new parts/elements. If you could do this in a separate assembly, it would be interesting to see what needs to be made public in the SDK to enable extensions like this.

@d3fr0g would you be interested in exploring this? Happy to provide feedback along the way.

twsouthwick avatar Jul 10 '20 17:07 twsouthwick

@twsouthwick It would be interesting, I can look into this second part of August. What I recall that a lot of the code is generated but couldn't find the schemas or the templates, so I'll have to look into that as well. But then again, probably the schema itself is a question. I'll get back to this when I'll have some time.

d3fr0g avatar Jul 14 '20 10:07 d3fr0g