Hello,
I’m trying to add watermark to a Word file, watermark gets added but is not visible if there is an image on the page. the watermark is behind the image. I want it to be visible all the time no matter what content the word document has.
I’ve tried setting ZOrder to 1000 but it did not work.
Also opacity is not working. it is not changing the opacity level.
Sub InsertWatermarkText(ByVal doc As Aspose.Words.Document, ByVal watermarkText As String)
’ Create a watermark shape. This will be a WordArt shape.
’ You are free to try other shape types as watermarks.
'Dim watermark As New Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText)
Dim watermark As New Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image)
’ Set up the text of the watermark.
'watermark.TextPath.Text = watermarkText
watermark.ImageData.SetImage(docDir & "watermark.jpg")
watermark.TextPath.FontFamily = "Arial"
watermark.Width = 200
watermark.Height = 200
’ Text will be directed from the bottom-left to the top-right corner.
watermark.Rotation = -40
’ Remove the following two lines if you need a solid black text.
watermark.Fill.Color = System.Drawing.Color.Blue ’ Try LightGray to get more Word-style watermark
watermark.StrokeColor = System.Drawing.Color.Gray ’ Try LightGray to get more Word-style watermark
watermark.AllowOverlap = True
watermark.BehindText = False
watermark.Fill.Opacity = 0.5
watermark.ZOrder = 1000
’ Place the watermark in the page center.
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page
watermark.WrapType = WrapType.None
watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center
watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center
’ Create a new paragraph and append the watermark to this paragraph.
Dim watermarkPara As New Aspose.Words.Paragraph(doc)
watermarkPara.AppendChild(watermark)
’ Insert the watermark into all headers of each document section.
For Each sect As Section In doc.Sections
’ There could be up to three different headers in each section, since we want
’ the watermark to appear on all pages, insert into all headers.
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary)
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst)
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven)
Next sect
End Sub
thank you.