These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

script for check boxes

flyboy3300
Registered: Mar 2 2010
Posts: 59

I am looking for help with a script that would check a box in one pdf when it is checked in a seperate pdf

My Product Information:
Acrobat Pro 8.1.6, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Communication between PDFs is tricky. Are both PDFs guarenteed to be together all the time? In the same relative locations? Can the check box be set in both documents, or only one?

The exact solution depends on the specifics. But the first step is to make both documents visible to each other through the JavaScript model. This is done by setting the document "disclosed" property to true in a document level script.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

flyboy3300
Registered: Mar 2 2010
Posts: 59
They are together but are in seperate folders, I am wanting to make only one check box work for both. Hope that answers your qestions, thanks for the help
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I guess the best strategy is to add a script to the mouseup event of the check box. The script should open the other file and set the value of the check box in that other file to the new value of the check box in the current file.
var oDoc = app.openDoc("../otherfolder/OtherFile.pdf",this);if(oDoc)oDoc.getField("check").value = event.target.value;

In order for this to work both files must be present and disclosed.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Is it your intention that the (second) file will close after the change?
If so, I would change Thom's script like so:
var oDoc = app.openDoc({cPath: "../otherfolder/OtherFile.pdf",oDoc: this, bHidden: true}); // Open the target file but keep it hidden from the userif(oDoc) {oDoc.getField("check").value = event.target.value; // Change the valueoDoc.saveAs(oDoc.path); // Save the fileoDoc.closeDoc(true); // Close the file}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
Thanks for all your help, here is what I put in;
var oDoc = app.openDoc({jPath: "\!Crisis Command Center\A. VP Flight Operations\Originals/MasterIndex.pdf",oDoc: this, bHidden: true}); // Open the target file but keep it hidden from the user
if(oDoc) {
oDoc.getField("a1").value = event.target.value; // Change the value
oDoc.saveAs(oDoc.path); // Save the file
oDoc.closeDoc(true); // Close the file
}

But this does not work what did I do wrong?

Thanks
flyboy3300
Registered: Mar 2 2010
Posts: 59
and this was the other that I tried;

var oDoc = app.openDoc("J:\!Crisis Command Center\A. VP Flight Operations\Originals\01-MasterIndex.pdf",this);
if(oDoc)
oDoc.getField("a1").value = event.target.value;

and it did not work also

Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
"did not work" is useless to us. If you want help, you need to provide more information.
What happened? What error messages did you see?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
Sorry, that was the proplem nothing happen. I checked the one box and nothing happen to the other check box. There was no error msg
try67
Expert
Registered: Oct 30 2008
Posts: 2398
And... what did it say?
Also, why did you change cPath to jPath in app.openDoc ? There's no such thing as jPath.
Also, your file path is not a valid one according to Acrobat JavaScript's standards.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Look in the Console window to get the error message. Although one issue is obvious. The path is completely wrong. Read this article:
http://www.acrobatusers.com/tutorials/file-paths-acrobat-javascript

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

flyboy3300
Registered: Mar 2 2010
Posts: 59
After reading you input and the webpage I changed the script to this;

var oDoc = app.openDoc("../J/!CrisesCommandCenter/A.VPFlightOperations/Orginals/01-MasterIndex.pdf",this);
if(oDoc)
oDoc.getField("a1").value = event.target.value;

This still does not work for the check mark in the second pdf. I have looked for error msg and do not see any. A little more back up on this is, I am trying to have a check list that has checkboxes and when they start the checklist with the first box it will show in a seperate pdf that has a list of different checklist that they have started thier checklist by checking the box automatically.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Drop the double dots in the beginning of the path. You should only use them for a relative path, and yours is absolute.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
Thanks, tried that and it still does not work
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Try this, just for testing purposes put the file in a simple location, like in the same folder as the same one the open file is in.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

flyboy3300
Registered: Mar 2 2010
Posts: 59
I put both pdf in the same file and changed the scipt to reflect this;

var oDoc = app.openDoc("/X/Safety/CrisisCommandCenter/MasterChecklist/TEST/01-MasterIndex.pdf",this);
if(oDoc)
oDoc.getField("d1").value = event.target.value;

Still no luck with it working

Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Try running just this line from the console:

app.openDoc("/X/Safety/CrisisCommandCenter/MasterChecklist/TEST/01-MasterIndex.pdf");
Does the file open?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
No it does not
try67
Expert
Registered: Oct 30 2008
Posts: 2398
So there's something wrong with your path.
Try this: open the file manually, open the console and run this code:
this.path
What does it print out?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
I have the path corrected and it will open the file now but it still will not check the box
flyboy3300
Registered: Mar 2 2010
Posts: 59
This is what I used has the last part of the script;

if(oDoc)
oDoc.getField("d1").value = event.target.value;

Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
OK... we're getting close. This code is too compact for debugging, though. Try this:

if (oDoc!=null) {var fieldname = "d1";var f = oDoc.getField(fieldname);if (f!=null) {console.println("Applying value " + event.target.value + " to field '"+fieldname+"'.");f.value = event.target.value;} else {console.println("Can't find field called '"+fieldname+"' in this document.");}} else {console.println("oDoc is null");}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
If I understand you this should be added on to the script that opened the file and the complete script looks like this now;

