Defines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
Specifies the vertical coordinate of the watermark within the parent document.
The code below demonstrates how to specify the desired watermark appearance and position before applying it to the document:
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.SizingType;importcom.groupdocs.watermark.watermarks.TextWatermark;// Specify an absolute or relative path to your document.
try(Watermarkerwatermarker=newWatermarker("C:\\Docs\\sample.docx")){// Specify the desired text and font for the watermark
TextWatermarkwatermark=newTextWatermark("Customized watermark.",newFont("Arial",24,FontStyle.Bold));// Specify the appearance and the position of the watermark
watermark.setForegroundColor(Color.getDarkOrange());watermark.setConsiderParentMargins(true);watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Top);watermark.setSizingType(SizingType.ScaleToParentDimensions);watermark.setRotateAngle(45);watermark.setScaleFactor(0.7);// Apply the watermark
watermarker.add(watermark);// Save the resulting document
watermarker.save("C:\\Docs\\watermarked-sample.docx");}
Run the program. A watermark will be added at a specified position and will have the specified look.
Customizing image watermarks
Image watermarks have similar settings that affect their look and position. To adjust an image watermark, use the methods that the ImageWatermark class inherits from the Watermark class.
Defines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
Specifies the vertical coordinate of the watermark within the parent document.
The code below demonstrates how to specify the desired watermark appearance and position before applying it to the document:
importcom.groupdocs.watermark.Watermarker;importcom.groupdocs.watermark.common.HorizontalAlignment;importcom.groupdocs.watermark.common.VerticalAlignment;importcom.groupdocs.watermark.watermarks.ImageWatermark;// Specify an absolute or relative path to your document
// and to the watermark image.
try(Watermarkerwatermarker=newWatermarker("C:\\Docs\\seagull.jpg");ImageWatermarkwatermark=newImageWatermark("C:\\Docs\\greetings-stamp.png")){// Specify watermark position, rotation and opacity
watermark.setHorizontalAlignment(HorizontalAlignment.Right);watermark.setVerticalAlignment(VerticalAlignment.Top);watermark.setRotateAngle(15);watermark.setBackground(false);watermark.setOpacity(0.8);// Apply the watermark
watermarker.add(watermark);// Save the resulting document
watermarker.save("C:\\Docs\\custom-image-watermark.jpg");}
Run the program. An image watermark will be added at a specified position.
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.