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.
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("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);WordProcessingWatermarkSectionOptionsoptions=newWordProcessingWatermarkSectionOptions();// 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();
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",19));WordProcessingTextEffectseffects=newWordProcessingTextEffects();effects.getLineFormat().setEnabled(true);effects.getLineFormat().setColor(Color.getRed());effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);effects.getLineFormat().setWeight(1);WordProcessingWatermarkSectionOptionsoptions=newWordProcessingWatermarkSectionOptions();options.setEffects(effects);watermarker.add(watermark,options);watermarker.save("document.docx");watermarker.close();
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);ImageWatermarkwatermark=newImageWatermark("logo.png");WordProcessingImageEffectseffects=newWordProcessingImageEffects();effects.setBrightness(0.7);effects.setContrast(0.6);effects.setChromaKey(Color.getRed());effects.getBorderLineFormat().setEnabled(true);effects.getBorderLineFormat().setWeight(1);WordProcessingWatermarkSectionOptionsoptions=newWordProcessingWatermarkSectionOptions();options.setEffects(effects);watermarker.add(watermark,options);watermarker.save("document.docx");watermarker.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.