app.openDoc("X:/Safety/Crisis Command Center/Master Checklists/TEST/01-MasterIndex.pdf",this);
if (oDoc!=null) {
var fieldname = "d1";
var f = oDoc.getField(fieldname);
if (f!=null) {
console.println("Applying value " + event.target.value + " to field '"+fieldname+"'.");
f.value = event.target.value;
} else {
console.println("Can't find field called '"+fieldname+"' in this document.");
}
} else {
console.println("oDoc is null");
}


This still did not check the box
try67
Expert
Registered: Oct 30 2008
Posts: 2398
But what does it say in the console???

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
oDoc is null
try67
Expert
Registered: Oct 30 2008
Posts: 2398
First line of the code needs to be:
var oDoc = app.openDoc("X:/Safety/Crisis Command Center/Master Checklists/TEST/01-MasterIndex.pdf",this);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
I changed the first line to that and I still get oDoc is null
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The file path is written as relative to the current document path. That's why it's not finding it. Also, "oDoc" is not assigned in the code. If the files are in the same folder then no path elements are needed. Just write it as:

var oDoc = app.openDoc("01-MasterIndex.pdf",this);

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

flyboy3300
Registered: Mar 2 2010
Posts: 59
That brings the pdf open but it is still not checking the box
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Again, what's displayed in the console window?

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

flyboy3300
Registered: Mar 2 2010
Posts: 59
There was nothing showing with the changes that was made the oDoc null went away
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In the code Try67 gave you he specifically included console.println messages for every step in the process. Certainly something must have been printed to the console?

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

acamerer
Registered: Apr 20 2010
Posts: 7
thomp wrote:
In the code Try67 gave you he specifically included console.println messages for every step in the process. Certainly something must have been printed to the console?
Hi, I'm a coworker of Flyboy's helping out today. I'm getting the same result: odoc is null. The 01-MasterIndex is opening, but not changing and not closing as try67's code would seem to indicate. Here's the code I have (I have the files in two different folders under a master folder as in the real environment):

var oDoc = app.openDoc("../A-VP_Flight_Operations/01-MasterIndex-ac.pdf",this);
if(oDoc) {
oDoc.getField("d1").value = event.target.value; // Change the value
oDoc.saveAs(oDoc.path); // Save the file
oDoc.closeDoc(true); // Close the file
}
if (oDoc!=null) {
var fieldname = "d1";
var f = oDoc.getField(fieldname);
if (f!=null) {
console.println("Applying value " + event.target.value + " to field '"+fieldname+"'.");
f.value = event.target.value;
} else {
console.println("Can't find field called '"+fieldname+"' in this document.");
}
} else {
console.println("oDoc is null");
}

Great website, btw! We're tempted to buy something ... :)
flyboy3300
Registered: Mar 2 2010
Posts: 59
With the complete code in including what Try67 put I get this in the console

syntax error
1:Console:Exec
undefined
flyboy3300
Registered: Mar 2 2010
Posts: 59
Here is what I am getting with Try67 orginal code;

