简体   繁体   English

Adobe Acrobat Pro DC JavaScript字段属性无法传播

[英]Adobe Acrobat Pro DC JavaScript field properties not propagating

I have been brought in mid stream on an Adobe Acrobat Pro DC customization project. 我是Adobe Acrobat Pro DC定制项目的中游对象。 The goal of this project is to add a warning along the left edge of each page. 该项目的目标是在每页的左边缘添加警告。 I have been given a piece of JavaScript that does this with one exception and asked to fix that exception. 我得到了一块JavaScript,它可以做到一个例外,并要求修复该例外。

The code is: 代码是:

var inch = 72; 
for (var p = 0; p < this.numPages; p++) { 
    var aRect = this.getPageBox( {nPage: p} ); 
    aRect[0] = 8.25*inch; //how far from the left the box ends
    aRect[1] = 0.5*inch; //how high from the bottom the box is
    aRect[2] = 7.75*inch; //how far from the left the box starts
    aRect[3] = 11.0*inch; //how tall the box is
    var f = this.addField("ControlledDoc", "text", p, aRect ) 
    f.rotation = 270;
    f.delay = true; 
    f.textSize = 7.5; 
    f.textFont = font.HelvB; 
    f.textColor = color.red; 
    f.alignment = "center"; 
    f.readonly = true; 
    f.display = display.visible; 
    f.delay = false; 
}
var myWillSaveScript = 'var f = this.getField("ControlledDoc"); \r' 
+ 'f.value = "This is an electronic controlled copy of a paper based document management system. When printed on the copy machine it becomes an uncontrolled paper copy valid until the end of the printing day."; \r';
this.setAction("WillSave", myWillSaveScript);

The problem presents when a document is more than one page in length. 当文档的长度超过一页时,就会出现此问题。 The ControlledDoc field is replicated on each page as expected. 按预期在每个页面上复制ControlledDoc字段。 Each page gets a ControlledDoc#n-1 field, where n is the page number. 每个页面都有一个ControlledDoc#n-1字段,其中n是页码。 On the first page, the f.rotation setting is retained and shows up in the UI as the Orientation dropdown in the Properties dialog being set to 270. However, on the second and subsequent pages the Orientation is set to 0. I can manually edit the document and set the Orientation to 270, but that defeats the purpose of automating things with JavaScript. 在第一页上,保留了f.rotation设置,并在UI中以“属性”对话框中的“方向”下拉列表设置为270的方式显示。但是,在第二页及后续页面上,“方向”设置为0。我可以手动编辑文档并将“方向”设置为270,但这违反了使用JavaScript自动化事物的目的。

I am new to controlling Acrobat Pro DC with JavaScript, so I will not be surprised if I am missing something stupid... 我不熟悉使用JavaScript控制Acrobat Pro DC,因此,如果我缺少一些愚蠢的东西,我也不会感到惊讶。

What do I need to change to make the rotation setting stick on the second and subsequent pages? 我需要更改什么以使旋转设置贴在第二页及后续页面上?

Field properties can be on a field level (the same for all copies of the field, with the same nam), or on a widget level (can be different from copy of the field to copy of the field). 字段属性可以在字段级别(对于该字段的所有副本都相同,具有相同的名称),也可以在小部件级别(可以随字段副本的不同而不同)。

The Acrobat JavaScript documentation has a list of those properties. Acrobat JavaScript文档包含这些属性的列表。 Unfortunately, those two lists (field level and widget level) do not contain the rotation property. 不幸的是,这两个列表(字段级别和窗口小部件级别)不包含rotation属性。 That means, we do not really know whether it is field or widget level. 这意味着我们并不真正知道它是字段级别还是小部件级别。 From your description, I get the feeling that it is widget level. 从您的描述中,我感觉到它是小部件级别的。

What you may try is to create an individual field for every page. 您可以尝试为每个页面创建一个单独的字段。 You would do that with the line 你会用线做

var f = this.addField("ControlledDoc." + p, "text", p, aRect) ;

About the delay property: I always use the doc.delay property (instead of the field.delay ), and because of that outside of a loop, so that it can provide maximum performance gain. 关于delay属性:我总是使用doc.delay属性(而不是field.delay ),并且由于处于循环之外,因此它可以提供最大的性能提升。 However, if the script exits from within the loop, I would have to set delay to false via the Console. 但是,如果脚本从循环中退出,则必须通过控制台将delay设置为false。 From my experience, this will create all appearances (but in order to find out, we'd have to get onto that page, and then they are created immediately…). 根据我的经验,这将创建所有外观(但是要找出原因,我们必须进入该页面,然后立即创建它们……)。

I'm assuming you're on page 1 when you run the script. 我假设您在运行脚本时位于第1页。 That's why it looks correct on page one. 这就是为什么它在第一页上看起来正确的原因。

The delay property, when false, tells Acrobat to delay updating the appearance of the field until it's set to true. delay属性为false时,它告诉Acrobat延迟更新字段的外观,直到将其设置为true。 When you add the field to the pages, you're telling Acrobat not to generate appearances until all of the settings are set... that's OK... but then, I suspect, you never visit the subsequent pages so the appearances never get updated for those pages even though the delay property is now set to true. 当您将字段添加到页面时,是在告诉Acrobat在设置所有设置之前不要生成外观...没关系。但是,我怀疑,您永远不会访问后续页面,因此外观永远都不会得到即使delay属性现在设置为true,这些页面也会更新。 Just pull out the two lines that set the delay property and it should work. 只需拉出设置delay属性的两行,它就可以工作。

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

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