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)

1using System;
2using System.IO;
3using System.Linq;
4using System.Text;
5using GemBox.Presentation;
6using GemBox.Presentation.Tables;
7
8class Sample
9{
10    [STAThread]
11    static void Main(string[] args)
12    {
13        // If using Professional version, put your serial key below.
14        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
15
16        PresentationDocument presentation = PresentationDocument.Load("CloneDestination.pptx");
17
18        string pathToFileDirectory = "Resources";
19
20        var sourcePresentation = PresentationDocument.Load(Path.Combine(pathToFileDirectory, "CloneSource.pptx"));
21
22        // Use context so that references between 
23        // shapes and slides are maintained between all cloning operations.
24        var context = CloneContext.Create(sourcePresentation, presentation);
25
26        // Clone all drawings from the first slide of another presentation 
27        // into the first slide of the current presentation.
28        foreach (var drawing in sourcePresentation.Slides[0].Content.Drawings)
29            presentation.Slides[0].Content.Drawings.AddClone(drawing, context);
30
31        // Establish explicit mapping between slides so that 
32        // hyperlink on the second slide is correctly cloned.
33        context.Set(sourcePresentation.Slides[0], presentation.Slides[0]);
34
35        // Clone the second slide from another presentation.
36        presentation.Slides.AddClone(sourcePresentation.Slides[1], context);
37
38        presentation.Save("Cloning.pptx");
39    }
40}
1Imports System.IO
2Imports System.Text
3Imports GemBox.Presentation
4Imports GemBox.Presentation.Tables
5
6Module Samples
7
8    Sub Main()
9
10        ' If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
12
13        Dim presentation As PresentationDocument = PresentationDocument.Load("CloneDestination.pptx")
14
15        Dim pathToFileDirectory As String = "Resources"
16
17        Dim sourcePresentation = PresentationDocument.Load(Path.Combine(pathToFileDirectory, "CloneSource.pptx"))
18
19        ' Use context so that references between 
20        ' shapes and slides are maintained between all cloning operations.
21        Dim context = CloneContext.Create(sourcePresentation, presentation)
22
23        ' Clone all drawings from the first slide of another presentation 
24        ' into the first slide of the current presentation.
25        For Each drawing In sourcePresentation.Slides(0).Content.Drawings
26            presentation.Slides(0).Content.Drawings.AddClone(drawing, context)
27        Next
28
29        ' Establish explicit mapping between slides so that 
30        ' hyperlink on the second slide is correctly cloned.
31        context.Set(sourcePresentation.Slides(0), presentation.Slides(0))
32
33        ' Clone the second slide from another presentation.
34        presentation.Slides.AddClone(sourcePresentation.Slides(1), context)
35
36        presentation.Save("Cloning.pptx")
37
38    End Sub
39
40End Module

Check next sample or find out more about GemBox.Presentation and GemBox Software.