none
Validation of Powerpoint presentations RRS feed

  • Question

  • Hi

    We have a webservice creating Office documents using Open XML SDK developed in VS 2010.

    We run into problems when creating Powerpoint-presentations in some scenarios.
    We create the presentation using another pre-created presentation on which we apply the SlideMaster from a template presentation. In most cases this works fine and the presentations opens nicely in Powerpoint.
    The strange thing is that with certain combination of pre-created presentation and template presentation, the resulting file doesn't open in Powerpoint without asking for repair.

    Now, when we use Open XML Productivity tool to validate the file, the validation result only consists if the "smtclean is not declared" messages, which seems to be shown for every type of presentation you try to validate, even a new blank presentation created with Powerpoint.
    Nothing wrong is found in validation which can explain the repair-message in Powerpoint.

    If we repair the presentation, save it and use the comparison tool, there are a lot of differences, but they all seem to be of the "renaming sort" if slidelayout parts. Why isn't the validating tools show me whats actually wrong?

    The following code is used to apply the SlideMaster to the pre-created presentation:

        Private Sub PTUpdateFormats(ByVal themeFile As String, ByVal presFile As String)
    
            Using themeDocument As PresentationDocument = PresentationDocument.Open(themeFile, False)
                Using presentationDocument As PresentationDocument = presentationDocument.Open(presFile, True)
                    PTApplyTheme(presentationDocument, themeDocument)
                End Using
            End Using
    
        End Sub
    
        Public Sub PTApplyTheme(ByVal presentationDocument As PresentationDocument, ByVal themeDocument As PresentationDocument)
    
            If (presentationDocument Is Nothing) Then
                Throw New ArgumentNullException("presentationDocument")
            End If
            If (themeDocument Is Nothing) Then
                Throw New ArgumentNullException("themeDocument")
            End If
    
            ' Get the presentation part of the presentation document.
            Dim presentationPart As PresentationPart = presentationDocument.PresentationPart
    
            ' Get the existing slide master part.
            Dim slideMasterPart As SlideMasterPart = presentationPart.SlideMasterParts.ElementAt(0)
    
            ' Get id for the existing slide master part.
            Dim relationshipId As String = presentationPart.GetIdOfPart(slideMasterPart)
    
            ' Get the new slide master part.
            Dim newSlideMasterPart As SlideMasterPart = themeDocument.PresentationPart.SlideMasterParts.ElementAt(0)
    
            ' Remove the theme part.
            presentationPart.DeletePart(presentationPart.ThemePart)
    
            ' Remove the old slide master part.
            presentationPart.DeletePart(slideMasterPart)
    
            ' Import the new slide master part, and reuse the old relationship ID.
            newSlideMasterPart = presentationPart.AddPart(newSlideMasterPart, relationshipId)
    
            ' Change to the new theme part.
            presentationPart.AddPart(newSlideMasterPart.ThemePart)
            Dim newSlideLayouts As Dictionary(Of String, SlideLayoutPart) = New Dictionary(Of String, SlideLayoutPart)()
            For Each slideLayoutPart As Object In newSlideMasterPart.SlideLayoutParts
                newSlideLayouts.Add(GetSlideLayoutType(slideLayoutPart), slideLayoutPart)
            Next
            Dim layoutType As String = Nothing
            Dim newLayoutPart As SlideLayoutPart = Nothing
    
            ' Insert the code for the layout for this example.
            Dim defaultLayoutType As String = "Rubrik och innehåll"
    
            ' Remove the slide layout relationship on all slides.
            For Each slidePart As SlidePart In presentationPart.SlideParts
                layoutType = Nothing
                If (Not (slidePart.SlideLayoutPart) Is Nothing) Then
    
                    ' Determine the slide layout type for each slide.
                    layoutType = GetSlideLayoutType(slidePart.SlideLayoutPart)
    
                    ' Delete the old layout part.
                    slidePart.DeletePart(slidePart.SlideLayoutPart)
                End If
    
                If ((Not (layoutType) Is Nothing) AndAlso newSlideLayouts.TryGetValue(layoutType, newLayoutPart)) Then
                    ' Apply the new layout part.
                    slidePart.AddPart(newLayoutPart)
                Else
                	newLayoutPart = newSlideLayouts(defaultLayoutType)
                	' Apply the new default layout part.
                	slidePart.AddPart(newLayoutPart)
                End If
            Next
    
        End Sub
    
        ' Get the type of the slide layout.
        Public Function GetSlideLayoutType(ByVal slideLayoutPart As SlideLayoutPart) As String
            Dim slideData As CommonSlideData = slideLayoutPart.SlideLayout.CommonSlideData
            ' Remarks: If this is used in production code, check for a null reference.
            Return slideData.Name
    
        End Function

    If anybody would like to test with my sample files, they can be downloaded from Skydrive files (Powerpoint files.zip)

    Is there anything wrong with my code, or am I missing to check something when I merge the Slidemaster to the presentation?
    A lot of other pre-created presentations and templates works fine to merge, but the combination that can be downloaded above won't work. Actually, the template and the pre-created presentation works together with other files.

    Thanks in advance


    Best Regards Peter Karlström Midrange AB, Sweden


    Friday, October 18, 2013 2:53 PM

