Shape

Updated at:

This topic describes the APIs for shapes in text documents.

InlineShapes

ActiveDocument.InlineShapes

Returns a collection of all inline shape objects in the document.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects in the document.
      const info = await app.ActiveDocument.InlineShapes;
    }

Method

ActiveDocument.InlineShapes.AddPicture()

You can use the AddPicture() method to embed graphical objects.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.AddPicture({ FileName, LinkToFile, SaveWithDocument, Range })

    expression: Represents a document application object.

  • Parameters

    Property

    Data type

    Required

    Description

    FileName

    String

    Yes

    The path and file name of the shape object.

    LinkToFile

    Boolean

    No

    Specifies whether to link the picture to the file from which it was created. Valid values:

    • true: Links the shape object to the file from which it was created.

    • false (default): Makes the shape object an independent copy.

    SaveWithDocument

    Boolean

    No

    Specifies whether the shape object is saved with the document. Valid values:

    • true: The linked shape object is saved with the document.

    • false (default): The linked shape object is not saved with the document.

    Range

    String

    No

    The position of the shape object in the text.

  • Return value

    This operation returns an embedded graph object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects in the document.
      const inlineShapes = await app.ActiveDocument.InlineShapes;
    
       // Insert an inline shape object.
      const inlineShape = await inlineShapes.AddPicture({
        FileName: 'example.com/a.jpg',
        LinkToFile: false,
        SaveWithDocument: false,
        Range: {
          start: 1,
          end: 2,
        }
      });
    }

Property

ActiveDocument.InlineShapes.Count

Returns the number of inline shape objects in the document.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Count

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects in the document.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Get the number of all inline shape objects in the document.
      const count = await shapes.Count;
      console.log(count);
    
    }

InlineShape

ActiveDocument.InlineShapes.Item(Index)

Returns a single `InlineShape` object from the collection.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index)

    Expression: object of a document type application

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const InlineShapes = await app.ActiveDocument.InlineShapes;
    
      // Get the first inline shape object.
      await InlineShapes.Item(1);
    }

Methods

ActiveDocument.InlineShapes.Item(Index).ConvertToShape()

The ConvertToShape() method converts a single inline shape to a non-inline shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).ConvertToShape()

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);
    
      // Convert the inline shape object to a floating shape object.
      await shape.ConvertToShape();
    }

ActiveDocument.InlineShapes.Item(Index).Delete()

Deletes the specified inline shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).Delete()

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);  
    
      // Delete the inline shape object.
      await shape.Delete();
    }

ActiveDocument.InlineShapes.Item(Index).Select()

Selects the specified inline shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).Select()

    Expression: Application Object for Document Type

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);  
    
      // Select the inline shape object.
      await shape.Select();
    }

Properties

ActiveDocument.InlineShapes.Item(Index).Data

You can retrieve the Base64 data for a single embedded graphic object from the Data property.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).Data

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);  
    
      // Asynchronously return the Base64 data of the inline shape object.
      const Data = await shape.Data;
      console.log(Data);
    }

ActiveDocument.InlineShapes.Item(Index).Height

Gets or sets the height of the specified inline shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).Height

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const InlineShapes = await app.ActiveDocument.InlineShapes;
    
      // Get the first inline shape object.
      await InlineShapes.Item(1);  
    
       // Set the height of the inline shape object.
       shape.Height = 200;
    }

ActiveDocument.InlineShapes.Item(Index).Width

The Width property sets the width of an embedded graphical object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).Width

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const InlineShapes = await app.ActiveDocument.InlineShapes;
    
      // Get the first inline shape object.
      await InlineShapes.Item(1);  
    
       // Set the width of the inline shape object.
       shape.Width = 200;
    }

ActiveDocument.InlineShapes.Item(Index).OLEFormat

You can use the OLEFormat property to obtain the OLE features of an embedded graphical object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).OLEFormat

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);   
    
      // Get the OLE features of the inline shape object.
      const OLEFormat = await shape.OLEFormat;
    }

ActiveDocument.InlineShapes.Item(Index).OriginData

