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