usmanazizgroupdocs
4/17/2017 - 9:52 AM

Documents-AddWatermarkToImageShapesWordDocument.vb

' For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-.NET
Using doc As WordsDocument = Document.Load(Of WordsDocument)("D:\test.docx")
    Dim watermark As New TextWatermark("Protected image", New Font("Arial", 8))
    watermark.HorizontalAlignment = HorizontalAlignment.Center
    watermark.VerticalAlignment = VerticalAlignment.Center
    watermark.RotateAngle = 45
    watermark.SizingType = SizingType.ScaleToParentDimensions
    watermark.ScaleFactor = 1

    For Each section As WordsSection In doc.Sections
        For Each shape As WordsShape In section.Shapes
            ' Headers&Footers usually contains only service information.
            ' So, we skip images in headers/footers, expecting that they are probably watermarks or backgrounds
            If shape.HeaderFooter Is Nothing AndAlso shape.Image IsNot Nothing Then
                shape.Image.AddWatermark(watermark)
            End If
        Next
    Next
End Using