Text watermark and image watermark are two kinds of watermarks in Word document. The text watermark always shows some additional but related information to the word context. While image watermark is used to make the Word document be more attractive. This section will demonstrate how to use Spire.Doc to add text watermark and image watermark to Word document in C#.
Add Image Watermark in C#:
using Spire.Doc; namespace SetImageWatermark { class Program { static void Main(string[] args) { { //create a new instance of Document and load the document from file. Document doc = new Document(); doc.LoadFromFile("Sample.docx", FileFormat.Docx2013); //create a new instance of the PictureWatermark and load the picture from file. PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile("logo.png"); //set the image watermark scaling and Washout property picture.Scaling = 20; picture.IsWashout = false; //add the picture watermark doc.Watermark = picture; //save the document to file doc.SaveToFile("ImageWatermark.docx", FileFormat.Docx2013); } } } }
Add Text Watermark in C#::
using Spire.Doc; using Spire.Doc.Documents; using System.Drawing; namespace SetTextWatermark { class Program { static void Main(string[] args) { { //create a new instance of Document and load the document from file. Document doc = new Document(); doc.LoadFromFile("Sample.docx", FileFormat.Docx2013); //create a new instance of the TextWatermark TextWatermark txtWatermark = new TextWatermark(); //set the text watermark with text string, font, color and layout. txtWatermark.Text = "Confidential"; txtWatermark.FontSize = 45; txtWatermark.Color = Color.Green; txtWatermark.Layout = WatermarkLayout.Diagonal; //add the text watermark doc.Watermark = txtWatermark; //save the file. doc.SaveToFile("TextWatermark.docx", FileFormat.Docx2013); } } } }