Tuesday, 23 February 2021 07:30

Add multiple watermarks in presentation slides

Spire.Presentation supports to insert text watermark and image watermark to PowerPoint document. This article will show you how to use Spire.Presentation to add multiple watermarks to the presentation slides in C#/VB.NET.

C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WatermarkDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PPT document and load file
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Sample.pptx");

            //Get the size of the watermark string
            Font font = new Font("Arial", 20);
            String watermarkText = "E-iceblue";
            SizeF size = TextRenderer.MeasureText("E-iceblue", font);
            float x = 30;
            float y = 80;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //Define a rectangle range
                    RectangleF rect = new RectangleF(x, y, 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 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;

                    //Add text to the shape
                    shape.TextFrame.Text = watermarkText;
                    TextRange textRange = shape.TextFrame.TextRange;
                    //Set the style of the text range
                    textRange.Fill.FillType = FillFormatType.Solid;
                    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                    textRange.EastAsianFont = new TextFont(font.Name);
                    textRange.FontHeight = font.Size;

                    x += (100 + size.Width);
                }
                x = 30;
                y += (100 + size.Height);
            }

            //Save the document
            presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010);

        }
    }
}
VB.NET
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace WatermarkDemo
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Create a PPT document and load file
            Dim presentation As Presentation = New Presentation
            presentation.LoadFromFile("Sample.pptx")
            'Get the size of the watermark string
            Dim font As Font = New Font("Arial", 20)
            Dim watermarkText As String = "E-iceblue"
            Dim size As SizeF = TextRenderer.MeasureText("E-iceblue", font)
            Dim x As Single = 30
            Dim y As Single = 80
            Dim i As Integer = 0
            Do While (i < 3)
                Dim j As Integer = 0
                Do While (j < 3)
                    'Define a rectangle range
                    Dim rect As RectangleF = New RectangleF(x, y, size.Width, size.Height)
                    'Add a rectangle shape with a defined range
                    Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect)
                    'Set the style of 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
                    'Add text to the shape
                    shape.TextFrame.Text = watermarkText
                    Dim textRange As TextRange = shape.TextFrame.TextRange
                    'Set the style of the text range
                    textRange.Fill.FillType = FillFormatType.Solid
                    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink)
                    textRange.EastAsianFont = New TextFont(font.Name)
                    textRange.FontHeight = font.Size
                    x = (x + (100 + size.Width))
                    j = (j + 1)
                Loop
                
                x = 30
                y = (y + (100 + size.Height))
                i = (i + 1)
            Loop
            
            'Save the document
            presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010)
        End Sub
    End Class
End Namespace

Output:

Add multiple watermarks in presentation slides

Published in Watermark

We have demonstrated how to use Spire.Presentation to add text watermark and image watermark to the presentation slides. This article will show how to remove text and image watermarks in presentation slides in C#.

Firstly, view the sample document contains the text and image watermark.

Remove text and image watermarks in presentation slides

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

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Step 2: Remove the text and image watermark.

Remove text watermark by removing the shape with contains the text string "Confidential".

for (int i = 0; i < ppt.Slides.Count; i++)
{
    for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
    {
        if (ppt.Slides[i].Shapes[j] is IAutoShape)
        {
            IAutoShape shape = ppt.Slides[i].Shapes[j] as IAutoShape;
            if (shape.TextFrame.Text.Contains("Confidential"))
            {
                ppt.Slides[i].Shapes.Remove(shape);
            }
        }
    }
}

Remove image watermark by setting SlideBackground.Fill.FillType as none.

for (int i = 0; i < ppt.Slides.Count; i++)
{
    ppt.Slides[i].SlideBackground.Fill.FillType = FillFormatType.None;
}

Step 3: Save the document to file.

ppt.SaveToFile("RemoveWartermark.pptx", FileFormat.Pptx2013);

Effective screenshot after removing the text and image watermark:

Remove text and image watermarks in presentation slides

Remove text and image watermarks in presentation slides

Full codes:

Remove text watermark in presentation slides:

using Spire.Presentation;
namespace RemoveWatermark
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

            for (int i = 0; i < ppt.Slides.Count; i++)
            {
                for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
                {
                    if (ppt.Slides[i].Shapes[j] is IAutoShape)
                    {
                        IAutoShape shape = ppt.Slides[i].Shapes[j] as IAutoShape;
                        if (shape.TextFrame.Text.Contains("Confidential"))
                        {
                            ppt.Slides[i].Shapes.Remove(shape);
                        }
                    }
                }
            }
            ppt.SaveToFile("RemoveTextWartermark.pptx", FileFormat.Pptx2013);
        }
    }

Remove image watermark in presentation slides:

using Spire.Presentation;
using Spire.Presentation.Drawing;
namespace RemoveWatermark
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample2.pptx", FileFormat.Pptx2013);

            for (int i = 0; i < ppt.Slides.Count; i++)
            {
                ppt.Slides[i].SlideBackground.Fill.FillType = FillFormatType.None;
            }

            ppt.SaveToFile("RemovePicWatermak.pptx", FileFormat.Pptx2013);

        }
    }
}
Published in Watermark

There are two kinds of watermarks in PowerPoint documents we usually used in presentation slides: text watermark and image watermark. Text watermark and image watermark are used to make the presentation slides more attractive and shows the copyright information of the presentation slides. We have already shown you how to add text watermark to presentation slides, this section will show you how to add image watermark in PowerPoint document in C#.

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

How to add image watermark in presentation slides

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 ppt = new Presentation();
ppt.LoadFromFile("sample.pptx");

Step 2: Set the image background type and style for the second slide in the presentation.

ppt.Slides[1].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[1].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

Step 3: Insert the image as the image watermark.

Image img= Image.FromFile ("logo.png");
IImageData image = ppt.Images.Append(img);
ppt.Slides[1].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

Step 4: Save the document.

ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2007);

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("sample.pptx");

            ppt.Slides[1].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[1].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

            Image img = Image.FromFile("logo.png");
            IImageData image = ppt.Images.Append(img);
            ppt.Slides[1].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
            ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2007);
        }
    }
}
Published in Watermark

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.

How to add image watermark in PowerPoint document in C#

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);
        }
    }
}
Published in Watermark

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:

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddTextWatermark
{

    class Program
    {

        static void Main(string[] args)
        {
            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);
        }
    }
}
Published in Watermark