GroupDocs.Watermark allows to add watermarks and save resultant document. It is capable to add watermark to image or documents. Full list of supported document formats can be found here. You may add text and image watermarks to the documents from local disk and from streams.
Add a text watermark
The following example demostrates how to add a TextWatermark to a local document:
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"using(Watermarkerwatermarker=newWatermarker(Constants.InDocumentPdf)){TextWatermarkwatermark=newTextWatermark("top secret",newFont("Arial",36));watermark.ForegroundColor=Color.Red;watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermarker.Add(watermark);watermarker.Save(Constants.OutDocumentPdf);}
Add an image watermark
The following example demonstrates how to add an ImageWatermark to a document from a stream:
Create a watermarker for the file stream (line 1);
Create a image watermark from the local image file (line 3);
// Constants.InDocumentXlsx is an absolute or relative path to your document. Ex: @"C:\Docs\document.xlsx"using(FileStreamstream=File.Open(Constants.InDocumentXlsx,FileMode.Open,FileAccess.ReadWrite)){using(Watermarkerwatermarker=newWatermarker(stream)){using(ImageWatermarkwatermark=newImageWatermark(Constants.LogoPng)){watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermarker.Add(watermark);}watermarker.Save(Constants.OutDocumentXlsx);}}
More resources
Advanced usage topics
To learn more about document watermarking features and get familiar how to manage watermarks and more, please refer to the advanced usage section.
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: