跳到主要内容

SetColor

设置当前文本块的文本颜色。

继承自 ApiRichTextPr.SetColor。

语法​

expression.SetColor(color);

expression - 表示 ApiRichRun 类的变量。

参数​

名称必需/可选数据类型默认值描述
color必需ApiColor未提供描述。

返回值​

ApiRichTextPr

示例​

在 PDF 中更改自由文本注释中文本的颜色。

// How do I change text color in a PDF?

// Apply a color to text formatting 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.SetColor(Api.RGB(255, 0, 0));

let color = textPr.GetColor();

console.log(`We set color to {r:${color["r"]}, g:${color["g"]}, b:${color["b"]}} for rich text properties`);