Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
using Syncfusion.Presentation;
// Create a ZIP archive and set the compression level to Best.
using Syncfusion.Presentation;
using Syncfusion.Compression.Zip;

//Opens the source PPTX document.
ZipArchive zipArchive = new ZipArchive();
zipArchive.DefaultCompressionLevel = Syncfusion.Compression.CompressionLevel.Best;

// Open the source PowerPoint presentation.
IPresentation sourcePptx = Presentation.Open(Path.GetFullPath(@"Data/Template.pptx"));

//Iterates through each section.
// Iterate through each section in the presentation.
foreach (ISection section in sourcePptx.Sections)
{
//Creates a destination PPTX document. Existing presentations can also be used here.
// Create a new destination presentation for the current section.
IPresentation destinationPptx = Presentation.Create();
// Clone the slides from the section and move to new PPTX document.

// Clone all slides from the current section and add them to the new presentation.
foreach (ISlide slide in section.Slides)
{
destinationPptx.Slides.Add(slide.Clone(), PasteOptions.SourceFormatting, sourcePptx);
}
//Saves the destination PPTX document.
string outputPath = Path.Combine(Path.GetFullPath("Output"), section.Name + "_Slides.pptx");
destinationPptx.Save(outputPath);
// Save the section presentation to a memory stream.
MemoryStream memoryStream = new MemoryStream();
destinationPptx.Save(memoryStream);

// Add the generated presentation to the ZIP archive with the section name as the file name.
string outputPath = Path.Combine(section.Name + "_Slides.pptx");
zipArchive.AddItem(outputPath, memoryStream, true, Syncfusion.Compression.FileAttributes.Normal);

// Close the destination presentation.
destinationPptx.Close();
}
//Closes the PPTX document.

// Save the ZIP archive containing all section presentations.
zipArchive.Save(Path.GetFullPath(@"Output/Split-PowerPoint-by-sections.zip"));
// Close the ZIP archive.
zipArchive.Close();
// Close the source presentation.
sourcePptx.Close();
Loading