Support to change Slide Master Design using Aspose.Slides for VB.NET

Hi, To All,

I want to change the slidemaster design of ppt/pptx files to a new one, how to implement it based on VB.net 2008 and aspose.Slides.dll version 5.2.0.0.
I tried a demo, but it doesn’t work.

Private Function ChangeMaster(ByVal sFile As String, ByVal srcPPT As String, ByVal dstPPT As String) As Boolean

    Dim srcPres As New Aspose.Slides.Presentation(srcPPT)
    Dim dPres As New Aspose.Slides.Presentation(sFile )
    Dim sldTitleSlide As Aspose.Slides.Slide = srcPres.CloneSlide(srcPres.GetSlideByPosition(1), 1, dPres, New SortedList())
    On Error Resume Next
    Dim TitleSlideMasterID As Integer = sldTitleSlide.MasterId
    Dim sldBodySlide = srcPres.CloneSlide(srcPres.GetSlideByPosition(2), 1, dPres, New SortedList())
    Dim BodySlideMasterID As Integer = sldBodySlide.MasterId
    dPres.Slides.Remove(sldTitleSlide)
    dPres.Slides.Remove(sldBodySlide)
    Dim sld As Aspose.Slides.Slide = dPres.AddTitleSlide()
    sld.ChangeMaster(dPres.GetSlideById(TitleSlideMasterID))
    sld = dPres.AddBodySlide()
    sld.ChangeMaster(dPres.GetSlideById(BodySlideMasterID))
    dPres.Write(dstPPT)

End Function

The above codes hasn’t worked out the desired output, who can help me how to implement it based on VB.net 2008 and aspose.Slides.dll version 5.2.0.0.

Thanks in advance!

Ducaisoft

@ducaisoft,

I have observed the information shared by you along with sample code. You are using a very old API version that belonged to legacy Aspose.Slides API which is no longer in business. I suggest you to please try using latest Aspose.Slides for .NET 18.10 on your end. Please visit this documentation link for sample code related to slide cloning and applying masters on them.

Thank you for your suggestion. Could you please show me a full demo code how to change the PPT/PPTx SlideMaster design input from another ppt/pptx?

@ducaisoft,

I have observed your comments and like to inform that the shared link is actual example of cloning slide and applying master to it. Can you please elaborate in the form of source presentations and desired output presentation that you want to generate using Aspose.Slides.

Thanks for your reference link. Unfortunately, by following the link, I tried it but failed so that it is best for you to show me the full demo codes how to change the ppt/pptx SlideMaster design. High appreciation for your sample in advance!

@ducaisoft,

As requested earlier, can you please elaborate in the form of source presentations and desired output presentation that you want to generate using Aspose.Slides. Please provide the source presentations and desired output presentation so that I may observe that to help you out.

Please see the attachment for the demo files.
Demo.zip (192.4 KB)
[Input Slide.pptx] is the input file whose slidemaster/theme will be changed.
[Source Master Slide.potx] is the source file whose SlideMaster/theme will apply to the input file.
[Desired Output.pptx] is the desired output file whose SlideMaster/theme has been same as that of the [Source Master Slide.potx].

Thank for your sample code in advance!

@ducaisoft,

I have observed your requirements and suggest you to please try using following samaple code on your end. There is small issue that new master slides background is not getting applied by default and an issue with ID SLIDESNET-40701 has been created in our issue tracking system to resolve this. For the time being, you can reset the master slide background your self to serve the purpose.

    public static void ApplyDiffMaster()
    {
        String path = @"C:\Users\Muhammad\Downloads\Demo\";
        Presentation templateMaster = new Presentation(path + "Source Master Slide.potx");
        Presentation sourcePresentation = new Presentation(path + "Input Slide.pptx");
        Presentation targetPresentation = new Presentation();
        IMasterSlide newMaster = targetPresentation.Masters.AddClone(templateMaster.Masters[0]);
        ISlideCollection TargetSlides = targetPresentation.Slides;

        foreach(ISlide slide in sourcePresentation.Slides)
        {
           ISlide ClonedSlide= TargetSlides.AddClone(slide,newMaster, true);
        }
       // newMaster.Background.Type = Aspose.Slides.BackgroundType.Themed;
        //Removing defualt slide
        targetPresentation.Slides.RemoveAt(0);
        targetPresentation.Masters.RemoveUnused(true);
        targetPresentation.Save(path + "Savedpres.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
    }

Thanks for your sample code.
It seems work, but the filesize of the output file is zero! what wrong?

Private Function ReplaceMaster(ByVal sFile As String, ByVal dFile As String, ByVal Master As String, Optional ByVal PPTX As Boolean = False)
    Dim TemplateMaster As Aspose.Slides.Presentation = New Aspose.Slides.Presentation(Master)
    Dim SourcePresentation As Aspose.Slides.Presentation = New Aspose.Slides.Presentation(sFile)
    Dim TargetPresentation As Aspose.Slides.Presentation = New Aspose.Slides.Presentation()
    Dim NewMaster As Aspose.Slides.IMasterSlide = TargetPresentation.Masters.AddClone(TemplateMaster.Masters(0))
    Dim TargetSlides As Aspose.Slides.ISlideCollection = TargetPresentation.Slides
    Dim ClonedSlide As Aspose.Slides.ISlide
    For Each Slide As Aspose.Slides.Slide In SourcePresentation.Slides
        ClonedSlide = TargetSlides.AddClone(Slide, NewMaster, True)
        Application.DoEvents()
    Next
    'NewMaster.Background.Type = Aspose.Slides.BackgroundType.Themed
    TargetPresentation.Slides.RemoveAt(0)
    TargetPresentation.Masters.RemoveUnused(True)
    If PPTX Then
        On Error Resume Next
        TargetPresentation.Save(dFile, Aspose.Slides.Export.SaveFormat.Pptx)
    Else
        On Error Resume Next
        TargetPresentation.Save(dFile, Aspose.Slides.Export.SaveFormat.Ppt)
    End If
End Function

@ducaisoft,

I have seen the equavalent VB code and it seems fine. Please try using latest Aspose.Slides for .Net 18.10 on your end. If there is still issue then please share the sample project reproducing issue along with generated presentation.

The output has been generated by Aspose.Slides.dll version 18.10. I don’t know what’s wrong with it,why the filesize of output file is 0!

@ducaisoft,

I have observed your comments. Can you please share the sample project reproducing issue along with generated presentation.

Please refer to the sample project based on VB.net 2008 and Aspose.Slides.dll version 18.10.
DCPPTMasterReplacer.zip (9.2 MB)

@ducaisoft,

I have worked with the sample code shared by you and have been able to observe the issue. An issue with ID SLIDESNET-40704 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESNET-40701) have been fixed in this update.