Watermarks in Word document

When adding watermark in Microsoft Word application, it places a shape with appropriate content in section headers. GroupDocs.Watermark API uses the same approach. When calling add() method of Watermarker class, the shape is added to a document.

You can also set some additional options (setName() or setAlternativeText()) when adding shape watermark to a Word document using GroupDocs.Watermark. Following code samples demonstrates it.

advanced_usage.add_watermarks_to_word_processing.WordProcessingAddWatermarkWithShapeSettings

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarker watermarker = new Watermarker("document.docx", loadOptions);                          
                                                                                                           
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));                      
                                                                                                           
//Some settings for watermark                                                                              
watermark.setVerticalAlignment(VerticalAlignment.Center);                                                  
watermark.setHorizontalAlignment(HorizontalAlignment.Center);                                              
watermark.setRotateAngle(25.0);                                                                            
watermark.setForegroundColor(Color.getRed());                                                              
watermark.setOpacity(1.0);                                                                                 
                                                                                                           
WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();               
                                                                                                           
// Set the shape name                                                                                      
options.setName("Shape 1");                                                                                
                                                                                                           
// Set the descriptive (alternative) text that will be associated with the shape                           
options.setAlternativeText("Test watermark");                                                              
                                                                                                           
watermarker.add(watermark, options);                                                                       
                                                                                                           
watermarker.save("document.docx");                                                               
                                                                                                           
watermarker.close();                                                                                       

You can also apply some text effects to the shape watermarks as shown in the below code.

advanced_usage.add_watermarks_to_word_processing.WordProcessingAddWatermarkWithTextEffects

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarker watermarker = new Watermarker("document.docx", loadOptions);                          
                                                                                                           
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));                      
                                                                                                           
WordProcessingTextEffects effects = new WordProcessingTextEffects();                                       
effects.getLineFormat().setEnabled(true);                                                                  
effects.getLineFormat().setColor(Color.getRed());                                                          
effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);                                          
effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);                                              
effects.getLineFormat().setWeight(1);                                                                      
                                                                                                           
WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();               
options.setEffects(effects);                                                                               
                                                                                                           
watermarker.add(watermark, options);                                                                       
watermarker.save("document.docx");                                                               
                                                                                                           
watermarker.close();                                                                                       

GroupDocs.Watermark also provides the facility to apply image effects to the shape watermarks.

advanced_usage.add_watermarks_to_word_processing.WordProcessingAddWatermarkWithImageEffects

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarker watermarker = new Watermarker("document.docx", loadOptions);                          
                                                                                                           
ImageWatermark watermark = new ImageWatermark("logo.png");                                          
                                                                                                           
WordProcessingImageEffects effects = new WordProcessingImageEffects();                                     
effects.setBrightness(0.7);                                                                                
effects.setContrast(0.6);                                                                                  
effects.setChromaKey(Color.getRed());                                                                      
effects.getBorderLineFormat().setEnabled(true);                                                            
effects.getBorderLineFormat().setWeight(1);                                                                
                                                                                                           
WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();               
options.setEffects(effects);                                                                               
                                                                                                           
watermarker.add(watermark, options);                                                                       
                                                                                                           
watermarker.save("document.docx");                                                               
                                                                                                           
watermarker.close();