Adding watermark to images inside a document

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

On this page

The most of the document formats allow you to place images inside a document. If you want to add watermark to images inside a document then it can be possible using GroupDocs.Watermark. Following are the steps to add watermark to the images of any document.

  1. Load the document
  2. Create and initialize watermark object
  3. Set watermark properties
  4. Find images in the document
  5. Add watermark to all found images
  6. Save the document

AdvancedUsage.AddingWatermarks.AddWatermarksToImages.AddWatermarkToImagesInsideDocument

// Specify an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"
using (Watermarker watermarker = new Watermarker("document.pdf"))
{
    // Initialize text watermark
    TextWatermark textWatermark = new TextWatermark("Protected image", new Font("Arial", 8));
    textWatermark.HorizontalAlignment = HorizontalAlignment.Center;
    textWatermark.VerticalAlignment = VerticalAlignment.Center;
    textWatermark.RotateAngle = 45;
    textWatermark.SizingType = SizingType.ScaleToParentDimensions;
    textWatermark.ScaleFactor = 1;

    // Initialize image watermark
    using (ImageWatermark imageWatermark = new ImageWatermark("protect.jpg"))
    {
        imageWatermark.HorizontalAlignment = HorizontalAlignment.Center;
        imageWatermark.VerticalAlignment = VerticalAlignment.Center;
        imageWatermark.RotateAngle = -45;
        imageWatermark.SizingType = SizingType.ScaleToParentDimensions;
        imageWatermark.ScaleFactor = 1;

        // Find all images in a document
        WatermarkableImageCollection images = watermarker.GetImages();
        for (int i = 0; i < images.Count; i++)
        {
            if (images[i].Width > 100 && images[i].Height > 100)
            {
                if (i % 2 == 0)
                {
                    images[i].Add(textWatermark);
                }
                else
                {
                    images[i].Add(imageWatermark);
                }
            }
        }
    }

    watermarker.Save("document.pdf");
}

On this page