GroupDocs.Watermark allows adding watermarks and saving the resultant documents. The full list of supported document formats can be found here. You may add text and image watermarks to the documents from the local disk and from streams.
Add a text watermark
The following example demonstrates how to add a TextWatermark to a local document:
Close the watermarker and free its resources (line 12).
basic_usage.AddATextWatermark
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf");TextWatermarkwatermark=newTextWatermark("top secret",newFont("Arial",36));watermark.setForegroundColor(Color.getRed());watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermarker.add(watermark);watermarker.save("document.pdf");watermarker.close();
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 4);
Create an image watermark from the local image file (line 6);
Close the watermark and free its resources (line 13);
Close the watermarker and free its resources (line 14).
basic_usage.AddAnImageWatermark
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.xlsx"
FileInputStreamstream=newFileInputStream("document.xlsx");Watermarkerwatermarker=newWatermarker(stream);ImageWatermarkwatermark=newImageWatermark("logo.png");watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermarker.add(watermark);watermarker.save("document.xlsx");watermark.close();watermarker.close();stream.close();
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.