Set Slide Background in PowerPoint Presentations using C#

In this article, you will learn how to set the background of slides in PowerPoint presentations programmatically using C#. Particularly, the article will cover how to set the background of normal slides as well as the master slide.

C# API to Set Slide Background in PowerPoint

In order to set or change the slides’ background in PowerPoint presentations, we will use Aspose.Slides for .NET. The API is designed to create, manipulate and convert PowerPoint and OpenOffice presentations. You can either download the API or install it using NuGet.

PM> Install-Package Aspose.Slides.NET

Set Background Color of Normal Slides in C#

The following are the steps to set the background color of the normal slides in a PowerPoint presentation using C#.

  • First, load the PowerPoint presentation using Presentation class.
  • Then, set the background of the desired slide by specifying its index using Background property, e.g. background type, color, fill type, etc.
  • Finally, save the updated presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to set the background of a slide in a PowerPoint presentation.

Below is the screenshot of the slide before setting the background.

PowerPoint Presentation

The following is the PowerPoint slide after setting the background.

Set Background of Slide in C#

Set Background Color of Master Slide in C#

You can also set the background of the master slide that will affect all the slides in the presentation. The following are the steps to change the background color of the master slide.

The following code sample shows how to change the background of the master slide in PowerPoint.

Set Gradient Background Color of Slides

You can also set the gradient background color of the slides using Aspose.Slides for .NET, as demonstrated in the steps below.

The following code sample shows how to set the gradient background color of the slides in PowerPoint.

The following screenshot shows the gradient background of the slide.

Set Gradient Background of Slide in C#

Set Image as Slide Background using C#

The following are the steps to set an image as a slide background using C#.

The following code sample shows how to set an image as the background of slides in a PowerPoint presentation.

Get a Free API License

You can use Aspose.Slides for .NET without evaluation limitations by requesting a temporary license.

Conclusion

In this article, you have learned how to set the background of slides in PowerPoint PPTX or PPT using C#. Furthermore, you have seen how to set gradient or image background of the PowerPoint presentations. You can visit the documentation to explore other features of Aspose.Slides for .NET. Also, you can feel free to let us know about your queries via our forum.

See Also