下面的代码是在vs2010中运行的Winforms代码
需要引用sprie.doc插件的几个dll;
sprie.doc的dll分享链接:https://pan.baidu.com/s/1liZxAy-IG8FIj8N_AciXZA
提取码:st2w
插入水印的代码,
private void button1_Click(object sender, EventArgs e)
{
//Open a blank word document as template
Document document = new Document(@"..\..\..\..\..\..\..\Data\测试水印.docx");
InsertImageWatermark(document);
//Save doc file.
document.SaveToFile("测试水印.docx", FileFormat.Docx);
//Launching the MS Word file.
WordDocViewer("测试水印.docx");
}
private void InsertImageWatermark(Document document)
{
PictureWatermark picture = new PictureWatermark();
picture.Picture = System.Drawing.Image.FromFile(@"..\..\..\..\..\..\..\Data\imgyy.png");
picture.Scaling = 50;
picture.IsWashout = true;
//插入
document.Watermark = picture;
}
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
以上就是我在C#中添加水印的代码,
现在我想要的是在指定位置添加水印,而不是默认居中的;