Split PowerPoint Document into Individual Slides in C#

When we deal with a large PowerPoint document, we may need to split the document to small presentations, each of which contains one original slide. In this article, you will learn how to split a PowerPoint document into individual slides using .NET Presentation API, the free Spire.Presentation.

The method in this solution is as below:

  • Create a new PowerPoint document, remove the default blank slide.
  • Clone the specified the slide from source presentation to the new one.

Using Code

using Spire.Presentation;

 

namespace SplitPresentation

{

    class Program

    {

        static void Main(string[] args)

        {

            //load source PowerPoint file

            Presentation ppt = new Presentation();

            ppt.LoadFromFile(“sample.pptx”);

 

            for (int i = 0; i < ppt.Slides.Count; i++)

            {

                //initialize new instance of Presentation class

                Presentation newppt = new Presentation();

                //remove blank slide

                newppt.Slides.RemoveAt(0);

                //clone slide from source file to new document

                newppt.Slides.Append(ppt.Slides[i]);

                //save the file

                newppt.SaveToFile(String.Format(“result-{0}.pptx”, i), FileFormat.Pptx2010);

            }

 

        }

    }

Output

After running the code, the sample file that contains three slides will be split into three presentation files as below.

output

Advertisements