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