跳到主要内容

SetImage

Sets an image to the current picture form.

Syntax

expression.SetImage(sImageSrc, nWidth, nHeight);

expression - A variable that represents a ApiPictureForm class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sImageSrcRequiredstringThe image source where the image to be inserted should be taken from (currently, only internet URL or base64 encoded images are supported).
nWidthRequiredEMUThe image width in English measure units.
nHeightRequiredEMUThe image height in English measure units.

Returns

boolean

Example

This example sets an image to the current picture form.

let doc = Api.GetDocument();
let pictureForm = Api.CreatePictureForm({"tip": "Upload your photo", "required": true, "placeholder": "Photo", "scaleFlag": "tooBig", "lockAspectRatio": true, "respectBorders": false, "shiftX": 50, "shiftY": 50});
pictureForm.SetImage("https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
let paragraph = doc.GetElement(0);
paragraph.AddElement(pictureForm);