Watermarks

更新时间:
复制 MD 格式

This topic describes how to obtain watermark objects, add a text watermark, and delete a watermark when you use a text document.

Obtain watermark objects

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks

    Expression: the document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Index

    Number

    Yes

    The index of the selected content, range, or part of the document.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    }

Add a template watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.AddTemplateWaterMark({ Index, ApplyTo })

    Expression: the document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Index

    Number

    Yes

    The index of the preset template watermark.

    ApplyTo

    Number

    No

    The location where the watermark is added. Valid values:

    • 0: the current section.

    • 1: the entire document.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Add the second preset template watermark to the entire document.
      waterMarks.AddTemplateWaterMark({
        Index: 2,
        ApplyTo: 1,
      });
    }

Add a text watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.AddTemplateWaterMark({ Text, FontName, FontSize, FontColor, Transparency, Gradient })

    Expression: the document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Text

    String

    Yes

    The text of the watermark.

    FontName

    String

    Yes

    The font type of the watermark.

    FontSize

    Number

    Yes

    The font size of the watermark.

    FontColor

    String

    Yes

    The font color of the watermark. Default value: 0xC0C0C0.

    Transparency

    Number

    Yes

    The transparency of the watermark.

    Gradient

    Boolean

    Yes

    Specifies whether the watermark has a gradient. Default value: false. Valid values:

    • false

    • true

    ApplyTo

    Number

    Yes

    The location where the watermark is added. The default value is 1, which indicates the entire document.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Add a text watermark.
      await waterMarks.AddTextWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, //The font size of the watermark.
        FontColor: '#171717', //The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    }

Edit a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.EditTextWaterMark({ Text, FontName, FontSize, FontColor, Transparency, Gradient })

    Expression: the document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Text

    String

    Yes

    The text of the watermark.

    FontName

    String

    Yes

    The font type of the watermark.

    FontSize

    Number

    Yes

    The font size of the watermark.

    FontColor

    String

    Yes

    The font color of the watermark. Default value: 0xC0C0C0.

    Transparency

    Number

    Yes

    The transparency of the watermark.

    Gradient

    Boolean

    Yes

    The gradient of the watermark.

    ApplyTo

    Number

    Yes

    The location where the watermark is added. The default value is 1, which indicates the entire document.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Edit the watermark.
      await waterMarks.EditTextWaterMark({
        Text: '', // The text of the watermark. 
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 66, // The font size of the watermark.
        FontColor: '#f00', // The font color of the watermark.
        Transparency: 1, // The transparency of the watermark.
        Gradient: true, // The watermark has a gradient.
        ApplyTo: 1, //The location where the watermark is added.
      });
    }

Delete a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.DeleteWaterMark()

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Delete a watermark.
      waterMarks.DeleteWaterMark();
    }

A single watermark

Obtain a single watermark object

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index)

    Expression: the document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Index

    Number

    Yes

    The index of the watermark object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // A single watermark object.
      const waterMark = await waterMarks.Item(1);
    }

Set the text of a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).Text

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddTextWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the text of the watermark.
      waterMark.Text = 'WebOffice';
    }

Set the font type of a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).FontName

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddFontNameWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the font type of the watermark.
      waterMark.FontName ='Kaiti';
    }

Set the font color of a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).FontColor

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddFontNameWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the font color of the watermark.
      waterMark.FontColor = '#fff000';
    }

Set the font size of a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).FontSize

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddFontNameWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the font size of the watermark.
      waterMark.FontSize = 80;
    }

Set the gradient of the watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).Gradient

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddFontNameWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the gradient of the watermark.
      waterMark.Gradient = true;
    }

Set the transparency of a watermark

  • Syntax

    Expression.ActiveDocument.Sections.Item(Index).WaterMarks.Item(Index).Transparency

    Expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a text watermark.
      await app.ActiveDocument.ActiveWindow.Selection.AddFontNameWaterMark({
        Text: 'Watermark text', // The text of the watermark.
        FontName: 'Song type', // The font type of the watermark.
        FontSize: 40, // The font size of the watermark.
        FontColor: '#171717', // The font color of the watermark.
        Transparency: 0.3, // The transparency of the watermark.
        Gradient: false, // The watermark does not have a gradient.
        ApplyTo: 1, // The location where the watermark is added.
      });
    
      // The watermark objects.
      const waterMarks = await app.ActiveDocument.Sections.Item(1).WaterMarks;
    
      // Obtain the watermark.
      const waterMark = await waterMarks.Item(1);
    
      // Set the transparency of the watermark.
      waterMark.Transparency = 0;
    }