Learn how to change the background color of PowerPoint presentations programmatically using C#: https://blog.aspose.com/2021/08/31/set-background-in-powerpoint-using-csharp/
Last active
September 1, 2021 06:08
-
-
Save aspose-com-gists/c06df204f6d0031eaee4451f9f1e798b to your computer and use it in GitHub Desktop.
Set Background of Slides in PowerPoint Presentations in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate the Presentation class that represents the presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Set the background color of the Master ISlide to Forest Green | |
pres.Masters[0].Background.Type = BackgroundType.OwnBackground; | |
pres.Masters[0].Background.FillFormat.FillType = FillType.Solid; | |
pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen; | |
// Save presentation | |
pres.Save("SetSlideBackgroundMaster_out.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate the Presentation class that represents the presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Set the background color of the first ISlide to Blue | |
pres.Slides[0].Background.Type = BackgroundType.OwnBackground; | |
pres.Slides[0].Background.FillFormat.FillType = FillType.Solid; | |
pres.Slides[0].Background.FillFormat.SolidFillColor.Color = Color.Blue; | |
// Save presentation | |
pres.Save("ContentBG_out.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate the Presentation class that represents the presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Apply Gradiant effect to the Background | |
pres.Slides[0].Background.Type = BackgroundType.OwnBackground; | |
pres.Slides[0].Background.FillFormat.FillType = FillType.Gradient; | |
pres.Slides[0].Background.FillFormat.GradientFormat.TileFlip = TileFlip.FlipBoth; | |
// Save presentation | |
pres.Save("ContentBG_Grad_out.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate the Presentation class that represents the presentation file | |
using (Presentation pres = new Presentation("SetImageAsBackground.pptx")) | |
{ | |
// Set the background with Image | |
pres.Slides[0].Background.Type = BackgroundType.OwnBackground; | |
pres.Slides[0].Background.FillFormat.FillType = FillType.Picture; | |
pres.Slides[0].Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch; | |
// Set the picture | |
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(dataDir + "Tulips.jpg"); | |
// Add image to presentation's images collection | |
IPPImage imgx = pres.Images.AddImage(img); | |
pres.Slides[0].Background.FillFormat.PictureFillFormat.Picture.Image = imgx; | |
// Save the presentation | |
pres.Save("ContentBG_Img_out.pptx", SaveFormat.Pptx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment