繁体   English   中英

Adobe Pro:使用Javascript更改FreeText注释的颜色

[英]Adobe Pro: Changing Color of FreeText Annotations with Javascript

我正在使用Adobe Pro编辑PDF,其中以FreeText注释的形式输入了许多附加内容。
现在,我想编写一个脚本将其中的文本颜色更改为黑色。 它已经适用于线/圆/ ...,但不适用于实际的文本。

这是我到目前为止所拥有的:

/* Bla */
var myDoc = event.target.doc;

if(!myDoc)
    console.println("Failed to access document");
else
    console.println("Opened Document");

//Color all Comments in Black
function colorComments(myDoc)
    {
    //Get a list of Comments
    var commentList = myDoc.getAnnots();
        if(commentList == null)
        {
            console.println("Failed to get Comments");
        }
        else
        {
            console.println("Found " + commentList.length + " Comments, Iterating through comments");
        }

    //Iterate through the comment List and change the Colors
    for each(comment in commentList)
    {
        if(comment == null)
        {
            console.println("Found undefined annot!");
        }

        switch(comment.type)
        {
            case "FreeText":
            {
                //change stroke color
                comment.strokeColor = color.black;
                var contents = comment.richContents;
                //Go through all spans and change the text color in each one
                for each(s in contents)
                {
                    console.println(s.text);
                    s.textColor = color.black;
                }
                break;
            }
        }
    }
}

colorComments(myDoc);

它将在控制台中打印文本的内容,但颜色完全不变。

似乎“ Span”对象被复制,而不是在我的代码中的某个地方引用。
创建一个数组来保存更改后的Span,然后将该数组分配给comment.richContents似乎很好。

case "FreeText":
{
  var spans = new Array;
  for each(span in comment.richContents)
  {
    span.textColor = color.red;
    spans[spans.length] = span;
  }
  comment.richContents = spans;
  break;
}

很好 (迭代comments.richContents直接改变for each循环的for循环,虽然没有改变结果。

为什么它不起作用的答案可能在JS的细节中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM