Insert Text Watermark to Word in WPF

2012-07-31 03:24:02 Written by  support iceblue
Rate this item
(0 votes)

Word watermark can be text or image, which appears behind document contents and will not influence integrity of document body. It often adds interest or identifies document status, for example, marking document as private or important. This is the guide you are looking for about how to insert text watermark in Word with WPF.

Spire.Doc for WPF, a professional WPF component on manipulating Word document, enables users to insert text watermark in Word document and set format for this watermark. Comparing with “Insert Watermark” Command in Microsoft Word, Spire.Doc for WPF provides a Spire.Doc.TextWatermark class. Firstly initialize a new instance of Textwatermark with TextWatermark TXTWatermark = new TextWatermark() and then set text watermark as document watermark type by code:document.Watermark = TXTWatermark.

Besides, TextWatermark class includes several parameters for watermark formatting setting, including text, font style, layout etc. The following screenshot is the document without watermark. After the code below, you will find a result screenshot with text watermark being adding at the bottom of the page.

Word Text Watermark

Download Spire.Doc for WPF and install it on your system. After adding button in MainWindow, double click this button to use the following code to insert text watermark in Word with WPF.

[C#]
using System.Windows;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;

namespace Doc_x_Watermark
{
   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\work\Documents\New Zealand.docx");

            //Insert Text Watermark and Set Format
            TextWatermark TXTWatermark = new TextWatermark();
            TXTWatermark.Text = "NZ Brief Introduction ";
            TXTWatermark.FontSize = 45;
            TXTWatermark.FontName = "Broadway BT";
            TXTWatermark.Layout = WatermarkLayout.Diagonal;
            TXTWatermark.Color = Color.Purple;
            document.Watermark = TXTWatermark;

            //Save and Launch
            document.SaveToFile("TXTWatermark.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("TXTWatermark.docx");
        }
    }
}
[VB.NET]
Imports System.Windows
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents

Class MainWindow

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'Load Document
        Dim document As New Document()
        document.LoadFromFile("E:\work\Documents\New Zealand.docx")

        'Insert Text Watermark and Set Format
        Dim TXTWatermark As New TextWatermark()
        TXTWatermark.Text = "NZ Brief Introduction"
        TXTWatermark.FontSize = 45
        TXTWatermark.FontName = "Broadway BT"
        TXTWatermark.Layout = WatermarkLayout.Diagonal
        TXTWatermark.Color = Color.Purple
        document.Watermark = TXTWatermark

        'Save and Launch
        document.SaveToFile("TXTWatermark.docx", FileFormat.Docx)
        System.Diagnostics.Process.Start("TXTWatermark.docx")

    End Sub
End Class

After running, you can get the result as following:

Word Text Watermark

Spire.Doc is a Microsoft Word component which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF.NET and Silverlight.

Additional Info

  • tutorial_title: Insert Text Watermark in WPF
Last modified on Friday, 24 September 2021 09:52