Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,59 @@
# Edit Presentation using C#

The [.NET PowerPoint library](https://www.syncfusion.com/document-sdk/net-powerpoint-library) (Presentation) enables you to create, read, and edit PowerPoint files programmatically without Microsoft Office or interop dependencies. Using this library, you can modify an existing PowerPoint presentation in C# — such as updating slide content, changing layouts, editing text, images, charts, and applying new styles.

## Steps to Edit an PowerPoint Presentation programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.Presentation.Net.Core](https://www.nuget.org/packages/Syncfusion.Presentation.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.Presentation;
using System.IO;
```

Step 4: Add the following code snippet in the Program.cs file to edit the PowerPoint presentation — update background, text, images, and table styles:

```csharp
//Opens the PPTX document.
using IPresentation pptxDoc = Presentation.Open(Path.GetFullPath(@"Data/Template.pptx"));

//Get the new background picture as a stream.
using FileStream bgPictureStream = new FileStream(Path.GetFullPath(@"Data/Background.png"), FileMode.Open);
//Create an instance for memory stream
using MemoryStream bgMemoryStream = new MemoryStream();
//Copy stream to memoryStream.
bgPictureStream.CopyTo(bgMemoryStream);

//Set the master slide background fill as Picture fill in PPTX document.
pptxDoc.Masters[0].Background.Fill.FillType = FillType.Picture;
pptxDoc.Masters[0].Background.Fill.PictureFill.ImageBytes = bgMemoryStream.ToArray();

//Get the first shape of the first slide from the PPTX document.
IShape shape = pptxDoc.Slides[0].Shapes[0] as IShape;
//Change the text of the shape.
if (shape.TextBody.Text == "Company History")
    shape.TextBody.Text = "Adventure Cycles History";

//Get the new picture as a stream.
using FileStream pictureStream = new FileStream(Path.GetFullPath(@"Data/AdventureCycles.png"), FileMode.Open);
//Create an instance for memory stream
using MemoryStream picMemoryStream = new MemoryStream();
//Copy stream to memoryStream.
pictureStream.CopyTo(picMemoryStream);

//Replace the existing image with the new image.
pptxDoc.Slides[0].Pictures[0].ImageData = picMemoryStream.ToArray();

//Changes the built in style of the table.
ITable table = pptxDoc.Slides[2].Tables[0];
table.BuiltInStyle = BuiltInTableStyle.ThemedStyle2Accent5;

//Save the PPTX document
pptxDoc.Save(Path.GetFullPath(@"Output/Output.pptx"));
```

More information about create an PowerPoint Presentation, you can be refer in this [documentation](https://help.syncfusion.com/document-processing/powerpoint/powerpoint-library/net/working-with-powerpoint-presentation) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Split Presentation using C#

The [.NET PowerPoint library](https://www.syncfusion.com/document-sdk/net-powerpoint-library) (Presentation) enables you to create, read, and edit PowerPoint files programmatically without Microsoft Office or interop dependencies. Using this library, you can **Split an PowerPoint Presentation** using C#.

## Steps to Split an PowerPoint Presentation programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.Presentation.Net.Core](https://www.nuget.org/packages/Syncfusion.Presentation.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.Presentation;
using Syncfusion.Compression.Zip;
```

Step 4: Add the following code snippet in Program.cs file to Split in the PowerPoint Presentation.

```csharp
ZipArchive zipArchive = new ZipArchive();
zipArchive.DefaultCompressionLevel = Syncfusion.Compression.CompressionLevel.Best;

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

// Iterate through each section in the presentation.
foreach (ISection section in sourcePptx.Sections)
{
// Create a new destination presentation for the current section.
IPresentation destinationPptx = Presentation.Create();

// 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);
}
// 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();
}

// 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();
```

More information about create an PowerPoint Presentation, you can be refer in this [documentation](https://help.syncfusion.com/document-processing/powerpoint/powerpoint-library/net/working-with-powerpoint-presentation) section.
Loading