I have an issue where I have text in the footer of my document but if I insert a watermark image which is the size of the page, it covers my disclaimer text which is in my footer. If I open the word document, and right click on the image and goto Order > Send Behind Text. Is there a way I can set this property from the background.
Private Shared Sub InsertWatermark(ByVal doc As Document, ByVal watermarkText As String)
Dim watermark As Aspose.Words.Drawing.Shape
If watermarkText = "Hart Logo" Then
watermark = New Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image)
watermark.ImageData.SetImage("d:\hart11dev\images\hartlogo.png")
watermark.Width = 550
watermark.Height = 750
watermark.Rotation = 0
ElseIf watermarkText > "" Then
watermark = New Aspose.Words.Drawing.Shape(doc, ShapeType.TextPlainText)
watermark.TextPath.Text = watermarkText
watermark.TextPath.FontFamily = "Calibri"
watermark.TextPath.Bold = True
watermark.Width = 600
watermark.Height = 200
watermark.Rotation = -40
watermark.Fill.Color = System.Drawing.Color.LavenderBlush
watermark.StrokeColor = System.Drawing.Color.LavenderBlush
End If
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page
watermark.WrapType = WrapType.None
watermark.VerticalAlignment = VerticalAlignment.Center
watermark.HorizontalAlignment = HorizontalAlignment.Center
Dim watermarkPara As New Aspose.Words.Paragraph(doc)
watermarkPara.AppendChild(watermark)
For Each sect As Aspose.Words.Section In doc.Sections
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderPrimary)
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderFirst)
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderEven)
Next sect
End Sub
Private Shared Sub InsertWatermarkIntoHeader(ByVal watermarkPara As Aspose.Words.Paragraph, ByVal sect As Aspose.Words.Section, ByVal headerType As Aspose.Words.HeaderFooterType)
Dim header As Aspose.Words.HeaderFooter = sect.HeadersFooters(headerType)
If header Is Nothing Then
header = New Aspose.Words.HeaderFooter(sect.Document, headerType)
sect.HeadersFooters.Add(header)
End If
header.AppendChild(watermarkPara.Clone(True))
End Sub
I also noticed another issue. All my fonts seem bold when a watermark is inserted. Attached is a watermark example with background image covering the footer text and a normal non watermark document. You can see the fonts all seem bold in the watermark document.
Hi Ryan,
Thanks for your inquiry.
You need to adjust the ZOrder of the watermark so it appears behind other images. You can do this by calling watermark.ZOrder = 0; You can also pass negative values if you find the image is still in front of the others.
Thanks,
Hi Ryan,
I cannot reproduce the issue with bold text after inserting the watermark. Are you able to relaibly test if this issue is happening when InsertWatermark is called and the issue does not occur when it’s not called? In that case could you post your code here which will allow us to reproduce the issue.
Thanks,
ZIndex is showing no effect… Here is my code. Watermark image is still overtop of footer text.
Private Shared Sub InsertWatermark(ByVal doc As Document, ByVal watermarkText As String)
Dim watermark As Aspose.Words.Drawing.Shape
If watermarkText = "Hart Logo" Then
watermark = New Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image)
watermark.ImageData.SetImage("d:\hart11dev\images\hartlogo.png")
watermark.Width = 550
watermark.Height = 750
watermark.Rotation = 0
watermark.ZOrder = -10000
ElseIf watermarkText > "" Then
watermark = New Aspose.Words.Drawing.Shape(doc, ShapeType.TextPlainText)
watermark.TextPath.Text = watermarkText
watermark.TextPath.FontFamily = "Calibri"
watermark.TextPath.Bold = True
watermark.Width = 600
watermark.Height = 200
watermark.Rotation = -40
watermark.Fill.Color = System.Drawing.Color.LavenderBlush
watermark.StrokeColor = System.Drawing.Color.LavenderBlush
End If
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page
watermark.WrapType = WrapType.None
watermark.VerticalAlignment = VerticalAlignment.Center
watermark.HorizontalAlignment = HorizontalAlignment.Center
Dim watermarkPara As New Aspose.Words.Paragraph(doc)
watermarkPara.AppendChild(watermark)
For Each sect As Aspose.Words.Section In doc.Sections
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderPrimary)
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderFirst)
InsertWatermarkIntoHeader(watermarkPara, sect, Aspose.Words.HeaderFooterType.HeaderEven)
Next sect
End Sub
Private Shared Sub InsertWatermarkIntoHeader(ByVal watermarkPara As Aspose.Words.Paragraph, ByVal sect As Aspose.Words.Section, ByVal headerType As Aspose.Words.HeaderFooterType)
Dim header As Aspose.Words.HeaderFooter = sect.HeadersFooters(headerType)
If header Is Nothing Then
header = New Aspose.Words.HeaderFooter(sect.Document, headerType)
sect.HeadersFooters.Add(header)
End If
header.AppendChild(watermarkPara.Clone(True))
End Sub
Hi
Thanks for your request. Maybe you should just set BehindText property of the watermark shape:
https://reference.aspose.com/words/net/aspose.words.drawing/shapebase/behindtext/
Hope this helps.
Best regards,
I just decreased the size of my watermark image by 50 pixels so it doesn’t extend into the disclaimer until the ZOrder issue is figured out.
The bolding is odd. The fonts look bolder on the screen, but print normally so I guess the watermark bolding issue might not be an issue.
watermark.BehindText = true worked great.