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.
- .NET API to Set Slide Background in PowerPoint
- Set Background Color of Normal Slides
- Set Background Color of Master Slide
- Gradient as Slide Background Color
- Set Image as Slide Background
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.
The following is the PowerPoint slide after setting the background.
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.
- First, load the PowerPoint presentation using Presentation class.
- Then, set the background of the master slide using Presentation.Masters[index].Background property.
- Finally, save the updated presentation using Presentation.Save(String, SaveFormat) method.
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.
- First, load the PowerPoint presentation using Presentation class.
- Set Presentation.Slides[index].Background.FillFormat.FillType property to FillType.Gradient.
- Set Presentation.Slides[index].Background.FillFormat.GradientFormat.TileFlip property to TileFlip.FlipBoth.
- Finally, save the updated presentation using Presentation.Save(String, SaveFormat) method.
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 Image as Slide Background using C#
The following are the steps to set an image as a slide background using C#.
- First, load the PowerPoint presentation using Presentation class.
- Set the background settings of the desired slide by specifying its index using Background property, e.g. background type, color, fill type, etc.
- Load the image into a System.Drawing.Image object.
- Add image to the presentation collection using Presentation.Images.AddImage(Image) and get its reference into an IPPImage object.
- Set image as background using Presentation.Slides[index].Background.FillFormat.PictureFillFormat.Picture.Image property.
- Finally, save the updated presentation using Presentation.Save(String, SaveFormat) method.
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.