This topic describes how to obtain shape objects and the number of shapes, and add an image when you use a text document.
Obtain shape objects
Obtain a collection of all shape objects in a document.
Syntax
Expression.ActiveDocument.ShapesExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; }
Add an image
Add an image in the drawing layer of a document.
Syntax:
Expression.ActiveDocument.Shapes.AddPicture({ FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height })Expression: the document type application object.
Parameters
Parameter
Type
Required
Description
FileName
String
Yes
The path and file name of the image.
LinkToFile
Boolean
No
Specifies whether the image is linked to the file from which it was created. Default value: false. Valid values:
true
false
SaveWithDocument
Boolean
No
Specifies whether the linked image is saved with the document. Default value: false. Valid values:
true
false
Left
Number
No
The position of the left edge of the new image relative to the anchor in points.
Top
Number
No
The position of the top edge of the new image relative to the anchor in points.
Width
Number
No
The width of the image in points.
Height
Number
No
The height of the image in points.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); }
Obtain the number of shape objects
Obtain the number of shape objects.
Syntax
Expression.ActiveDocument.Shapes.CountExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the number of all shape objects. const count = await shapes.Count; console.log(count); }
A single shape
Obtain a single shape object
Obtain a single shape object from a collection of shape objects.
Syntax
Expression.ActiveDocument.Shapes.Item(Index)Expression: the document type application object.
Parameters
Parameter
Type
Required
Description
Index
String
Yes
The index number of the shape object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); }
Set the width of a shape object
Set the width of a single shape object.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).WidthExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); // Set the width of the first shape. shape.Width = 200; }
Set the height of a shape object
Set the height of a single shape object.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).HeightExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); // Set the height of the first shape object. shape.Height = 240; }
Delete a shape object
Delete a shape object.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).Delete()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); // Delete a single shape object. await shape.Delete(); }
Convert a drawing layer shape to an inline shape
Convert a shape in the drawing layer of a document to an inline shape in the text layer.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).ConvertToInlineShape()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); // Convert the first shape object to an inline shape object. await shape.ConvertToInlineShape(); }
Move a shape horizontally
Move a specified shape horizontally by the specified number of points.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).IncrementLeft(Increment)Expression: the document type application object.
Parameters
Parameter
Type
Required
Description
Increment
Number
Yes
The distance in points by which the shape is to be moved horizontally. Valid values:
A positive value: moves the shape object to the right.
A negative value: moves the shape object to the left.
0: does not move the shape object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Add an image in the drawing layer. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: true, SaveWithDocument: true, Left: 10, // The position of the left edge of the image relative to the anchor. Top: 10, // The position of the top edge of the image relative to the anchor. Width: 60, // The width of the image. Height: 120, // The height of the image. }); // Obtain the first shape object. const shape = await shapes.Item(1); // Move the first shape to the right by 30 points. await shape.IncrementLeft(30); }
Move a shape vertically
Move a specified shape vertically by the specified number of points.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).IncrementTop(Increment)Expression: the document type application object.
Parameters
Parameter
Type
Required
Description
Increment
Number
Yes
The distance in points by which the shape is to be moved vertically. Valid values:
A positive value: moves the shape object down.
A negative value: moves the shape object up.
0: does not move the shape object.
Example
async function example() {
await instance.ready();
const app = instance.Application;
// Obtain the shape objects.
const shapes = await app.ActiveDocument.Shapes;
// Add an image in the drawing layer.
await shapes.AddPicture({
FileName: 'https://example.com/a.jpg', // The path of the image.
LinkToFile: true,
SaveWithDocument: true,
Left: 10, // The position of the left edge of the image relative to the anchor.
Top: 10, // The position of the top edge of the image relative to the anchor.
Width: 60, // The width of the image.
Height: 120, // The height of the image.
});
// Obtain the first shape object.
const shape = await shapes.Item(1);
// Move the first shape down by 30 points.
await shape.IncrementTop(30);
}Inline shapes
Obtain inline shape objects
Obtain all inline shape objects in the selection.
Syntax
Expression.ActiveDocument.InlineShapesExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all inline shape objects in the selection. const info = await app.ActiveDocument.InlineShapes; }
Add an inline image
Syntax
Expression.ActiveDocument.InlineShapes.AddPicture({ FileName, LinkToFile, SaveWithDocument, Range })Expression: the document type application object.
Parameters
Parameter
Type
Required
Description
FileName
String
Yes
The path and file name of the image.
LinkToFile
String
No
Specifies whether the image is linked to the file from which it was created. Default value: false. Valid values:
true
false
SaveWithDocument
String
No
Specifies whether the linked image is saved with the document. Default value: false. Valid values:
true
false
Range
String
No
The position in the text where the image is added.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, // Range: the position in the text where the image is added. }); }
Obtain the number of inline shape objects
Syntax
Expression.ActiveDocument.InlineShapes.CountExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the number of inline shape objects. const count = await shapes.Count; console.log(count); }
A single inline shape
Obtain a single inline shape object
Syntax
Expression.ActiveDocument.InlineShapes.Item(Index)Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first inline shape object. const shape = await shapes.Item(1); }
Set the width of an inline shape object
Set the width of a single inline shape object.
Syntax
Expression.ActiveDocument.InlineShapes.Item(Index).WidthExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first inline shape object. const shape = await shapes.Item(1); // Set the width of the inline shape object. shape.Width = 200; }
Set the height of an inline shape object
Set the height of a single inline shape object.
Syntax
Expression.ActiveDocument.InlineShapes.Item(Index).HeightExpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first inline shape object. const shape = await shapes.Item(1); // Set the height of the inline shape object. shape.Height = 200; }
Delete an inline shape object
Syntax
Expression.ActiveDocument.InlineShapes.Item(Index).Delete()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first inline shape object. const shape = await shapes.Item(1); // Delete the inline shape object. await shape.Delete(); }
Convert an inline shape object to a drawing layer shape object
Convert an inline shape object in the text layer of a document to a shape object in the drawing layer.
Syntax
Expression.ActiveDocument.InlineShapes.Item(Index).ConvertToShape()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.InlineShapes; // Add an inline image. await shapes.AddPicture({ FileName: 'https://example.com/a.jpg', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first inline shape object. const shape = await shapes.Item(1); // Convert the inline shape object to a shape object in the drawing layer. await shape.ConvertToShape(); }
Select an inline shape object
Select a single inline shape object.
Syntax
Expression.ActiveDocument.Shapes.Item(Index).Select()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the shape objects. const shapes = await app.ActiveDocument.Shapes; // Insert a single image. await shapes.AddPicture({ FileName: 'https://example.aliyundoc.com/583546003_25a7bc59d95249c2a3c257fa369ca289?imageMogr2/thumbnail/180x180! ', // The path of the image. LinkToFile: false, SaveWithDocument: false, }); // Obtain the first shape object. const shape = await shapes.Item(1); // Select a single shape object. await shape.Select(); }