C# Copy shapes between slides in PowerPoint document

In this article, we will explain how to copy a shapes or all shapes from one slide into another within the same PowerPoint document by using Spire.Presentation.

Firstly, view the sample PowerPoint document:

C# Copy shapes between slides in PowerPoint document

Copy a single shape from the first slide to the second slide:

//Load the sample document
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx");


//define the source slide and target slide
ISlide sourceSlide = ppt.Slides[0];
ISlide targetSlide = ppt.Slides[1];

//copy the second shape from the source slide to the target slide
targetSlide.Shapes.AddShape((Shape)sourceSlide.Shapes[1]);

//save the document to file 
ppt.SaveToFile("Copyshape.pptx", FileFormat.Pptx2013);

Effective screenshot after copy a single shape from the first slide to second slide:

C# Copy shapes between slides in PowerPoint document

Copy all shapes from the first slide to the second slide:

//Load the sample document
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx");


//copy all the shapes from the source slide to the target slide
for (int i = 0; i < ppt.Slides.Count - 1; i++)
{
    ISlide sourceSlide = ppt.Slides[i];
    ISlide targetSlide = ppt.Slides[ppt.Slides.Count - 1];
    for (int j = 0; j < sourceSlide.Shapes.Count; j++)
    {
        targetSlide.Shapes.AddShape((Shape)sourceSlide.Shapes[j]);
    }
}

//save the document to file 
ppt.SaveToFile("Copyshapes.pptx", FileFormat.Pptx2013);

Effective screenshot after copy all shapes from the first slide to second slide:

C# Copy shapes between slides in PowerPoint document