GroupDocsGists
10/19/2017 - 11:04 AM

AddWatermarkToImages.cs

// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-.NET
using (Document doc = Document.Load(Utilities.MapSourceFilePath (PptFilePath)))
{
    // 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(@"D:\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 = doc.FindImages();

        for (int i = 0; i < images.Count; i++)
        {
            if (images[i].Width > 100 && images[i].Height > 100)
            {
                if (i % 2 == 0)
                {
                    images[i].AddWatermark(textWatermark);
                }
                else
                {
                    images[i].AddWatermark(imageWatermark);
                }
            }
        }
    }
    doc.Save();
}