C # Add a watermark to a Word document

Source: Internet
Author: User

Like PDF, in Word, the watermark is also divided into image watermark and text watermark, add image watermark to the document can make the document become more beautiful, more attractive. Text watermark can protect the document, remind others that the document is protected by copyright, can not be copied freely. Before I shared how to add a watermark to a PDF, someone asked me how to add a watermark to a Word document, and today it's time to record how I realized it.

The steps are really simple, in order to save time and simplify the size of the code, I downloaded a free word component from the E-iceblue official website, unzip the installation, refer to the official website of the tutorial, create the project, and follow the steps to the code simple setup. Here's a look at how this component can be implemented.

Original document:

Part I: Adding a picture watermark

First step: Add a reference.

After the component is installed, create a C # console project, add the DLL file under the installation directory to the project as a reference, and add the namespace as follows:

1  using  2  using Spire.Doc.Documents;

Second Step: create a new Word Document object, load the Word document to be added watermark;

1 New  2 Doc. LoadFromFile ("Introduction to XML file. doc");

Step Three: create a new Image Watermark object and add the image to be set as watermark;

1 New  2 picture. Picture = System.Drawing.Image.FromFile (" flower _2.jpg"

Fourth Step: set the size of the picture as needed, then set it as the watermark of the document;

1   the ; 2  

To add a picture watermark:

Part Two: Adding a text watermark

Fifth Step: Create a new text watermark object, and add the text to be set as a watermark;

1 New Textwatermark (); 2 3 " Microsoft ";

Sixth step: Set the text font size and text arrangement, I set the arrangement by diagonal;

1  - ; 2 txtwatermark.layout = watermarklayout.diagonal;

Seventh Step: set the text as a watermark for the Word document;

1 Doc. Watermark = Txtwatermark;

Eighth step: Save the document and reopen it;

1 Doc. SaveToFile (" watermark. doc"); 2 System.Diagnostics.Process.Start (" watermark. doc");

Add a text watermark

C # Add a watermark to a Word document

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.