Returns the Base64-encoded data of the original image for the specified inline shape.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.InlineShapes.Item(Index).OriginData

    Document Type Application Object Expression

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all inline shape objects.
      const shapes = await app.ActiveDocument.InlineShapes;
    
      // Insert an inline shape object.
      await shapes.AddPicture({
        FileName: 'https://example.aliyundoc.com/image_01.png', 
        LinkToFile: false,
        SaveWithDocument: false,
      });
    
      // Get the first inline shape object.
      const shape = await shapes.Item(1);  
    
      // Asynchronously return the Base64 data of the original image of the inline shape object.
      const OriginData = await shape.OriginData;
      console.log(OriginData);
    }

Shapes

ActiveDocument.Shapes

Returns a collection of all floating shape objects in the document.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    }

Method

ActiveDocument.Shapes.AddPicture()

You can use the AddPicture() method to insert graphic objects without embedding them.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.AddPicture({ FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height })

    Expression: Application object of document type

  • Parameters

    Property

    Data Type

    Required

    Description

    FileName

    String

    Yes

    The path and file name of the picture.

    LinkToFile

    Boolean

    No

    Specifies whether to link the picture to the file from which it was created. Valid values:

    • true: Links the picture to the file from which it was created.

    • false (default): Makes the picture file an independent copy.

    SaveWithDocument

    Boolean

    No

    Specifies whether the picture is saved with the document. Valid values:

    • true: The linked picture is saved with the document.

    • false (default): The linked picture is not saved with the document.

    Left

    Number

    No

    The position of the left edge of the new picture relative to the drawing canvas, in points.

    Top

    Number

    No

    The position of the top edge of the new picture relative to the drawing canvas, in points.

    Width

    Number

    No

    The width of the picture, in points.

    Height

    Number

    No

    The height of the picture, in points.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Insert a floating shape object.
      const shape = await shapes.AddPicture({
        FileName: 'https://example.com/image_01.png', // The path and file name of the picture.
        LinkToFile: true, // Link the picture to the file from which it was created.
        SaveWithDocument: true, // The linked picture is saved with the document.
        Left: 10, // The distance from the left edge.
        Top: 10, // The distance from the top edge.
        Width: 60, // The width of the picture.
        Height: 120, // The height of the picture.
      });
    }

Property

ActiveDocument.Shapes.Count

The Count property returns the number of all non-embedded graph objects.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Count

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the number of all floating shape objects.
      const count = await shapes.Count;
      console.log(count);
    }

Shape

ActiveDocument.Shapes.Item()

You can retrieve a single non-embedded graph object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index)

    expression: Represents a document application object.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    String

    Yes

    The graph object at the specified index.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    }

Methods

ActiveDocument.Shapes.Item(Index).ConvertToInlineShape()

Converts a floating shape to an inline shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).ConvertToInlineShape()

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Convert the floating shape to an inline shape.
      await shape.ConvertToInlineShape();
    }

ActiveDocument.Shapes.Item(Index).Delete()

Deletes the specified floating shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).Delete()

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Delete the floating shape object.
      await shape.Delete();
    }

ActiveDocument.Shapes.Item(Index).IncrementLeft()

Moves the specified floating shape horizontally by a specified distance.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).IncrementLeft(Increment)

    Expression: Application object of the document type

  • Parameters

    Property

    Data type

    Required

    Description

    Increment

    Number

    Yes

    The distance to move the floating shape object horizontally, in points. Valid values:

    • A positive value moves the floating shape object to the right.

    • A negative value moves the floating shape object to the left.

    • A value of 0 does not move the floating shape object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Move the floating shape object 30 points to the right.
      await shape.IncrementLeft(30);
    }

ActiveDocument.Shapes.Item(Index).IncrementTop()

Moves the specified floating shape vertically by a specified distance.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).IncrementLeft(Increment)

    expression: Represents a document application object.

  • Parameters

    Property

    Data type

    Required

    Description

    Increment

    Number

    Yes

    The distance to move the floating shape object vertically, in points. Valid values:

    • A positive value moves the floating shape object down.

    • A negative value moves the floating shape object up.

    • A value of 0 does not move the floating shape object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Move the floating shape object 30 points down.
      await shape.IncrementTop(30);
    }

ActiveDocument.Shapes.Item(Index).Select()

Selects the specified floating shape.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).Select()

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Select the floating shape object.
      await shape.Select();
    }

ActiveDocument.Shapes.Item(Index).ZOrder()

You can use the ZOrder() method to set the z-index of a non-embedded graphic object relative to the text.

Important

