Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
In today's modern enterprise, Word Documents are synonymous with information and carry important information between divisions and companies. However, with digital documents, there is also the risk of someone tapering or forging an invalid or fake Word document.
As such, one way to combat it is to add watermarks to Word documents. However, this doesn't increase the security of a Word document. A watermark allows primary differentiation between the actual Word document and the forged one. Furthermore, adding a watermark programmatically is quite challenging, as most instances require users to manually use Microsoft Word and add a watermark on each document, making it a painstakingly long process.
Fortunately, IronWord can programmatically add images as watermarks in Word. This allows developers to add them in the pipeline programmatically, reducing repetitive words and increasing efficiency and consistency.
Althought there are various kinds of watermarks, such as shape watermark, text watermark.This article will only use image and picture watermarks, discuss IronWord as a library, and provide practical examples of adding images to the Word document.
IronWord is a reliable and easy-to-use C# Docx library that allows developers to build and edit Word document using C without relying on traditional dependencies such as Microsoft Office or Word Interlope.
Furthermore, it has extension documentation and fully supports .NET 8, 7, 6, Framework, Core, and Azure. This makes it cross-platform compatible with most applications and flexible no matter the application you are dealing with.
Please remember that IronWord requires a licensing key for operation. You can get a key as part of a free trial by visiting this link.
//Replace the license key variable with the trial key you obtained
IronWord.License.LicenseKey = "REPLACE-WITH-YOUR-KEY";
//Replace the license key variable with the trial key you obtained
IronWord.License.LicenseKey = "REPLACE-WITH-YOUR-KEY";
IRON VB CONVERTER ERROR developers@ironsoftware.com
After receiving a trial key, set this variable in your project.
Let's examine an example of adding an image watermark to a Word Document. We won't mention static void main to reduce repetitive code but will showcase only the main code.
We will use this image as the watermark image and add it to the Word document.
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
#region
IronWord.License.LicenseKey = "YOUR-KEY";
#endregion
// Create a new Word document
WordDocument doc = new WordDocument();
//doc.AddImage("ironword.png");
IronWord.Models.Image image = new IronWord.Models.Image("ironword.png");
image.Width = 500; // In unit pixel
image.Height = 250; // In unit pixel
doc.AddImage(image);
// Export docx
doc.SaveAs("documentImageResized.docx");
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
#region
IronWord.License.LicenseKey = "YOUR-KEY";
#endregion
// Create a new Word document
WordDocument doc = new WordDocument();
//doc.AddImage("ironword.png");
IronWord.Models.Image image = new IronWord.Models.Image("ironword.png");
image.Width = 500; // In unit pixel
image.Height = 250; // In unit pixel
doc.AddImage(image);
// Export docx
doc.SaveAs("documentImageResized.docx");
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
#Region ""
IronWord.License.LicenseKey = "YOUR-KEY"
'#End Region
' Create a new Word document
Dim doc As New WordDocument()
'doc.AddImage("ironword.png");
Dim image As New IronWord.Models.Image("ironword.png")
image.Width = 500 ' In unit pixel
image.Height = 250 ' In unit pixel
doc.AddImage(image)
' Export docx
doc.SaveAs("documentImageResized.docx")
The output of the Word document is below.
Keep in mind that the dimensions set in the example are made to fit the whole Word document and display IronWord's capabilities.
In addition to adding the image, we can use the `WrapText` property to ensure that the image watermark stays behind the text in the background.
image.WrapText = WrapText.BehindText;
image.WrapText = WrapText.BehindText;
image.WrapText = WrapText.BehindText
Through this property, the image watermark should wrap behind the text, only showing me in the background, allowing the text to be unhindered.
Furthermore, developers try more customizations for the image watermark to make it unique. IronWord allows you to offset the dimensions of the image relative to the Word document and manage the position of the image watermark as well.
using IronWord;
using IronWord.Models;
#region
IronWord.License.LicenseKey = "YOUR-KEY";
#endregion
// Create a new Word document
WordDocument doc = new WordDocument();
//doc.AddImage("ironword.png");
IronWord.Models.Image image = new IronWord.Models.Image("ironword.png");
ElementPosition elementPosition = new ElementPosition();
elementPosition.SetXPosition(50);
elementPosition.SetYPosition(50);
image.Width = 50; // In unit pixel
image.Height = 50; // In unit pixel
image.Position = elementPosition;
image.DistanceFromTop = 100;
image.DistanceFromBottom = 100;
image.DistanceFromLeft = 100;
image.DistanceFromRight = 100;
using IronWord;
using IronWord.Models;
#region
IronWord.License.LicenseKey = "YOUR-KEY";
#endregion
// Create a new Word document
WordDocument doc = new WordDocument();
//doc.AddImage("ironword.png");
IronWord.Models.Image image = new IronWord.Models.Image("ironword.png");
ElementPosition elementPosition = new ElementPosition();
elementPosition.SetXPosition(50);
elementPosition.SetYPosition(50);
image.Width = 50; // In unit pixel
image.Height = 50; // In unit pixel
image.Position = elementPosition;
image.DistanceFromTop = 100;
image.DistanceFromBottom = 100;
image.DistanceFromLeft = 100;
image.DistanceFromRight = 100;
Imports IronWord
Imports IronWord.Models
#Region ""
IronWord.License.LicenseKey = "YOUR-KEY"
'#End Region
' Create a new Word document
Dim doc As New WordDocument()
'doc.AddImage("ironword.png");
Dim image As New IronWord.Models.Image("ironword.png")
Dim elementPosition As New ElementPosition()
elementPosition.SetXPosition(50)
elementPosition.SetYPosition(50)
image.Width = 50 ' In unit pixel
image.Height = 50 ' In unit pixel
image.Position = elementPosition
image.DistanceFromTop = 100
image.DistanceFromBottom = 100
image.DistanceFromLeft = 100
image.DistanceFromRight = 100
Similar to the code above, we set the dimensions of the image's x and y locations to 50. We also offset the dimensions from each side by 100px to create a margin around it.
Throughout the examples, we demonstrated how straightforward it is to use the IronWord library to manipulate and read Word documents programmatically in C#. The library's flexibility and scalability make it a valuable tool that allows developers to use IronWord in practical, real-life examples, such as adding a watermark and a text watermark. It's essential to grasp how Word works with other applications because it provides developers with additional solutions to their challenges.
IronWord offers a free trial license.
9 .NET API products for your office documents