string wMarkText="水印"; int wMarkFontSize = 46; string wMarkColor = "#736b6b"; int wMarkLayout = 0; wMarkColor = wMarkColor.Substring(1); #region 给Word文档添加水印 string path = "E:\TestFile\20191115033010124.docx"; //新建一个Document类对象,并加载需要添加水印的Word文档 Document doc = new Document(); //doc.LoadFromFile("E:\TestFile\20191115033010124.docx"); doc.LoadFromFile(path); //新建一个TextWatermark对象,设置文本水印字样 TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = wMarkText; //设置文本水印字体大小、颜色和文本排列方式 txtWatermark.FontSize = wMarkFontSize; txtWatermark.Color = Color.FromArgb(Convert.ToInt32("FF" + wMarkColor, 16)); if (wMarkLayout == 0) { txtWatermark.Layout = WatermarkLayout.Diagonal; } else { txtWatermark.Layout = WatermarkLayout.Horizontal; } //将文本应用到Word文档水印 doc.Watermark = txtWatermark; //保存(替换原)文档 doc.SaveToFile(path, FileFormat.Docx2013); return this.ApiResult("添加水印成功!"); #endregion