SetHighlight
指定作为背景应用于当前文本块内容的高亮颜色。
语法
expression.SetHighlight(sColor);
expression - 表示 ApiRun 类(文本块)的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| sColor | 必需 | highlightColor | 可用的突出显示颜色。 |
返回值
示例
在 PDF 中为文本应用背景高亮。
// How do I mark text with color in a PDF?
// Add a highlight background behind text 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);
const run = Api.CreateRun();
run.AddText("This is a text run with the text highlighted with light gray color.");
paragraph.AddElement(run);
run.SetHighlight("lightGray");
page.AddObject(shape);