如何在Adobe Acrobat Pro中使用javascript将注释文本的一部分粗体化

时间:2017-02-09 14:05:16

标签: javascript adobe acrobat

我想在内容中添加内联粗体样式。怎么样,我可以实现吗?下面的代码输出粗体标记标记,而不是应用粗体格式。

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",
});

1 个答案:

答案 0 :(得分:1)

需要将文本字段属性设置为允许富文本格式。然后,您需要创建一个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

});

相关问题