As a means of digital information protection, watermark can be used to achieve anti-counterfeiting and copyright statement by adding some digital information to multimedia, such as sound, video signal and other documents. In the office of our more commonly used is to add a watermark to Word document, in the following article will explain how to implement word watermark in C # (including text watermark, picture watermark).
Tool Use:Free Spire.doc for. NET (Community Edition)
(after installation, reference Spire.Doc.dll in the project program, DLL files can be obtained in the Bin folder under the installation path)
Here is the operation code, for reference:
1. Add a word text watermark
using Spire.Doc;using Spire.Doc.Documents;using System.Drawing;namespace Text_Watermark{ class Program { static void Main(string[] args) { //新建一个Document类对象,并加载需要添加水印的Word文档 Document doc = new Document(); doc.LoadFromFile("Test.docx"); //新建一个TextWatermark对象,设置文本水印字样 TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "Internal Use Only"; //设置文本水印字体大小、颜色和文本排列方式 txtWatermark.FontSize = 45; txtWatermark.Color = Color.Green; txtWatermark.Layout = WatermarkLayout.Diagonal; //将文本应用到Word文档水印 doc.Watermark = txtWatermark; //保存并打开文档 doc.SaveToFile("Text_Watermark.docx",FileFormat.Docx2013); System.Diagnostics.Process.Start("Text_Watermark.docx"); } }}
After you debug the run program, generate the document as follows:
2. Add a word picture watermark
using Spire.Doc;using Spire.Doc.Documents;namespace Add_Watermark_To_Word{ class Program { static void Main(string[] args) { //新建一个Document类对象,并加载需要添加水印的Word文档 Document doc = new Document(); doc.LoadFromFile("Test.docx"); //初始化PictureWatermark类实例,加载作为水印的图片 PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile("wto.jpg"); //设置图片大小,并将图片设置成水印 picture.Scaling = 50; doc.Watermark = picture; //保存并打开文档 doc.SaveToFile("Image_Watermark.docx",FileFormat.Docx2013); System.Diagnostics.Process.Start("Image_Watermark.docx"); } }}
Test results:
The above content for the Word document Watermark added introduction, thanks to read!
C # Add Word watermark (text watermark, picture watermark)