Add text or image watermark

GroupDocs.Watermark allows to add watermarks and save resultant document. 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:

  • Create a watermarker for the local file (line 2);
  • Create a watermark with text and font (line 4);
  • Set the watermark color, horizontal and vertical alignments (lines 5-7);
  • Add the watermark to the document (line 9);
  • Save the document to the new file (line 10).
  • Close the watermarker and free its resources (line 12).


// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarker watermarker = new Watermarker(Constants.InDocumentPdf);                                      
TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36));                        
watermarker.add(watermark);                                                                     ;                                                              

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);
  • Set the watermark horizontal and vertical alignments (lines 7, 8);
  • Add the watermark to the document (line 9);
  • Save the document to the new file (line 11).
  • Close the watermark and free its resources (line 13);
  • Close the watermarker and free its resources (line 14).


// Constants.InDocumentXlsx is an absolute or relative path to your document. Ex: "C:\\Docs\\document.xlsx" 
FileInputStream stream = new FileInputStream(Constants.InDocumentXlsx);                                     
Watermarker watermarker = new Watermarker(stream);                                                          
ImageWatermark watermark = new ImageWatermark(Constants.LogoPng);                                           

More resources

Advanced usage topics

To learn more about document watermarking features and get familiar how to manage watermarks and more, please refer to theadvanced usage section.

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document watermarking App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to add watermark to PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Watermarking App.