Adding image watermarks

GroupDocs.Watermar API supports adding the following image file types as image watermark:

  • Bmp;
  • Png;
  • Gif;
  • Jpeg.

Add image watermark from local file

Following code snippet shows how to add ImageWatermark to a document. If the document consists of multiple parts (pages, worksheets, slides, frames etc), the watermark will be added to all of them.

advanced_usage.adding_image_watermarks.AddImageWatermark

// Constants.InPresentationPptx is an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarker watermarker = new Watermarker(Constants.InPresentationPptx);                                           
                                                                                                                   
// Use path to the image as constructor parameter                                                                  
ImageWatermark watermark = new ImageWatermark(Constants.WatermarkJpg);                                             
                                                                                                                   
// Add watermark to the document                                                                                   
watermarker.add(watermark);                                                                                        
                                                                                                                   
watermarker.save(Constants.OutPresentationPptx);                                                                   
                                                                                                                   
watermark.close();                                                                                                 
watermarker.close();                                                                                             

Add image watermark from stream

You can also use a stream of the image to initialize  ImageWatermark instance as shown in below example.

advanced_usage.adding_image_watermarks.AddImageWatermarkUsingStream

// Constants.WatermarkJpg is an absolute or relative path to your document. Ex: "C:\\Docs\\watermark.jpg"
FileInputStream watermarkStream = new FileInputStream(Constants.WatermarkJpg);                           
                                                                                                         
Watermarker watermarker = new Watermarker(Constants.InImagePng);                                         
                                                                                                         
// Use stream containing an image as constructor parameter                                               
ImageWatermark watermark = new ImageWatermark(watermarkStream);                                          
                                                                                                         
// Add watermark to the document                                                                         
watermarker.add(watermark);                                                                              
                                                                                                         
watermarker.save(Constants.OutImagePng);                                                                 
                                                                                                         
watermark.close();                                                                                       
watermarker.dispose();                                                                                   
watermarkStream.close();                                                                                 

For the advanced use of image watermark properties please check the following article about text watermarks, however same techniques will work for image watermark as well:

More resources

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.