Skip to main content

SetPicturePosition

Sets the picture position inside the current form:

  • 0 - the picture is placed on the left/top;
  • 50 - the picture is placed in the center;
  • 100 - the picture is placed on the right/bottom.

Syntax

expression.SetPicturePosition(nShiftX, nShiftY);

expression - A variable that represents a ApiPictureForm class.

Parameters

NameRequired/OptionalData typeDefaultDescription
nShiftXRequiredpercentageHorizontal position measured in percent.
nShiftYRequiredpercentageVertical position measured in percent.

Returns

boolean

Example

Control where the image sits within a picture field in a document.

// How do I shift an image to a specific spot inside a picture field in a document?

// Reposition the image horizontally and vertically inside a picture field in a document.

let doc = Api.GetDocument();
let pictureForm = Api.CreatePictureForm({"key": "Personal information", "tip": "Upload your photo", "required": true, "placeholder": "Photo", "scaleFlag": "tooBig", "lockAspectRatio": true, "respectBorders": false});
let paragraph = doc.GetElement(0);
paragraph.AddElement(pictureForm);
pictureForm.SetImage("https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png", Api.MillimetersToEmus(70), Api.MillimetersToEmus(80));
pictureForm.SetPicturePosition(70, 70);
let position = pictureForm.GetPicturePosition();
paragraph = Api.CreateParagraph();
paragraph.AddText("Picture position: ");
paragraph.AddLineBreak();
for (let i = 0; i < position.length; i++ ){
let shift = position[i];
paragraph.AddText("" + shift);
paragraph.AddLineBreak();
}
doc.Push(paragraph);