How to duplicate slides in presentation

Ashokst
Posted by in C# category on for Beginner level | Points: 250 | Views : 2018 red flag

This article presents how to clone PowerPoint slide within the same presentation or among multiple presentations using Free PowerPoint API in C#.

Introduction

It is easy for us to copy the contents in presentation slides, while it is very difficult for us to clone a slide which making an exact copy. That’s because it is not easy to copy the templates, the background image/color and other elements such as shape, chart in the slides. Spire.Presentation makes it possible to make an exact copy or clone of any slide within the same presentation or between multiple presentations from code in C# and VB.NET. Developers can use Spire.Presentation to clone a new slide without making any changes on the original slide.  In this article, we will explain how to clone a presentation in C# in different ways: We can get the Free Spire.Presentation from NuGet. After getting the Spire.Presentation.dll , developers need to add it manually as reference in the Bin folder though the below path:  “…\Spire.Presentation\Bin\NET4.0\Spire. Presentation.dll”. There is no need to install MicroSoft PowerPoint on your machine and it is totally independent.

  • Cloning a slide from one position to another position within the same presentation.
  • Cloning a slide from another presentation to a specified position between multiple presentations.

We can get the Free Spire.Presentation from NuGet. After getting the Spire.Presentation.dll , developers need to add it manually as reference in the Bin folder though the below path:  “…\Spire.Presentation\Bin\NET4.0\Spire. Presentation.dll”. There is no need to install MicroSoft PowerPoint on your machine and it is totally independent.

Using the code

Here comes to the steps of how to duplicate a slide in the presentation within the same PowerPoint document or from the different PowerPoint documents.

Step 1: Create a PPT document and load the document from file.

Presentation ppt = new Presentation();

ppt.LoadFromFile("sample.pptx");

Step 2: Define the slide that will be cloned from the same presentation or from another presentation.

Duplicate the slides from the same presentation:

//Get a list of slides and choose the first slide to be cloned

ISlide slide = ppt.Slides[0];

Duplicate the slides from the different presentation:

//Load the document from files and choose the first slide to be cloned.

Presentation ppt1 = new Presentation();

ppt1.LoadFromFile("table.pptx");

ISlide slide = ppt1.Slides[0];

Step 3:  Insert the desired slide to the specified index in the same presentation.

int index = 1;   

ppt.Slides.Insert(index, slide); 


Step 4: Save and launch to view.

ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2010);

System.Diagnostics.Process.Start("result.pptx");

Please check the screenshot of clone the slide within the same presentation:


The screenshot of clone the slide from the other presentation slides:


Full code:

namespace CloneSlidesinPrsentation

{

    class Program

    {

        static void Main(string[] args)

        {

           Presentation ppt = new Presentation();

            ppt.LoadFromFile("sample.pptx");

            ////Get a list of slides and choose the first slide to be cloned.

            //ISlide slide = ppt.Slides[0];

            //Load the document from files and choose the first slide to be cloned.

           Presentation ppt1 = new Presentation();

            ppt1.LoadFromFile("table.pptx");

            ISlide slide = ppt1.Slides[0];

            int index = 1;   

            ppt.Slides.Insert(index, slide);         

            ppt.SaveToFile("result2.pptx", Spire.Presentation.FileFormat.Pptx2010);

            System.Diagnostics.Process.Start("result2.pptx");

        }

    }

}



Conclusion


Free Spire.Presentation supports different version of Microsoft PowerPoint, such as PPT, PPS, PPTX and PPSX. It also supports multiple elements in PowerPoint documents:

  • Insert all kinds of shapes (such as triangle, rectangle, BackOrPreviousButton );
  • Insert audio, video;
  • Add table, chart, shape, hyperlinks;
  • Convert to other file format, such as PDF, XPS and Image;
  • Animation.

Welcome to have a check on free Spire.Presentation to confirm it meets your needs on processing the PowerPoint documents from code. I believe you will be impressed by this easy-to-use presentation API.
Page copy protected against web site content infringement by Copyscape

About the Author

Ashokst
Full Name: Ashok ST
Member Level: Starter
Member Status: Member
Member Since: 7/20/2015 11:56:55 PM
Country: India



Login to vote for this post.

Comments or Responses

Posted by: Soniaturner on: 11/24/2015 | Points: 25
This is my first time I visit here. I found much enjoyable things in your blog, especially its discussion. I think you would be hard pressed to find someone with the same constancy I have had over the years so I am happy with that.
admission essay writing service http://www.clazwork.com/
Posted by: Jimmymeraz on: 12/7/2015 | Points: 25
Thank you for this tutorial.This post is very useful for all students and business individuals Now anyone can get creative power point presentation help here http://essaywriting.com.pk/power-point-presentation/

Login to post response

Comment using Facebook(Author doesn't get notification)