Clone Slides and Drawings in PowerPoint

The example below shows how you can use the GemBox.Presentation component to clone slides and drawings in PowerPoint presentations programmatically in C# and VB.NET.

Upload your file (Drag file here)
using GemBox.Presentation;
using System;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("%InputFileName%");

        var sourcePresentation = PresentationDocument.Load("%#CloneSource.pptx%");

        // Use context so that references between 
        // shapes and slides are maintained between all cloning operations.
        var context = CloneContext.Create(sourcePresentation, presentation);

        // Clone all drawings from the first slide of another presentation 
        // into the first slide of the current presentation.
        foreach (var drawing in sourcePresentation.Slides[0].Content.Drawings)
            presentation.Slides[0].Content.Drawings.AddClone(drawing, context);

        // Establish explicit mapping between slides so that 
        // hyperlink on the second slide is correctly cloned.
        context.Set(sourcePresentation.Slides[0], presentation.Slides[0]);

        // Clone the second slide from another presentation.
        presentation.Slides.AddClone(sourcePresentation.Slides[1], context);

        presentation.Save("Cloning.%OutputFileType%");
    }
}
Imports GemBox.Presentation
Imports System

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = PresentationDocument.Load("%InputFileName%")

        Dim sourcePresentation = PresentationDocument.Load("%#CloneSource.pptx%")

        ' Use context so that references between 
        ' shapes and slides are maintained between all cloning operations.
        Dim context = CloneContext.Create(sourcePresentation, presentation)

        ' Clone all drawings from the first slide of another presentation 
        ' into the first slide of the current presentation.
        For Each drawing In sourcePresentation.Slides(0).Content.Drawings
            presentation.Slides(0).Content.Drawings.AddClone(drawing, context)
        Next

        ' Establish explicit mapping between slides so that 
        ' hyperlink on the second slide is correctly cloned.
        context.Set(sourcePresentation.Slides(0), presentation.Slides(0))

        ' Clone the second slide from another presentation.
        presentation.Slides.AddClone(sourcePresentation.Slides(1), context)

        presentation.Save("Cloning.%OutputFileType%")
    End Sub
End Module
PowerPoint slide contents cloned with GemBox.Presentation
Screenshot of PowerPoint slide contents cloned with GemBox.Presentation

Note that cloned drawings are still connected (if they are moved, connector is also moved), same as in the source presentation, and that hyperlinks are correctly cloned because the same CloneContext instance is used in all cloning operations.

See also


Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy