Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 1, 2021 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/c06df204f6d0031eaee4451f9f1e798b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c06df204f6d0031eaee4451f9f1e798b to your computer and use it in GitHub Desktop.
Set Background of Slides in PowerPoint Presentations in C#
// 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);
}
// 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);
}
// 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);
}
// 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