Adobe Pro:使用 Javascript 更改 FreeText 注释的颜色
我正在使用 Adobe 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎“Span”对象被复制,而不是在我的代码中的某处引用。
创建一个数组来保存更改后的 Spans,然后将该数组分配给 comment.richContents 似乎工作正常。
效果很好。 (直接迭代
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.
That works fine. (iterating over
comments.richContents
directly and changing thefor each
loop to afor
loop didn't change the result though.The answer to WHY it didn't work probably lies somewhere in the specifics of JS.