Adobe Acrobat Pro DC JavaScript field properties not propagating

934 views Asked by At

I have been brought in mid stream on an Adobe Acrobat Pro DC customization project. 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.

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. Each page gets a ControlledDoc#n-1 field, where n is the page number. 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.

I am new to controlling Acrobat Pro DC with JavaScript, so I will not be surprised if I am missing something stupid...

What do I need to change to make the rotation setting stick on the second and subsequent pages?

2

There are 2 answers

2
joelgeraci On BEST ANSWER

I'm assuming you're on page 1 when you run the script. 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. 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. Just pull out the two lines that set the delay property and it should work.

0
Max Wyss On

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. Unfortunately, those two lists (field level and widget level) do not contain the rotation property. 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. However, if the script exits from within the loop, I would have to set delay to false via the Console. 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…).