Forums

Overview » VB .NET » How to Use VB.NET to Add Watermark in Word
Reply

How to Use VB.NET to Add Watermark in Word

Lemon Brown
Member



Since: 15 Sep 2011
Posts: 89
Posted 11 Jan 2012 04:53:59

In Word, watermark can be image or text. It is used to protect owners' copyright and show properties of this document, for example, add company name or "important", "secrect" as watermark in Word document. The following code shows how to add text watermark in Word by using VB.NET via Spire.Doc.

Imports System
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace watermark_2
	Partial Public Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			'Create word document
			Dim document As New Document()

			document.LoadFromFile("D:\Sample.doc")

			InsertWatermark(document)

			'Save doc file.
			document.SaveToFile("Sample.doc", FileFormat.Doc)

			'Launching the MS Word file.
			WordDocViewer("Sample.doc")

		End Sub

		Private Sub InsertWatermark(ByVal document As Document)

			Dim txtWatermark As New TextWatermark()
			txtWatermark.Text = "E-ICEBLUE"
			txtWatermark.FontSize = 70
			txtWatermark.Layout = WatermarkLayout.Diagonal
			document.Watermark = txtWatermark

		End Sub

		Private Sub WordDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub

	End Class
End Namespace

In Word, watermark can be image or text. It is used to protect owners' copyright and show properties of this document, for example, add company name or "important", "secrect" as watermark in Word document. The following code shows how to add text watermark in Word by using VB.NET via Spire.Doc.

Imports System
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace watermark_2
	Partial Public Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			'Create word document
			Dim document As New Document()

			document.LoadFromFile("D:\Sample.doc")

			InsertWatermark(document)

			'Save doc file.
			document.SaveToFile("Sample.doc", FileFormat.Doc)

			'Launching the MS Word file.
			WordDocViewer("Sample.doc")

		End Sub

		Private Sub InsertWatermark(ByVal document As Document)

			Dim txtWatermark As New TextWatermark()
			txtWatermark.Text = "E-ICEBLUE"
			txtWatermark.FontSize = 70
			txtWatermark.Layout = WatermarkLayout.Diagonal
			document.Watermark = txtWatermark

		End Sub

		Private Sub WordDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub

	End Class
End Namespace

Reply to this topic

Message
Reply
Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency