跳到主要内容

SetRelativeHeight

设置对象(图像、形状、图表)边界框的相对高度。

继承自 ApiDrawing.SetRelativeHeight

示例

将文档中形状的高度设置为页面的百分比。

// How do I make a shape's height scale proportionally with the page in a document?

// Stretch a rectangle to fill a quarter of the page height so it adapts to different page sizes in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let fill = Api.CreateSolidFill(Api.CreateRGBColor(91, 155, 213));
let stroke = Api.CreateStroke(0.4 * 36000, Api.CreateSolidFill(Api.CreateRGBColor(65, 113, 156)));
let drawing = Api.CreateShape("rect", 1 * 36000, 1 * 36000, fill, stroke);
drawing.SetWrappingStyle("inFront");
drawing.SetVerPosition("page", 50 * 36000);
drawing.SetHorPosition("page", 0);
drawing.SetRelativeWidth("page", 100);
drawing.SetRelativeHeight("page", 25);
paragraph.AddDrawing(drawing);
paragraph = Api.CreateParagraph();
paragraph.AddText("The shape was created with a width 100% of page width and 25% of height page");
doc.Push(paragraph);