跳到主要内容

SetBold

为文本字符设置粗体属性。

语法​

expression.SetBold(isBold);

expression - 表示 ApiRichTextPr 类的变量。

参数​

名称必需/可选数据类型默认值描述
isBold必需boolean指定文本块的内容显示为粗体。

返回值​

ApiRichTextPr

示例​

在 PDF 中将文本设为粗体。

// How do I add bold formatting to text in a PDF?

// Apply bold styling to formatted 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.SetBold(true);

console.log(`We set bold to ${textPr.GetBold()} for rich text properties`);