The background can be plain white, a solid or gradient color fill, pattern or a picture fill. A properly managed PPT document with suitable background style can give a different feeling to showing the content for its readers. Using Spire.Presentation for .NET, you can set the background style to add a color background for your presentation. You can also use a picture or a pattern for a slide background.
Spire.Presentation for .NET, a reliable .NET PPT component, enables you to generate, read, edit, convert even print your PPT documents without installing Microsoft PowerPoint on your machine. Using Spire.Presentation for .NET, you can set the background style of slides in your PPT document with C#, VB.NET. Please see the target PPT document with different background style of slides as below pictures:
There is a guide to introduce a method to set background of slides to achieve above screenshots with C#, VB.NET via Spire.Presentation for .NET.
The main steps of method are:
Step 1: Create a presentation with three slides.
Presentation presentation = new Presentation(); presentation.Slides.Append(); presentation.Slides.Append();
Step 2: Set the background of the first slide to Gradient color.
presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Gradient; presentation.Slides[0].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.LightGreen); presentation.Slides[0].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.White);
Step 3: Set the background of the second slide to Solid color
presentation.Slides[1].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Solid; presentation.Slides[1].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen;
Step 4: Set the background of the third slide to picture
string ImageFile = @"Data\bg.png"; RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height); presentation.Slides[2].SlideBackground.Fill.FillType = FillFormatType.Picture; IEmbedImage image = presentation.Slides[2].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect); presentation.Slides[2].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData;
Step 5: Save the document
presentation.SaveToFile("background.pptx", FileFormat.Pptx2010);
Download and install Spire.Presentation for .NET and use below code to experience this method to set background for slides in PPT document.
The full code:
using System.Drawing; using Spire.Presentation; using Spire.Presentation.Drawing; namespace backgroundc { class Program { static void Main(string[] args) { //create PPT document Presentation presentation = new Presentation(); //add new slide presentation.Slides.Append(); //add new slide presentation.Slides.Append(); //set the background of the first slide to Gradient color presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Gradient; presentation.Slides[0].SlideBackground.Fill.Gradient.GradientShape = GradientShapeType.Linear; presentation.Slides[0].SlideBackground.Fill.Gradient.GradientStyle = Spire.Presentation.Drawing.GradientStyle.FromCorner1; presentation.Slides[0].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.LightGreen); presentation.Slides[0].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.White); //set the background of the second slide to Solid color presentation.Slides[1].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Solid; presentation.Slides[1].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen; //set the background of the third slide to picture string ImageFile = @"Data\bg.png"; RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height); presentation.Slides[2].SlideBackground.Fill.FillType = FillFormatType.Picture; IEmbedImage image = presentation.Slides[2].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect); presentation.Slides[2].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData; IAutoShape shape; TextRange textRange; for (int i = 0; i < 3; i++) { shape = presentation.Slides[i].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 100)); shape.ShapeStyle.LineColor.Color = Color.White; shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None; shape.AppendTextFrame("Demonstrates to how to set the background style of slides."); //set the Font and fill style textRange = shape.TextFrame.TextRange; textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid; textRange.Fill.SolidColor.Color = Color.Black; textRange.LatinFont = new TextFont("Arial Black"); } //save the document presentation.SaveToFile("background.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("background.pptx"); } } }
Imports System.Drawing Imports Spire.Presentation Imports Spire.Presentation.Drawing Module Module1 Sub Main() 'create PPT document Dim presentation As New Presentation() 'add new slide presentation.Slides.Append() 'add new slide presentation.Slides.Append() 'set the background of the first slide to Gradient color presentation.Slides(0).SlideBackground.Type = BackgroundType.[Custom] presentation.Slides(0).SlideBackground.Fill.FillType = FillFormatType.Gradient presentation.Slides(0).SlideBackground.Fill.Gradient.GradientShape = GradientShapeType.Linear presentation.Slides(0).SlideBackground.Fill.Gradient.GradientStyle = Spire.Presentation.Drawing.GradientStyle.FromCorner1 presentation.Slides(0).SlideBackground.Fill.Gradient.GradientStops.Append(1.0F, KnownColors.LightGreen) presentation.Slides(0).SlideBackground.Fill.Gradient.GradientStops.Append(0.0F, KnownColors.White) 'set the background of the second slide to Solid color presentation.Slides(1.SlideBackground.Type = BackgroundType.[Custom] presentation.Slides(1).SlideBackground.Fill.FillType = FillFormatType.Solid presentation.Slides(1).SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen ‘set the background of the third slide to picture Dim ImageFile As String = "bg.png" Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height) presentation.Slides(2).SlideBackground.Type = BackgroundType.[Custom] presentation.Slides(2).SlideBackground.Fill.FillType = FillFormatType.Picture Dim image As IEmbedImage = presentation.Slides(2).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect) presentation.Slides(2).SlideBackground.Fill.PictureFill.Picture.EmbedImage = TryCast(image, IImageData) Dim shape As IAutoShape Dim textRange As TextRange For i As Integer = 0 To 3 shape = presentation.Slides(i).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 600, 100)) shape.ShapeStyle.LineColor.Color = Color.White shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None shape.AppendTextFrame("Demonstrates to how to set the background style of slides.") 'set the Font and fill style textRange = shape.TextFrame.TextRange textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid textRange.Fill.SolidColor.Color = Color.Black textRange.LatinFont = New TextFont("Arial Black") Next 'save the document presentation.SaveToFile("background.pptx", FileFormat.Pptx2010) System.Diagnostics.Process.Start("background.pptx") End Sub End Module
If you couldn't successfully use the Spire.presentation, please refer the Spire.Presentation Quick Start which can guide you quickly use the Spire.presentation.