One of the main features of the GroupDocs.Watermark library is adding text watermarks to documents. You may add watermarks to documents or images from local disks, as well as from streams. For a full list of supported document formats, check Supported formats.
To add a text watermark perform the following steps:
Create an instance of the Watermarker class for a local file or file stream;
Create an instance of the TextWatermark class and specify the desired text and font for the watermark;
Call the add method to apply the watermark to the document;
Call the save method to store the document in a new location.
importcom.groupdocs.watermark.Watermarker;importcom.groupdocs.watermark.common.HorizontalAlignment;importcom.groupdocs.watermark.common.VerticalAlignment;importcom.groupdocs.watermark.watermarks.Color;importcom.groupdocs.watermark.watermarks.Font;importcom.groupdocs.watermark.watermarks.FontStyle;importcom.groupdocs.watermark.watermarks.TextWatermark;// Specify an absolute or relative path to your document.
try(Watermarkerwatermarker=newWatermarker("C:\\Docs\\contract.docx")){// Specify the desired text and font for the watermark
TextWatermarkwatermark=newTextWatermark("Contract Draft",newFont("Arial",60,FontStyle.Bold));// Specify font color, text opacity and alignments
watermark.setForegroundColor(Color.getDarkGreen());watermark.setOpacity(0.5);watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);// Apply the watermark
watermarker.add(watermark);// Save the resulting document
watermarker.save("C:\\Docs\\watermarked-contract.docx");}
Run the program. A new watermarked document will appear in the specified path.
What’s next
GroupDocs.Watermark offers many more capabilities for adding text watermarks. For example, it allows specifying background and foreground colors, formatting, text opacity, use of absolute or relative positioning, custom fonts, and so on. To learn more about this, see the Adding text watermarks article of the “Advanced usage” section.
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.
On this page
Ask AI
Ask anything about this page — the answer is based on its content.
Searching the docs and writing an answer…
Something went wrong while getting an answer. Please try again in a moment.