跳到主要内容

GetAllImages

从文档内容返回图像对象集合。

继承自 ApiDocumentContent.GetAllImages。

语法​

expression.GetAllImages();

expression - 表示 ApiDocument 类的变量。

参数​

此方法没有任何参数。

返回值​

ApiImage[]

示例​

获取文档中的所有图像。

// How do I collect every image object present in a document?

// Check the class type of the first image to verify what kind of object was inserted.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);

let image1 = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
60 * 36000, 60 * 36000
);
paragraph.AddDrawing(image1);

let image2 = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/presentation_sky.png',
130 * 36000, 90 * 36000
);
paragraph.AddDrawing(image2);

let images = doc.GetAllImages();
let classType = images[0].GetClassType();
paragraph = Api.CreateParagraph();
paragraph.AddText('Class type: ' + classType);
doc.Push(paragraph);