跳到主要内容

SetFontFamily

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

继承自 ApiRichTextPr.SetFontFamily。

语法​

expression.SetFontFamily(fontFamily);

expression - 表示 ApiRichRun 类的变量。

参数​

名称必需/可选数据类型默认值描述
fontFamily必需string用于当前文本块的字体系列。

返回值​

ApiRichTextPr

示例​

在 PDF 中更改自由文本注释中文本的字体。

// How do I choose a different font for text in a PDF?

// Select a font family for text in a PDF.

let doc = Api.GetDocument();
let freeTextAnnot = Api.CreateFreeTextAnnot([160, 50, 360, 135]);
let page = doc.GetPage(0);
page.AddObject(freeTextAnnot);
freeTextAnnot.SetIntent("freeTextCallout");
freeTextAnnot.SetCallout([{x: 161, y: 51}, {x: 249, y: 125}, {x: 261, y: 125}]);
freeTextAnnot.SetRectDiff([100, 64, 0.5, 0.5]);

let richContent = freeTextAnnot.GetContent();
let para = richContent.GetElement(0);
let run = para.GetElement(0);
run.AddText("Some example text");

let textPr = run.GetTextPr();
textPr.SetFontFamily("Calibri");

console.log(`We set font family to ${textPr.GetFontFamily()} for rich text properties`);