如何在 Adob​​e Acrobat Pro 中使用 javascript 将部分注释文本加粗

How to make part of annotation text bold using javascript in Adobe Acrobat Pro

我想在内容中添加内嵌粗体样式。我怎样才能做到这一点?下面的代码输出粗体标记标记而不是应用粗体格式。

var annot = this.addAnnot({
    page: 0,
    type: "FreeText",
    rect: [50, 50, 300, 100],    // location and size of text field in points
    contents: "<b>Links to</b>: http://www.example.com",
});

需要设置文本字段属性以允许富文本格式。然后,您需要创建一个包含具有所需格式的文本的 Span 对象数组。

var spans = new Array();
spans[0] = new Object();
spans[0].text = "Attention:\r";
spans[0].textStyle = "bold";
spans[0].textSize = 18;

spans[1] = new Object();
spans[1].text = "Adobe Acrobat DC\r";
spans[1].textColor = color.red;
spans[1].textSize = 20;
spans[1].alignment = "center";

spans[2] = new Object();
spans[2].text = "will soon be here!";
spans[2].textColor = color.green;
spans[2].fontStyle = "italic";
spans[2].underline = true;
spans[2].alignment = "right";

// Now create the annot with spans as it's richContents
var annot = this.addAnnot({
page: 0,
type: "FreeText",
rect: [50, 50, 300, 100], 
richContents: spans

});