Image watermarks serve as visible indicators overlaid onto documents, reinforcing ownership, confidentiality, or branding. They can be logos, signatures, or custom graphics, providing a layer of protection and professionalism to your documents. In this article, we will delve into the process of how to add image watermark to DOCX using C#. With the inclusion of code example, we aim to furnish you with a tangible and efficient means of bolstering document security. Below, we outline the fundamental steps to insert image watermark to DOCX in C#.
Steps to Add Image Watermark to DOCX Using C#
- Prepare your IDE to employ GroupDocs.Watermark for .NET, enabling the insertion of image watermarks into DOCX documents
- Create an instance of the Watermarker class, specifying the path of the DOCX file as an argument in its constructor
- Create an instance of the ImageWatermark class and customize its properties according to your preferred settings for the watermark
- Call the Watermarker.Add method to incorporate the configured watermark into the document
- Call the Watermarker.Save method to store the output DOCX document onto the disk
By following these steps, you can effortlessly enhance the security and professionalism of your DOCX documents by adding image watermarks. Whether you’re protecting sensitive information or branding your documents, image watermarks provide an effective solution. With the power of watermark library, you can easily add image watermark in DOCX using C#. This approach offers a practical and versatile solution for safeguarding your documents while maintaining ease of implementation within your C# projects. The following code example demonstrates how to execute this procedure.
Code to Add Image Watermark to DOCX Using C#
using GroupDocs.Watermark.Common; | |
using GroupDocs.Watermark.Watermarks; | |
using GroupDocs.Watermark; | |
namespace AddImageWatermarktoDOCXUsingCSharp | |
{ | |
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 an absolute or relative path to the desired image | |
ImageWatermark watermark = new ImageWatermark("logo.jpg"); | |
// Specify watermark size, opacity and alignments | |
watermark.Width = 200; | |
watermark.Height = 200; | |
watermark.Opacity = 0.5; | |
watermark.HorizontalAlignment = HorizontalAlignment.Center; | |
watermark.VerticalAlignment = VerticalAlignment.Center; | |
// Apply the watermark | |
watermarker.Add(watermark); | |
// Save the resulting document | |
watermarker.Save("output.docx"); | |
} | |
} | |
} | |
} |
Begin integrating image watermarks into your DOCX files today, enhancing your document management with heightened reliability and professionalism. This method offers flexibility, suitable for various operating systems including Windows, macOS, and Linux, as long as .NET is installed. After setting up the chosen library and adjusting file paths as needed, incorporating the provided code into your applications is a seamless and efficient process. Well done! You’ve successfully mastered the technique of how to add image watermark to DOCX in C#.
In a previous tutorial, we provided an extensive guide on adding text watermarks to PDF using C#. If you need additional support, we suggest referring to our comprehensive tutorial on how to add text watermark to PDF using C#.