In today’s digital age, protecting your documents from unauthorized use and asserting ownership is paramount. One effective method to achieve this is by adding watermarks. Watermarks not only deter unauthorized copying but also provide a professional touch to your documents. In this article, we’ll explore how to add text watermark to DOCX using C#, providing you with a practical and straightforward solution to safeguard your documents. Additionally, we will furnish you with a code example demonstrating how to insert text watermark to DOCX using C#.
Steps to Add Text Watermark to DOCX Using C#
- Set up your IDE to utilize GroupDocs.Watermark for .NET in order to insert a watermark in DOCX document
- Instantiate the Watermarker class by providing the path of the DOCX file to its constructor
- Create an instance of the TextWatermark class and set its properties according to your preferences for the watermark
- Call the Watermarker.Add method to insert the watermark onto the DOCX
- Call the Watermarker.Save method to save the resulting DOCX document onto disk
Text watermarks serve as a visible indication of ownership or confidentiality, making it clear to viewers that the document is protected. They are particularly useful for documents shared in collaborative environments, ensuring that the source is always attributed and preventing unauthorized distribution. To summarize, add text watermark in DOCX using C# is a straightforward process that enhances document security and professionalism. By following the steps outlined above, you can easily implement text watermarks in your C# applications, safeguarding your documents and asserting ownership.
Code to Add Text Watermark to DOCX Using C#
using GroupDocs.Watermark.Common; | |
using GroupDocs.Watermark.Watermarks; | |
using GroupDocs.Watermark; | |
namespace AddTextWatermarktoDOCXUsingCSharp | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Set License to avoid the limitations of Watermark library | |
License lic = new License(); | |
lic.SetLicense(@"GroupDocs.Watermark.lic"); | |
// Specify an absolute or relative path to your document. | |
using (Watermarker watermarker = new Watermarker("input.docx")) | |
{ | |
// Specify the desired text and font for the watermark | |
TextWatermark watermark = new TextWatermark("Watermark Text", | |
new Font("Arial", 60, FontStyle.Bold)); | |
// Specify font color and text opacity, rotation and alignments | |
watermark.ForegroundColor = Color.DarkGreen; | |
watermark.Opacity = 0.5; | |
watermark.HorizontalAlignment = HorizontalAlignment.Center; | |
watermark.VerticalAlignment = VerticalAlignment.Center; | |
watermark.RotateAngle = -45; | |
// Apply the watermark | |
watermarker.Add(watermark); | |
// Save the resulting document | |
watermarker.Save("output.docx"); | |
} | |
} | |
} | |
} |
The steps detailed above, along with the code provided, demonstrate a straightforward and seamless approach to add watermark to word document using C#. This method is adaptable and can be applied across various operating systems, including Windows, macOS, and Linux, as long as .NET is installed. After configuring the chosen library and adjusting file paths as needed, incorporating the provided code into your applications becomes a straightforward and efficient process. Congratulations! You have now mastered the technique of adding watermarks to Word files in C#.
In a prior tutorial, we provided an in-depth guide on converting DOCX to ODT using Node.js. Should you need additional assistance, we suggest referring to our comprehensive tutorial on how to convert DOCX to ODT using Node.js.