Clone and then Remove Empty Slide PPT and PPTX

I have the following code which clones multiple presentations. An empty slide remains. How to get rid of it? The following is for PPT but I also need the equivalent for PPTX.


Thanks!

I am just looping through an array to grab the file names:

ppt_template = ppt_template.TrimEnd(",").ToString
Dim arr_PPT As Array = Split(ppt_template, “,”, -1)

If ppt_template.Length > 0 Then

For i As Integer = 0 To UBound(arr_PPT)

Dim srcPres1 As New Presentation(Path.Combine(Request.PhysicalApplicationPath, “Files” & arr_PPT(i)))

'Clone first presentation with the newly created presentation
pres = getClonedPres(srcPres1, pres)

'HOW? Remove the first default slide of the merged presentation?

Try
'pres.Slides.RemoveAt(0)
pres.DeleteUnusedMasters()
Catch ex As Exception
End Try


Next
End If

Hi,


I have observed the sample code shared by you and like to share that in order to remove the default empty slide that will be available on index 0 (Only if you have cloned the slides in target presentation not at index 0). You already have the statement in your code available but it is commented. Please un-comment the statement and use the following statement before deleting unused masters.

pres.Slides.RemoveAt(0)

If there is still an issue then please share the sample application along with source and generated presentations with us and I will try my best to help you further.

Many Thanks,

Thanks! I’m appending many slides so putting the RemoveAt in the loop didn’t work so I moved it outside like so and all is fine. Thanks again!


'Instantiate a Presentation object that represents a PPT file
Dim pres As PresentationEx = New PresentationEx
Dim iCount As Integer = 0

ppt_template = ppt_template.TrimEnd(",").ToString
Dim arr_PPT As Array = Split(ppt_template, “,”, -1)

'remove master slide


If ppt_template.Length > 0 Then

For i As Integer = 0 To UBound(arr_PPT)

Dim srcPres1 As New PresentationEx(Path.Combine(Request.PhysicalApplicationPath, “Files” & arr_PPT(i)))

'Clone first presentation with the newly created presentation
Dim slds As SlideExCollection = pres.Slides
Dim SlideIndex As Integer = slds.AddClone(srcPres1.Slides(0))
'slds.AddClone(srcPres1.Slides(0))

Try
'Template(Slide)
Dim Slide As SlideEx = srcPres1.Slides(0)
'Get the template master from template slide
Dim masterslide As MasterSlideEx = Slide.LayoutSlide.MasterSlide
'Changing Slide master of cloned slide
Slide = pres.Slides(SlideIndex)

'Removing Old master
Dim Oldmasterslide As MasterSlideEx = Slide.LayoutSlide.MasterSlide
pres.Masters.Remove(Oldmasterslide)
Slide.LayoutSlide.MasterSlide = masterslide

Dim c As Integer = pres.Masters.Count
Catch ex As Exception

End Try

Next

'Remove the first default slide of the merged presentation
Try
pres.Slides.RemoveAt(0)
Catch
End Try
End If

Hi,


That is really appreciable that things working on your end. Please share, if I may help you further in this regard.

Many Thanks,