Watermarks in word processing 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 (Name or AlternativeText) when adding shape watermark to a Word document using GroupDocs.Watermark. Following code samples demonstrates it.

AdvancedUsage.AddingWatermarks.AddWatermarksToWordProcessing.WordProcessingAddWatermarkWithShapeSettings

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
// Specify an absolute or relative path to your document. Ex: @"C:\Docs\document.docx"
using (Watermarker watermarker = new Watermarker("document.docx", loadOptions))
{
    TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));

    //Some settings for watermark
    watermark.VerticalAlignment = VerticalAlignment.Center;
    watermark.HorizontalAlignment = HorizontalAlignment.Center;
    watermark.RotateAngle = 25.0;
    watermark.ForegroundColor = Color.Red;
    watermark.Opacity = 1.0;

    WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();

    // Set the shape name
    options.Name = "Shape 1";

    // Set the descriptive (alternative) text that will be associated with the shape
    options.AlternativeText = "Test watermark";

    watermarker.Add(watermark, options);
    watermarker.Save("document.docx");
}

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

AdvancedUsage.AddingWatermarks.AddWatermarksToWordProcessing.WordProcessingAddWatermarkWithTextEffects

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
// Specify an absolute or relative path to your document. Ex: @"C:\Docs\document.docx"
using (Watermarker watermarker = new Watermarker("document.docx", loadOptions))
{
    TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));

    WordProcessingTextEffects effects = new WordProcessingTextEffects();
    effects.LineFormat.Enabled = true;
    effects.LineFormat.Color = Color.Red;
    effects.LineFormat.DashStyle = OfficeDashStyle.DashDotDot;
    effects.LineFormat.LineStyle = OfficeLineStyle.Triple;
    effects.LineFormat.Weight = 1;

    WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();
    options.Effects = effects;

    watermarker.Add(watermark, options);
    watermarker.Save("document.docx");
}

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

AdvancedUsage.AddingWatermarks.AddWatermarksToWordProcessing.WordProcessingAddWatermarkWithImageEffects

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
// Specify an absolute or relative path to your document. Ex: @"C:\Docs\document.docx"
using (Watermarker watermarker = new Watermarker("document.docx", loadOptions))
{
    using (ImageWatermark watermark = new ImageWatermark("logo.png"))
    {
        WordProcessingImageEffects effects = new WordProcessingImageEffects();
        effects.Brightness = 0.7;
        effects.Contrast = 0.6;
        effects.ChromaKey = Color.Red;
        effects.BorderLineFormat.Enabled = true;
        effects.BorderLineFormat.Weight = 1;

        WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();
        options.Effects = effects;

        watermarker.Add(watermark, options);
    }

    watermarker.Save("document.docx");
}