跳到主要内容

CreateShape

使用指定的参数创建形状。

语法​

expression.CreateShape(shapeType, width, height, fill, stroke);

expression - 表示 Api 类的变量。

参数​

名称必需/可选数据类型默认值描述
shapeType可选ShapeType"rect"指定预设形状几何图形的形状类型。"textRect" 类型会创建文本框:它没有填充和轮廓,且其高度随文本变化。
width可选EMU914400以英制度量单位表示的形状宽度。
height可选EMU914400以英制度量单位表示的形状高度。
fill可选ApiFill用于填充形状的颜色或图案。如果未指定,则使用默认形状样式填充(主题强调色),文本框没有填充。
stroke可选ApiStroke用于绘制形状轮廓的笔触。如果未指定,则使用默认形状样式轮廓(主题强调色),文本框没有轮廓。

返回值​

ApiShape

示例​

在 PDF 中插入带有文本和颜色的流程图形状。

// How do I add a shape and populate it with text in a PDF?

// Create a shape with colored background and multiple text runs in a PDF.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 150 * 36000, 65 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetContent();
const paragraph = docContent.GetElement(0);

let run = Api.CreateRun();
run.SetFontSize(60);
run.AddText("This is just a sample text. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.SetFontSize(60);
run.SetFontFamily("Comic Sans MS");
run.AddText("This is a text run with the font family set to 'Comic Sans MS'.");
paragraph.AddElement(run);
page.AddObject(shape);