I have a word doc that I am applying a watermark to. If I print the word doc directly, it shows up. When I run it thru a tiff converter the watermark is not there. Pls help.
Code following:
Protected Sub btnWatermk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWatermk.Click
Dim doc As New Document("C:\Data\Test1.doc")
InsertWatermarkText(doc, "CONFIDENTIAL")
doc.Save("C:\Data\TestWMk.doc")
Dim options As New ImageSaveOptions(SaveFormat.Tiff)
options.TiffCompression = TiffCompression.Ccitt4
doc.Save("C:\Data\TestWMk.tiff", options)
'Try
’ Dim opt2 As New ImageSaveOptions(SaveFormat.)
’ doc.Save("C:\Data\TestWMk.pdf", opt2)
'Catch ex As Exception
’ lblIncrement.Text = ex.Message
'End Try
End Sub
Protected Sub InsertWatermarkText(ByVal doc As 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 Shape(doc, ShapeType.TextPlainText)
’ Set up the text of the watermark.
watermark.TextPath.Text = watermarkText
watermark.TextPath.FontFamily = "Arial"
watermark.Width = 500
watermark.Height = 100
’ 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.Gray ’ Try LightGray to get more Word-style watermark
watermark.StrokeColor = System.Drawing.Color.Gray ’ Try LightGray to get more Word-style watermark
’ Place the watermark in the page center.
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page
watermark.WrapType = WrapType.None
watermark.VerticalAlignment = VerticalAlignment.Center
watermark.HorizontalAlignment = HorizontalAlignment.Center
’ Create a new paragraph and append the watermark to this paragraph.
Dim watermarkPara As New 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
Private Shared Sub InsertWatermarkIntoHeader(ByVal watermarkPara As Paragraph, ByVal sect As Section, ByVal headerType As HeaderFooterType)
Dim header As HeaderFooter = sect.HeadersFooters(headerType)
If header Is Nothing Then
’ There is no header of the specified type in the current section, create it.
header = New HeaderFooter(sect.Document, headerType)
sect.HeadersFooters.Add(header)
End If
’ Insert a clone of the watermark into the header.
header.AppendChild(watermarkPara.Clone(True))
End Sub