C # Add Word watermark (text watermark, picture watermark)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.