Watermark

Watermark (1)

Watermarks serve as subtle overlays placed on the slides, typically in the form of text or images, which can convey messages, copyright information, company logos, or other visual elements. By incorporating watermarks into your PowerPoint presentations, you can enhance professionalism, reinforce branding, and discourage unauthorized use or distribution of your material. In this article, you will learn how to add text or image watermarks to a PowerPoint document in Python using Spire.Presentation for Python.

Install Spire.Presentation for Python

This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.Presentation

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows

Add a Text Watermark to PowerPoint in Python

Unlike MS Word, PowerPoint does not have a built-in feature that allows to apply watermarks to each slide. However, you can add a shape with text or an image to mimic the watermark effect. A shape can be added to a slide using the ISlide.Shapes.AppendShape() method, and the text of the shape can be set through the IAutoShape.TextFrame.Text property. To prevent the shape from overlapping the existing content on the slide, you'd better send it to the bottom.

The following are the steps to add a text watermark to a slide using Spire.Presentation for Python.

  • Create a Presentation object.
  • Load a PowerPoint file using Presentation.LoadFromFile() method.
  • Get a specific slide through Prentation.Slides[index] property.
  • Add a shape to the slide using ISlide.Shapes.AppendShape() method.
  • Add text to the shape through IAutoShape.TextFrame.Text property.
  • Send the shape to back using IAutoShape.SetShapeArrange() method.
  • Save the presentation to a PowerPoint file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint file
presentation.LoadFromFile("C:/Users/Administrator/Desktop/input.pptx")

# Define a rectangle
left = (presentation.SlideSize.Size.Width - 350.0) / 2
top = (presentation.SlideSize.Size.Height - 110.0) / 2
rect = RectangleF(left, top, 350.0, 110.0)

for i in range(0, presentation.Slides.Count):

    # Add a rectangle shape to
    shape = presentation.Slides[i].Shapes.AppendShape(
    ShapeType.Rectangle, rect)
    
    # Set the style of the shape
    shape.Fill.FillType = FillFormatType.none
    shape.ShapeStyle.LineColor.Color = Color.get_Transparent()
    shape.Rotation = -35
    shape.Locking.SelectionProtection = True
    shape.Line.FillType = FillFormatType.none

    # Add text to the shape
    shape.TextFrame.Text = "CONFIDENTIAL"
    textRange = shape.TextFrame.TextRange

    # Set the style of the text range
    textRange.Fill.FillType = FillFormatType.Solid
    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.get_Black().R, Color.get_HotPink().G, Color.get_HotPink().B)
    textRange.FontHeight = 45
    textRange.LatinFont = TextFont("Times New Roman")

    # Send the shape to back
    shape.SetShapeArrange(ShapeArrange.SendToBack)

# Save to file
presentation.SaveToFile("output/TextWatermark.pptx", FileFormat.Pptx2010)
presentation.Dispose()

Python: Add Text or Image Watermarks to PowerPoint

Add an Image Watermark to PowerPoint in Python

To add an image watermark, you need first to create a rectangle with the same size as an image. Then fill the shape with this image and place the shape at the center of a slide. To prevent the shape from overlapping the existing content on the slide, you need to send it to the bottom as well. The following are the steps to add an image watermark to a slide using Spire.Presentation for Python.

  • Create a Presentation object.
  • Load a PowerPoint file using Presentation.LoadFromFile() method.
  • Get a specific slide through Prentation.Slides[index] property.
  • Load an image using Presentation.Images.AppendStream() method.
  • Add a shape that has the same size with the image to the slide using ISlide.Shapes.AppendShape() method.
  • Fill the shape with the image through IAuotShape.Fill.PictureFill.Picture.EmbedImage property.
  • Send the shape to back using IAutoShape.SetShapeArrange() method.
  • Save the presentation to a PowerPoint file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint file
presentation.LoadFromFile("C:/Users/Administrator/Desktop/input.pptx")

# Load an image
stream = Stream("C:/Users/Administrator/Desktop/logo.png")
image = presentation.Images.AppendStream(stream)
stream.Close()

# Get width and height of the image
width = (float)(image.Width)
height = (float)(image.Height)

# 
slideSize = presentation.SlideSize.Size

# Loop through the slides in the presentation
for i in range(0, presentation.Slides.Count):

    # Get a specific slide
    slide = presentation.Slides[i]

    # Add a shape to slide
    shape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF((slideSize.Width - width )/2, (slideSize.Height - height)/2, width, height))

    # Fill the shape with image
    shape.Line.FillType = FillFormatType.none
    shape.Locking.SelectionProtection = True
    shape.Fill.FillType =  FillFormatType.Picture
    shape.Fill.PictureFill.FillType = PictureFillType.Stretch
    shape.Fill.PictureFill.Picture.EmbedImage = image

    # Send the shape to back
    shape.SetShapeArrange(ShapeArrange.SendToBack)

# Save to file
presentation.SaveToFile("output/ImageWatermark.pptx", FileFormat.Pptx2013)
presentation.Dispose()

Python: Add Text or Image Watermarks to PowerPoint

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.

page