Answers

All replies

  • We run into problems when creating Powerpoint-presentations in some scenarios.

    What do you mean "in some scenarios"? Do they have the common ground?

    Do you want to use OpenXML to merge PowerPoint Decks Together?

    See sample below:

    http://msdn.microsoft.com/en-us/library/office/ee361883(v=office.12).aspx


    • Edited by Andy_mic Monday, October 21, 2013 9:35 AM
    Monday, October 21, 2013 9:35 AM
  • Hi Andy

    Thank you for your reply.

    We have 4 different presentation templates (potx) and 7 different predefined presentations (pptx) from which we build presentations using a web-service.
    3 of the potx-templates can be mixed with all 7 predefined presentations without problem.
    1 of the templates can be mixed with 5 of the predifined presentations, but when using the other two our problem occurs. On the link om my skydrive i placed the last template and of of the predefined presentations which causes trouble. The resulting presentation can be validated using Open XML Productivity Tools without showing any errors (execpt for the usual smtclean errors). When opened with Powerpoint a repair message is shown because Powerpoint has found errors in the file.

    So we don't try to merge decks here, rather applying the slidemaster and theme from the potx-template on to the predefined presentation.


    Best Regards Peter Karlström Midrange AB, Sweden

    Tuesday, October 22, 2013 6:58 AM
  • Hi Peter,

    I think that the problem here is that there are a lot of inter-dependencies in PresentationML, and the Open XML SDK validator, while it checks for a number of them, doesn't catch them all.

    To solve this issue, some time ago Bob McClellan and I put together something called PresentationBuilder which deals with these inter-dependencies.  This is part of PowerTools for Open XML - licensed under Ms-PL, so free to use.

    I put your presentations through PresentationBuilder, and it worked without issues, and produced a valid presentation.  I did make one small change to PresentationBuilder - made it valid to pass in a POTX.  Your presentations worked with PresentationBuilder with no changes if I saved the POTX to a PPTX, however, I thought that it is valid to supply a POTX, so I made the change to PresentationBuilder to allow for that.  You can get PresentationBuilder 2.3.1 at https://powertools.codeplex.com/releases/view/74771

    See: http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2013/01/14/quick-introduction-to-presentationbuilder.aspx

    See: http://openxmldeveloper.org/wiki/w/wiki/presentationbuilder.aspx

    Regards, Eric White
    Thursday, November 14, 2013 4:02 AM
  • Hi Eric

    Thanks for your effort and your support.

    As a mather of fact, I already use Powertools for Open XML in this project and will download the updated Presentationbuilder and look into the parts concerning this issue.

    I will report back to this post when it's done, but it will probably take a couple of weeks to make this happen.


    Best Regards Peter Karlström Midrange AB, Sweden

    Sunday, November 17, 2013 2:58 PM
  • Hi again Eric

    Sorry for the delay.

    I have been testing the new PresentationBuilder and this really works now.

    But on the path to a complete solution I have been trying to implement the new class in the complete solution Project. Here is where I get troubles.

    The OpenXMLPowerTools which I use in the solution uses .NET Framework 3.5. The new PresentationBuilder is using .NET Framework 4.0.
    They work well together in an ordinary Windows Forms application, but when I try using it as a Webservice the new PresentationBuilder seems to have no effect in the new presentation.

    Do you know if there will be a new package of OpenXMLPowerTools incorporating this new PresentationBuilder class?

    Thanks in advance


    Best Regards Peter Karlström Midrange AB, Sweden

    Tuesday, January 21, 2014 1:26 PM
  • Hi

    Solved it!
    Did som minor adjustments in the Project, and got a .NET Framework 4 version of the OpenXMLPowerTools with the new PresenationBuilder.

    Now Everything is working fine when merging my presentations.

    Thanks for your support.


    Best Regards Peter Karlström Midrange AB, Sweden

    Tuesday, January 21, 2014 3:37 PM