To any Microsoft Word document, watermark is a valuable asset. Watermark is mainly used to mark the document as private, confidential and inform about the usage & credibility of the document. Watermark can be a recognizable background image or pattern to catch the reader’s eye and to convey a readily recognizable message that portrays the status of the document.
Whatever text or image, watermark appears on printed page can mark document for specific use. The text or image you use can be an emblem of some brand, logo of a company, monogram of a product, etc. Using watermark feature in Word document would is helpful to inform audience of your document about the constraints over the usage you have applied.
How to Use C# Add Watermark in Word Document
Microsoft Word supports both text and image watermark. Through Spire.Doc, we can use C# add watermark in Word document without Microsoft Word installed on system. Download Spire.Doc and make sure Spire.Doc and Visual Studio are correctly installed on system. Follow the simple guide below to add watermark in Word.
Step 1 Create Project
Create a C# windows form project in visual studio. Add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
using System;
using System.Text;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;
namespace watermark
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Step 2 Load Word Document
Use the following code to load Word document which we need add watermark in.
//Create word document
Document document = new Document();
document.LoadFromFile(@"D:\Work\Stephen\2011.11.08\Use C#VB.NET Insert Watermark into Word Document.doc");
Step 3 Add Watermark
Spire.Doc allows users to add and design watermark. We can freely set font size and layout.
private void AddWatermark(Document document)
{
TextWatermark txtWatermark = new TextWatermark();
txtWatermark.Text = "E-ICEBLUE";
txtWatermark.FontSize = 70;
txtWatermark.Layout = WatermarkLayout.Diagonal;
document.Watermark = txtWatermark;
}
Step 4 Save and Preview
The code below can help use save the document and preview the effect.
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
Effective Screenshot:
Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. Click to learn more…