var oDoc = app.openDoc({cPath: "../dhlacvgfs003/Astar/Safety and Security/Safety/Safety/Crisis Command Center/Master Checklists/TEST/01-MasterIndex.pdf,oDoc: this, bHidden: true}); // Open the target file but keep it hidden from the user
if(oDoc) {
oDoc.getField("d1").value = event.target.value; // Change the value
oDoc.saveAs(oDoc.path); // Save the file
oDoc.closeDoc(true); // Close the file
}



syntax error
1:Console:Exec
undefined
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You guys are editing the code that we supply to you in ways that cause it to malfunction.
You need to be very careful when copying and pasting or editing the code.
In my original code the cPath argument was surronded by quotes. In your version there's only only quote, which is why you're getting this error message.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

flyboy3300
Registered: Mar 2 2010
Posts: 59
Is this the correction that is needed with the second quote marks, after the pdf? Here is what it looks like with the same error msg.;

var oDoc = app.openDoc({cPath: "../dhlacvgfs003/Astar/Safety and Security/Safety/Safety/Crisis Command Center/Master Checklists/TEST/01-MasterIndex.pdf",oDoc: this, bHidden: true}); // Open the target file but keep it hidden from the user
if(oDoc) {
oDoc.getField("d1").value = event.target.value; // Change the value
oDoc.saveAs(oDoc.path); // Save the file
oDoc.closeDoc(true); // Close the file
}




syntax error
1:Console:Exec
undefined
flyboy3300
Registered: Mar 2 2010
Posts: 59
I can go back to this with out anything about the checking the box and it will bring the second pdf up;

app.openDoc("/dhlacvgfs003/Astar/Safety and Security/Safety/Safety/Crisis Command Center/Master Checklists/TEST/01-MasterIndex.pdf");



[object Doc]
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Sorry, I give up...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Sorry I didn't get in on this earlier. I believe that the problem is that the documents are not disclosed. I believe I mentioned this in my first two posts.

Add this line of code to a document level script in all PDFs involved

this.disclosed = true;

Here's an article on entering doc scripts
http://www.acrobatusers.com/tutorials/2007/07/js_document_scripts

You might also want to read this article:
http://www.acrobatusers.com/tutorials/file-paths-acrobat-javascript

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

acamerer
Registered: Apr 20 2010
Posts: 7
Thom,
Ken got the document to open and the box to check/uncheck with this code:

var oDoc = app.openDoc("01-MasterIndex.pdf",this);
if(oDoc)
oDoc.getField("d1").value = event.target.value;

So we wanted to get the doc to save and close, so added Try67's code:

if(oDoc) {
oDoc.getField("d1").value = event.target.value; // Change the value
oDoc.saveAs(oDoc.path); // Save the file
oDoc.closeDoc(true); // Close the file
}

but it throws the following error:
NotAllowedError: Security settings prevent access to this property or method.
Doc.saveAs:6:Field d1:Mouse Up

Any advice? I can't see the answer. Sorry for the trouble...
Thanks,
Alan
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, Read this article:
http://www.acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

acamerer
Registered: Apr 20 2010
Posts: 7
Thom,
I read that article, thanks! So I was trying various permutations of the save options available shown in the article and at best I keep getting the error below. The tempcheck.pdf doc is opening, but no check showing even though it says it's changing the field, no save and no close...

CURRENT CODE:
var oDoc = app.openDoc({cPath: "/dhlacvgfs003/Astar/Safety and Security/Safety/Safety/Crisis Command Center/Master Checklists/TEST/tempcheck.pdf",oDoc: this, bHidden: false}); //I set hidden to false so I could see the doc open and see if it was changing... Open the target file but keep it hidden from the user

if (oDoc!=null) {
var fieldname = "D1";
var f = oDoc.getField(fieldname);
if (f!=null) {
console.println("Applying value " + event.target.value + " to field '"+fieldname+"'.");
f.value = event.target.value
this.saveAs("/c/temp/temp.pdf"); // Save the file
console.println("Saving...");
//oDoc.closeDoc(true); // Close the file
} else {
console.println("Can't find field called '"+fieldname+"' in this document.");
}
} else {
console.println("oDoc is null");
}

CONSOLE RESPONSE:
Applying value Yes to field 'D1'.

NotAllowedError: Security settings prevent access to this property or method.
Doc.saveAs:9:Field d1:Mouse Up

...but not sure why because both documents are 'disclosed' as you indicated.
There is no security on either document.

Thanks for any help or even just a clue to the right direction...
ac
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to re-read the section called "Creating a custom save function" from Thom's article.
It's not possible to use saveAs directly in a form script in later versions of Acrobat.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

acamerer
Registered: Apr 20 2010
Posts: 7
Thank you. I re-read the article. So how do you save a file and close it with said later version of Acrobat? The code you gave at the beginning of this discussion said to use the oDoc.saveAs command... is there a time many versions ago when that would have worked?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In the past Acrobat was a bit looser with the scripting. But computing environments have gotten a bit more paranoid since then and Adobe has tightened up security, and continues to do so. Saving is one of the casualties.

The only way to save a PDF from a script is for that script to be executed from a privileged context. There are several different ways to create a privileged context, for example, batch scripts are privileged by default and so is the Console Window. A document can be made privileged by saving it as certified. But it will only remain privileged if the certifying signature is on the users machine and the document has not been changed in any way that breaks certification.

The article I refered you to uses a folder level trustedFunction to create privilege. I believe that try67 though that this function was being performed by a folder level automation script, or from the console. the saveAs function would never work from a non-certified document script. My original script did not include saving and closing. I figured the user would have to do this when they were done with the forms.

So how is this document going to be used? General distribution, or in a limited/controled set of users?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

acamerer
Registered: Apr 20 2010
Posts: 7
Thanks Thom. This will definitely be a controlled group. Aircraft accident information is very highly gaurded in an actual incident. We just want the VP to be able see the status of his 'underlings' progress at a glance.

I'll email a diagram I've created of the process, to help you see what we're trying to do.

Suffice it to say that there are about 15 people who have checklists of things they need to do in the case of an accident, and the VP in charge needs to see their progress if any. We have checklists for each of them, which we are guessing need to export their data to an intermediate master list, which is then accessed by the VP's Master checklist. We're doing it this way so that there is no conflict with open documents (ie, Master checklist is open so underling user can't access it directly).
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Given your workflow you have a better option. First, you would be well served with a pair of toolbar buttons for controling the process. One for exporting data and one for importing data into the master. These toolbar buttons drive very simple automation scripts. One to export a data file to a predefined location. And one to import the data file from that predefined location. The import script would need to be much more complex since it's importing data from more than one file.

Importing and exporting data is much simpler and more reliable than trying to open and set field values in another PDF. Another option is to use a DB connection. But this will not work in Reader. Probably the most general purpose solution would be to use a server script to contol the import/export process.

So you have lots of options.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script