usingGroupDocs.Watermark;usingGroupDocs.Watermark.Watermarks;// Specify an absolute or relative path to your document.using(Watermarkerwatermarker=newWatermarker("C:\\Docs\\sample.docx")){// Specify the desired text and font for the watermarkTextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",36,FontStyle.Bold|FontStyle.Italic));watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermark.Opacity=0.4;watermark.RotateAngle=45;watermark.ForegroundColor=Color.Red;// Apply the watermarkwatermarker.Add(watermark);// Save the resulting documentwatermarker.Save("C:\\Docs\\watermarked-sample.docx");}
Additionally, if you are certain about your file extension or know the document type in advance, you can specify the FileType through the LoadOptions class. Specifying it eliminates the need for format detection, enabling faster and more efficient document processing:
varfilePath="C:\\Docs\\sample.docx";varloadOptions=newLoadOptions(){FileType=FileType.FromExtension(Path.GetExtension(filePath))};// Or set the FormatFamily property directly when using a stream, for example:loadOptions.FormatFamily=FormatFamily.WordProcessing;using(varwatermarker=newWatermarker(filePath,loadOptions)){....}
Running
Run the program. A new watermarked document will appear in the specified path.
What’s next
Congratulations! You have added a simple text watermark to a document. Read the Developer guide and API reference to learn how to customize text watermarks, add images as watermarks, search documents for existing watermarks, and much more.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.