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
Monday, 11 November 2024 02:56

C#: Insert Watermarks into PowerPoint Slides

Inserting text watermarks into PowerPoint presentations is an effective way to protect intellectual property and ensure content authenticity of these documents. Spire.Presentation for .NET provides a powerful and flexible way to programmatically add text watermarks to PowerPoint slides. Unlike PowerPoint's built-in features, this approach allows for batch processing, precise control over watermark placement and appearance, and integration into larger .NET applications.

This article will demonstrate how to insert text watermarks to PowerPoint presentations with C# using the Spire.Presentation for .NET library.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Insert a Single Watermark into PowerPoint Slides

Using Spire.Presentation for .NET, developers can add a single text watermark to a PowerPoint presentation by creating a locked transparent text box with the watermark in a custom style on each page. The detailed steps are as follows:

  • Create an instance of Presentation class and load a PowerPoint file using Presentation.LoadFromFile() method.
  • Define the watermark text, create a Font object, and measure the size of the text.
  • Get the size of the slides in the presentation through Presentation.SlideSize.Size property.
  • Create a RectangleF object based on the text size and the slide size.
  • Iterate through the slides in the presentation:
    • Create an IAutoShape object on each slide at the position of the rectangle using ISlide.Shapes.AppendShape() method.
    • Set the style of the shape using the properties under IAutoShape class.
    • Add the watermark text to the shape through IAutoShape.TextFrame.Text property.
    • Get the watermark text as a TextRange object through IAutoShape.TextFrame.TextRange property.
    • Set the format of the watermark text through the properties under TextRange class.
  • Save the presentation using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace SingleTextWatermarkPowerPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of Presentation
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("Sample.pptx");

            // Define the watermark text and create a font for it
            string text = "Example";
            // Create a font object
            Font font = new Font("Arial", 50);
            // Measure the size of the watermark text
            Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
            SizeF size = graphics.MeasureString(text, font);

            // Get the slide size
            SizeF slideSize = presentation.SlideSize.Size;

            // Create a retangle based on the text size and page size
            RectangleF rect = new RectangleF((slideSize.Width - size.Width) / 2, (slideSize.Height - size.Height) /2, size.Width, size.Height);

            // Iterate through the slides in the presentation
            foreach (ISlide slide in presentation.Slides)
            {
                // Create a shape of watermark on each slide
                IAutoShape watermark = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                // Set the style of the watermark
                watermark.Fill.FillType = FillFormatType.None;
                watermark.ShapeStyle.LineColor.Color = Color.Empty;
                watermark.Rotation = -45;
                watermark.Locking.SelectionProtection = true;
                watermark.Line.FillType = FillFormatType.None;
                // Add the watermark text to the shape
                watermark.TextFrame.Text = text;
                // Set the style of the watermark text
                TextRange textRange = watermark.TextFrame.TextRange;
                textRange.Fill.FillType = FillFormatType.Solid;
                textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                textRange.FontHeight = 50;
            }

            // Save the presentation
            presentation.SaveToFile("output/PowerPointSingleTextWatermark.pptx", FileFormat.Auto);
            presentation.Dispose();
        }
    }
}

Single Text Watermark in PowerPoint Slides

Insert Repeated Watermarks into PowerPoint Slides

Developers can insert repeated text watermarks into slides by drawing multiple identical text watermarks at specified intervals on the slides. Here are the detailed steps:

  • Create an instance of Presentation class and load a PowerPoint file using Presentation.LoadFromFile() method.
  • Define the watermark text, create a Font object, and measure the size of the text.
  • Get the size of the slides in the presentation through Presentation.SlideSize.Size property.
  • Iterate through the slides in the presentation:
    • Define the start position and the intervals.
    • Add watermark shapes and text and set their format.
    • Move the lateral position to the next interval on the row after finishing adding a watermark.
    • Move the vertical position to the next row after finishing adding the watermarks of each row.
  • Save the presentation using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation.Drawing;
using Spire.Presentation;
using System.Drawing;

namespace RepeatedTextWatermarkPowerPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of Presentation
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("Sample.pptx");

            // Define the watermark text and create a font for it
            string text = "Example";
            // Create a font object
            Font font = new Font("Arial", 20);
            // Measure the size of the watermark text
            Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
            SizeF size = graphics.MeasureString(text, font);

            // Get the slide size
            SizeF slideSize = presentation.SlideSize.Size;

            // Iterate through the slides in the presentation
            foreach (ISlide slide in presentation.Slides)
            {
                float x = 30;
                float y = 80;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // Create a rectangle
                        RectangleF rect = new RectangleF(x, y, size.Width, size.Height);
                        IAutoShape watermark = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                        // Set the style of the watermark
                        watermark.Fill.FillType = FillFormatType.None;
                        watermark.ShapeStyle.LineColor.Color = Color.Empty;
                        watermark.Rotation = -45;
                        watermark.Locking.SelectionProtection = true;
                        watermark.Line.FillType = FillFormatType.None;
                        // Add the watermark text to the shape
                        watermark.TextFrame.Text = text;
                        // Set the style of the watermark text
                        TextRange textRange = watermark.TextFrame.TextRange;
                        textRange.Fill.FillType = FillFormatType.Solid;
                        textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                        textRange.FontHeight = 20;
                        x += ((slideSize.Width - 60) / 3 + size.Width / 2);
                    }
                    x = 30;
                    y += ((slideSize.Height - 160) / 3 + size.Height / 2);
                }
            }

            // Save the presentation
            presentation.SaveToFile("output/PowerPointRepeatedTextWatermark.pptx", FileFormat.Auto);
            presentation.Dispose();
        }
    }
}

***

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Published in Watermark

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details