Spire.Presentation offer developers an easy way to add the watermarks to the presentation slides. There are two kinds of watermarks in PowerPoint documents: text watermark and image watermark. We'll learn how to add image watermark in PowerPoint document via Spire.Presentation.
The goal of the article is to make an image as a background img watermark as following screenshot.
Here comes to the steps of how to add image watermarks in C#:
Step 1: Create a presentation document and load the document from the file
Presentation ppt = new Presentation(); ppt.LoadFromFile(fileName);
Step 2: Get the image you want to add as image watermark.
IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));
Step 3: Set the properties of SlideBackground, and then fill the image as watermark.
ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom; ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture; ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType=PictureFillType.Stretch; ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
step4: Save the document to a new file.
ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);
Full codes:
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace AddimageWatermark { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile(fileName); IImageData image = ppt.Images.Append(Image.FromFile("Header.png")); ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom; ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture; ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch; ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; if (fileExtensions == ".ppt") { ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT); } else { ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.Pptx2007); } Viewer(resultFileName); } } }