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

发布于 2024-12-08 16:09:57 字数 1470 浏览 0 评论 0原文

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

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

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

在控制台中打印文本的内容,但颜色根本没有改变。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-12-15 16:09:57

似乎“Span”对象被复制,而不是在我的代码中的某处引用。
创建一个数组来保存更改后的 Spans,然后将该数组分配给 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 并将 foreach 循环更改为 for 循环并没有改变结果。

为什么的答案它不起作用可能在于 JS 的细节中的某个地方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文