Add image watermarks

One of the main features of GroupDocs.Watermark is adding image watermarks to documents. You can add watermarks to documents or images from a local path, as well as from a stream. For a full list of supported formats, check Supported document formats.

Add an image watermark

To add an image watermark, follow these steps:

  1. Open the document by passing its path (or a stream) to the Watermarker class.
  2. Create an ImageWatermark from the watermark image file (or a stream).
  3. Position the watermark — for example, set horizontal_alignment, vertical_alignment, and opacity.
  4. Call add() to apply the watermark and save() to write the result.
from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import ImageWatermark
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment

def add_image_watermark():
    with Watermarker("./sample.docx") as watermarker:
        # Build an image watermark from a logo file and center it
        watermark = ImageWatermark("./logo.png")
        watermark.horizontal_alignment = HorizontalAlignment.CENTER
        watermark.vertical_alignment = VerticalAlignment.CENTER
        watermark.opacity = 0.7

        watermarker.add(watermark)
        watermarker.save("./output.docx")

if __name__ == "__main__":
    add_image_watermark()

sample.docx and logo.png are the sample files used in this example. Download sample.docx and logo.png.

Binary file (DOCX, 125 KB)

Download full output

What’s next

GroupDocs.Watermark offers more capabilities for image watermarks — loading from streams, scaling, tiling, and absolute or relative positioning. See Adding image watermarks in the advanced guide.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.