A slide master is the top slide that stores the information about the theme and slide layouts, which will be inherited by other slides in the presentation. In other words, when you modify the style of slide master, every slide in the presentation will be changed accordingly, including the ones added later.
This quality makes it possible that when you want to insert an image or watermark to every slide, you only need to insert the image in slide master. In this article, you'll learn how to add an image to slide master using Spire.Presenation in C#, VB.NET.
Screenshot of original file:
Detailed Steps:
Step 1: Initialize a new Presentation and load the sample file
Presentation presentation = new Presentation(); presentation.LoadFromFile(@"sample.pptx");
Step 2: Get the master collection.
IMasterSlide master = presentation.Masters[0];
Step 3: Insert an image to slide master.
String image = @"logo.png"; RectangleF rff = new RectangleF(40, 40, 100, 80); IEmbedImage pic=master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rff); pic.Line.FillFormat.FillType = FillFormatType.None;
Step 4: Add a new blank slide to the presentation.
presentation.Slides.Append();
Step 5: Save and launch the file.
presentation.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx");
Output:
Full Code:
using Spire.Presentation; using Spire.Presentation.Drawing; using System; using System.Drawing; namespace AddImage { class Program { static void Main(string[] args) { //initialize a new Presentation and load the sample file Presentation presentation = new Presentation(); presentation.LoadFromFile(@"sample.pptx"); //get the master collection IMasterSlide master = presentation.Masters[0]; //append image to slide master String image = @"logo.png"; RectangleF rff = new RectangleF(40, 40, 100, 80); IEmbedImage pic = master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rff); pic.Line.FillFormat.FillType = FillFormatType.None; //add new slide to presentation presentation.Slides.Append(); //save and launch the file presentation.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx"); } } }
Imports Spire.Presentation Imports Spire.Presentation.Drawing Imports System.Drawing Namespace AddImage Class Program Private Shared Sub Main(args As String()) 'initialize a new Presentation and load the sample file Dim presentation As New Presentation() presentation.LoadFromFile("sample.pptx") 'get the master collection Dim master As IMasterSlide = presentation.Masters(0) 'append image to slide master Dim image As [String] = "logo.png" Dim rff As New RectangleF(40, 40, 100, 80) Dim pic As IEmbedImage = master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rff) pic.Line.FillFormat.FillType = FillFormatType.None 'add new slide to presentation presentation.Slides.Append() 'save and launch the file presentation.SaveToFile("result.pptx", FileFormat.Pptx2010) System.Diagnostics.Process.Start("result.pptx") End Sub End Class End Namespace