跳到主要内容

SetFontFamily

使用指定的字体系列设置所有 4 个字体槽。

语法​

expression.SetFontFamily(fontFamily);

expression - 表示 ApiParagraph 类的变量。

参数​

名称必需/可选数据类型默认值描述
fontFamily可选string | null用于当前段落的一个或多个字体系列。传递 null 或省略此参数可移除字体系列。

返回值​

ApiParagraph | null | undefined

示例​

在文档中为段落的所有文本应用特定字体。

// How do I change the font family used for a paragraph's text in a document?

// Switch a paragraph to a different typeface to match a desired visual style in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is a paragraph with the font family set to 'Consolas'.");
paragraph.SetFontFamily("Consolas");