This feature is supported in JS-SDK V1.1.15 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).ZOrder({ ZOrderCmd })

    Expression: Application object for the document type

  • Parameters

    Property

    Data type

    Required

    Description

    ZOrderCmd

    Enum

    Yes

    The z-index position relative to the text to which you want to move the floating shape object. For more information, see ZOrderCmd.

  • Parameters

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Move the floating shape object to a z-index position relative to the text.
      shape.ZOrder(app.Enum.ZOrderCmd.bringInFrontOfText);
    }

Properties

ActiveDocument.Shapes.Item(Index).Data

The Data property returns the Base64 data of a specified non-embedded graphic object.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).Data

    Expression: Document-type application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Get the Base64 data of the floating shape object.
      const Data = await shape.Data;
      console.log(Data);;
    }

ActiveDocument.Shapes.Item(Index).Height

You can use the Height property to specify the height of a non-embedded graphic object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).Height

    Expression: Document-Type Application Object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Set the height of the floating shape object.
      shape.Height = 240;
    }

ActiveDocument.Shapes.Item(Index).Width

The Width property sets the width of a non-embedded graphical object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).Width

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Set the width of the floating shape object.
      shape.Width = 200;
    }

ActiveDocument.Shapes.Item(Index).WrapFormat

Gets or sets the text wrapping style for the specified floating shape.

Important

This feature is supported in JS-SDK V1.1.15 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).WrapFormat = WdWrapType

    expression: Represents a document application object.

  • Parameters

    Property

    Data type

    Required

    Description

    WdWrapType

    Enum

    Yes

    Specifies how text wraps around the shape object. For more information, see WdWrapType.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Set the text to wrap around all sides of the shape.
      shape.WrapFormat = app.Enum.WdWrapType.wdWrapSquare;
    }

ActiveDocument.Shapes.Item(Index).OriginData

You can use the OriginData property to retrieve the Base64 data of a single non-embedded graph object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).OriginData

    expression: Represents a document application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all floating shape objects.
      const shapes = await app.ActiveDocument.Shapes;
    
      // Get the first floating shape object.
      const shape = await shapes.Item(1);
    
      // Asynchronously return the Base64 data of the original image of the floating shape object.
      const OriginData = await shape.OriginData;
      console.log(OriginData);
    }

OLEFormat

ActiveDocument.Shapes.Item(Index).OLEFormat

Returns the OLE features of an OLE object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).OLEFormat

    or expression.ActiveDocument.InlineShapes.Item(Index).OLEFormat

    expression: Represents a document application object.

  • Examples

    • Access through a `Shape` object

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
        
        // Get all floating shape objects.
        const shapes = await app.ActiveDocument.Shapes;
      
        // Get the first floating shape object.
        const shape = await shapes.Item(1);
      
        // Get the OLE features of the floating shape object.
        const OLEFormat = await shape.OLEFormat;
      }
    • Access through an `InlineShape` object

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
        
        // Get all inline shape objects.
        const shapes = await app.ActiveDocument.InlineShapes;
      
        // Get the first inline shape object.
        const shape = await shapes.Item(1);  
      
        // Get the OLE features of the inline shape object.
        const OLEFormat = await shape.OLEFormat;
      }

Property

ActiveDocument.Shapes.Item(Index).OLEFormat.ProgID

Returns the programmatic identifier (ProgID) of the specified OLE object.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Shapes.Item(Index).OLEFormat.ProgID

    or expression.ActiveDocument.InlineShapes.Item(Index).OLEFormat.ProgID

    expression: Represents a document application object.

  • Examples

    • Access through a `Shape` object

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
        
        // Get all floating shape objects.
        const shapes = await app.ActiveDocument.Shapes;
      
        // Get the first floating shape object.
        const shape = await shapes.Item(1);
      
        // Get the OLE features of the floating shape object.
        const OLEFormat = await shape.OLEFormat;
      
        // Get the ProgID of the floating shape object.
        const ProgID = OLEFormat.ProgID;
        console.log(ProgID);
      }
    • Access through an `InlineShape` object

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
        
        // Get all inline shape objects.
        const shapes = await app.ActiveDocument.InlineShapes;
      
        // Get the first inline shape object.
        const shape = await shapes.Item(1);  
      
        // Get the OLE features of the inline shape object.
        const OLEFormat = await shape.OLEFormat;
      
        // Get the ProgID of the inline shape object.
        const ProgID = OLEFormat.ProgID;
        console.log(ProgID);
      }