How to add text watermark in PowerPoint document

There are two kinds of watermarks in PowerPoint documents we usually used in presentation slides: text watermark and image watermark. By using Spire.Presentation, developers can easily add the watermarks to the presentation slides. This section will show you how to add text watermark in PowerPoint document in C#.

Firstly, please check the effective screenshot of the text watermark in PowerPoint file added by Spire.Presentation.

***

Here comes to the steps of how to add text watermark in C#:

Step 1: Create a presentation document and load the document from the file

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");

Step 2: Get the size of watermark string

Font stringFont = new Font("Arial", 45);
Size size = TextRenderer.MeasureText("E-iceblue", stringFont);

Step 3: Add a rectangle shape with the defined rectangle range

RectangleF rect = new RectangleF((presentation.SlideSize.Size.Width - size.Width) / 2, (presentation.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);

Step 4: Set the style for the shape

shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -45;
shape.Locking.SelectionProtection = true;
shape.Line.FillType = FillFormatType.None;

Step 5: Add text to the shape and set the style of the text range

shape.TextFrame.Text = "E-iceblue";
TextRange textRange = shape.TextFrame.TextRange;
//set the style of the text range
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.Black);
textRange.FontHeight = 45;

Step 6: Save the document to file

presentation.SaveToFile("result.pptx",FileFormat.Pptx2007);

Full codes:

{
Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");
//Get the size of watermark string
Font stringFont = new Font("Arial", 45);
Size size = TextRenderer.MeasureText("E-iceblue", stringFont);
//Define a rectangle range
RectangleF rect = new RectangleF((presentation.SlideSize.Size.Width - size.Width) / 2, (presentation.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
//Add a rectangle shape with a defined range
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
//Set the style of shape
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -45;
shape.Locking.SelectionProtection = true;
shape.Line.FillType = FillFormatType.None;
//add text to shape
shape.TextFrame.Text = "E-iceblue";
TextRange textRange = shape.TextFrame.TextRange;
//set the style of the text range
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.Black);
textRange.FontHeight = 45;

presentation.SaveToFile("result.pptx",FileFormat.Pptx2007);
}