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.

Cloning

Drawing (such as shapes, pictures, connectors, tables, etc.) and slide instances in GemBox.Presentation can be only at one single location in a presentation at a time. To insert a drawing or a slide into some other part of the same or another presentation, it must be inserted as a clone.

The following example demonstrates how to clone drawings and slides.

Notice 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.

Screenshot
Cloning Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.IO;
using System.Linq;
using System.Text;
using GemBox.Presentation;
using GemBox.Presentation.Tables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PresentationDocument presentation = PresentationDocument.Load("CloneDestination.pptx");

        string pathToFileDirectory = "Resources";

        var sourcePresentation = PresentationDocument.Load(Path.Combine(pathToFileDirectory, "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.pptx");
    }
}
Imports System.IO
Imports System.Text
Imports GemBox.Presentation
Imports GemBox.Presentation.Tables

Module Samples

    Sub Main()

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

        Dim presentation As PresentationDocument = PresentationDocument.Load("CloneDestination.pptx")

        Dim pathToFileDirectory As String = "Resources"

        Dim sourcePresentation = PresentationDocument.Load(Path.Combine(pathToFileDirectory, "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.pptx")

    End Sub

End Module

Check next sample.