Hi
I am using VB.NET and I am trying to create a watermark on a existing document that has a header and footer. I looked through the forums and found the following post:
"Shape behind text per-page" by dchipping on 02-21-2007, 3:53 PM
This seems to be what I am looking for but I am not getting the expected results. I had to convert the code from C# to VB and according to my knowledge it should be correct. When I run this code it creates the text in the middle of the page as normal text, not the expected watermark and it creates the same text in a paragraph after the header.
The shape that should be the watermark is blank on my document and I loose the existing header and footer.
Here is my code:
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim doc As New Document("C:\mydoc.doc")
InsertWatermark(doc, "Some Text", "Some Text")
doc.Save("C:\mydoc.doc", SaveFormat.Doc)
End Sub
'=========================================================================================
Private Shared Sub InsertWatermark(ByVal doc As Document, ByVal text As String, ByVal html As String)
Dim builder As New DocumentBuilder(doc)
builder.MoveToDocumentEnd()
'move to document end
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary)
'Move to header
'Prepare and insert watermark
Dim shape As New Shape(doc, ShapeType.TextFadeRight)
With shape
.FillColor = Color.Black
.Rotation = 315
.Width = 400
.Height = 400
.WrapType = 3
.WrapSide = WrapSide.Both
.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center
.RelativeVerticalPosition = RelativeVerticalPosition.Page
.VerticalAlignment = VerticalAlignment.Center
End With
Dim para As New Paragraph(doc)
Dim run As New Run(doc)
Dim node As Node = builder.CurrentNode
run.Text = text
run.Font.Color = System.Drawing.Color.Red
para.AppendChild(run)
shape.BehindText = True
shape.PrependChild(para)
builder.InsertNode(shape)
'move to document end
builder.MoveToDocumentEnd()
'Insert text
builder.InsertHtml(html)
builder.InsertBreak(BreakType.SectionBreakNewPage)
builder.CurrentSection.DeleteHeaderFooterShapes()
builder.CurrentSection.HeadersFooters.LinkToPrevious(False)
End Sub
Please advise
Thanks