开发者

Adobe Pro: Changing Color of FreeText Annotations with Javascript

开发者 https://www.devze.com 2023-04-11 04:56 出处:网络
I\'m using Adobe Pro to edit PDFs in which a lot of Additions have been entered in the Form of FreeText Annotations.

I'm using Adobe Pro to edit PDFs in which a lot of Additions have been entered in the Form of FreeText Annotations.

Now i want to write a Script to Change the Textcolor in these to Black. It already works for Lines/Circles/... but not for the actual Text.

Here is what i have so far:

/* 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);

Which prints the Contents of the Text in the Console, but the Color doesn't change at all.


It seems the "Span" object gets copied instead of referenced somewhere in my code.
Creating a array to hold the changed Spans and then assigning the array to comment.richContents seems to work fine.

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

That works fine. (iterating over comments.richContents directly and changing the for each loop to a for loop didn't change the result though.

The answer to WHY it didn't work probably lies somewhere in the specifics of JS.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号