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

Need help with creating a custom "Finalize Form" button

djparent
Registered: May 5 2009
Posts: 5
Answered

I'm a total n00b with LCD, so please bear with me. I've already spent many days on Google, and though I've learned much about Javascript I haven't found anything similar to what I need to do. I hope someone here can help!

What I'm trying to do:

-create a 'Finalize' button which will perform three functions; open the 'save as' dialogue to save the filled out form, set all fields to read only, and make the button disappear from the newly saved form. There is a print button on the form which must remain active after saving, and I want all of this to work from Reader once completed.

What I've got so far:

-script to open 'save as dialogue';

app.execMenuItem("SaveAs");

-script to set all fields read-only;
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
var oFields = xfa.layout.pageContent(nPageCount, "field");
var nNodesLength = oFields.length;
// Set the field property.
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
oFields.item(nNodeCount).access = "readOnly";
}
}

Basically I need to know what I need to add to the script to keep my print button, known as form1.Page1.PrintButton, active after clicking, and to make the 'Finalize' button invisible. I tried adding the line:
form1.Page1.FinalizeForm.style.visibility="hidden";
to the script but it did not seem to work.

What am I doing wrong?

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
For being a noob you've got a great start.

The "presence" property controls the visibility of form elements. This tutorial covers a bunch of the XFA scripting concepts, including hiding and showing fields.

http://www.acrobatusers.com/events/online/245

To exclude certain fields from being set to read only, qualify the line of code that sets the access property with an "if" statement.
if(oFields.item(nOndeCount).name == "MyField")...

If you've got more than one then use an object
var testFields = {"MyField1":true, "MyField2":true};....

if(testFields[oFields.item(nOndeCount).name])....

Or name them a certain way and use a regular expression

To do proper LiveCycle programming you'll need both the Acrobat JavaScript Reference and the Adobe XML Form Object Reference, these and lots of other docs can be found at www.adobe.com/devnet. You should also get a book that covers Core 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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

djparent
Registered: May 5 2009
Posts: 5
Thanks Thom!
djparent
Registered: May 5 2009
Posts: 5
Ok, I've done some more reading and now it works. Everything is entered as a 'click' event, and I had to save the form as 'dynamic xml' and change the script state-change properties to 'automatic'.

Here is my script:

for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
var oFields = xfa.layout.pageContent(nPageCount, "field");
var nNodesLength = oFields.length;
// Set the field property.
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
if(oFields.item(nNodeCount).name !== "PrintButton") {
oFields.item(nNodeCount).access = "readOnly";
}
}
}
{this.presence = "hidden";
app.execMenuItem("SaveAs");}
matrix27
Registered: May 2 2009
Posts: 9
i have created a form and linked all fields to an MS Access 2003 database. I wanted a Button that would contain a script to save all the contents of the fields into the MS Access 2003 database...Pls help.

Adobe Livecycle ES
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please post this question to a new thread.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

aajay
Registered: Jul 2 2009
Posts: 2
Do you happen to know if it’s possible to enter a UNC path the Jscript expression, to offer a standard place to save all the PDF filled out?

I simply want to make sure that all my employees save to same path

Regards
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Unfortunately No. That would be really nice. When run from a document script the JavaScript saveAs function displays the SaveAs dialog using the default path, which is usually the last path used. Could be the path the form was opened from but you can't know. This is part of the JavaScript sandboxing to keep potentially dangerous scripts from interacting with the users system.

However, since this is for you employees and I assume that means its in house, you have another option. When run from a privileged folder level script the saveAs function can specify an exact folder location. If you can install a folder level script on all of your employees systems then your special set of form could be saved to a specific location.

Look up the doc.saveAs function in the Acrobat JavaScript reference and read these articles:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts
http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions

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

webpointz
Registered: May 21 2009
Posts: 36
I have a "app.trustedFunction" script that gets called when a digital signature is signed in a PDF in a browser on the webserver.

It passes the path and filename to do a "doc.saveAs" works works great when the path is either local or uses the drive letter and path of a network folder, however I can't rely on "mapping" of the drive and the letter being used.

Is there any particular settings on IIS that would allow it to use the UNC Path?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, if the location was a WebDav Server. Then you could use an URL

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

webpointz
Registered: May 21 2009
Posts: 36
Thanks...that's helpful!

I have one further question...the PDF being signed is in a web browser page. The local Reader javascripts folder has a Config.js file with a trustedFunction handling the "doc.saveAs" and it works perfectly.

My only remaining question is once the PDF is signed, is there a way that I can force a reload of the web page that has the PDF? I would like to reload the page because I have code that checks the signed output for a signature and if it's signed it will instead show a message that the PDF was signed rather than stay on screen showing the signature.

Thanks
Michael
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hmm, Acrobat doesn't have any direct control over any containing application. But there are some things that can be done. You can force the web page to open with app.launchURL(), this might cause the HTML page containing the PDF to be replaced, but it also might not be reliable. There is JavaScript message passing mechanism between Acrobat and a containing HTML page. Under well controled circumstances I've seen this used to good effect.

You'll find an example here:

http://www.windjack.com/resources/howto.php

Scroll down to the "IE Browser/Acrobat intercommunication" link.

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

webpointz
Registered: May 21 2009
Posts: 36
Excellent...thanks for the quick response!
webpointz
Registered: May 21 2009
Posts: 36
Looks like there is just ONE more hurdle.

When I run everything locally on my test server everything works great...but as soon as i place on a development server, the PDF isn't saving the file to the UNC Path.

My question is...under the digital signature field, I am running a javascript that is passing the path and filename to a function that is as follows:

// SaveAs Function: DO NOT REMOVE
var SaveDoc = app.trustedFunction(function(doc,pathtofile,filename) {

app.beginPriv();

var myPath = pathtofile + filename;

// saveAs is the only privileged code that needs to be enclosed
// with beginPriv/endPriv
doc.saveAs(myPath);
this.hostContainer.postMessage(["close"]);
app.endPriv();

});

The above is contained in CONFIG.JS on MY local machine under the Reader/Javascripts folder.
Is THIS file being accessed by the webserver OR does this file need to be somewhere else?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Looks like you've made a lot of progress. But as you're finding out there are a number of issues with Acrobat and the Internet. Mostly, Acrobat is very sensitive to security. On your local server the security thing between the client and server is very controlable. I've had exactly this same problem before where an app stopped working when I moved it to my remote test server.

I haven't personally used WebDav stuff before, but I know from other developers that it does not "Just Work". There's some setup on the server side that needs to be done to allow Acrobat to interact with it. I can't point you in the right direction for this one except to say that there must be some info out there about it because these other developers were able to get it working.

The Folder level JavaScript files are only availible to Acrobat/Reader on the local system. All activity in Acrobat and Reader is local. The server has no direct access to anything on the local system through Acrobat/Reader. So, your local trusted function will only work for you.

There are a few options if you need remote users to have access to this trusted function. First off they can't be random remote users. They will have to do some kind of setup in order to make this work.
Remote users will have to do one of the following

1. Install the folder level script on thier system
2. Certify the PDF with a digital signature on thier system (which they are already doing?)
In this case you don't need a trusted function since the saveAs can operate directly from
the PDF
3. Add the web site or PDF as trusted in the Enhanced Security Acrobat/Reader Preference. (Actually I haven't given this one a good testing. Trusted Locations work for some privileged operations and not for others. So this may not be enough to make it work)

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

webpointz
Registered: May 21 2009
Posts: 36
Thanks for your help in this matter...excellent, excellent advice all of the way.

After a few permissions hiccups, the system is solid and working magnificently. One last question I do have is this:

The PDF is pre-assembled using iText and coldfusion, then enhanced for reader using Acrobat Pro. When the initial PDF is assembled, the digital signature field has a "mouse-up" event that when clicked on, calls the "signing dialog". It works great when the user provides their password and click the OK button, however, how do I handle if they "CANCEL" the action. Right now OK or CANCEL fires the javascript call.

Here is the code under the signature field:

acroForm = writer.getAcroForm();
acroForm.addSignature("signature", 40, 50, 340, 140).setAction(PdfAction.javaScript("

// Requires Config.JS script functions in Acrobat Reader folder

SaveDoc(this,'#PathToFile#','#OutFilePDF#');

", writer));




Kindest regards
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
That's a good one. I'd suggest separating out the actions. There's a "signing" event. I'm not sure where in the process it's called. But you could do some tests to figure out if it happens after the signing process, at which point you could use the signatureValidate function to determine if the document was actually signed. There's also a signatureSign function that returns a status value. If the signing is done with this function you'd have a positive indication that a signature was applied.

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

webpointz
Registered: May 21 2009
Posts: 36
Actually...I tried the following after debugging:

var sigCheck = this.getField('signature').value;

if (sigCheck == '<>') {
SaveDoc(this,'networkpath','filename.pdf');
}

Tried the above in the Acrobat JavaScript Debugger trapping the field value in an ALERT box.
Seems that when a signature is successfully added it has a passed value in the getField of "<>" and if the cancel button is selected it has NO value at all.So the code when the file is built looks as follows:

acroForm.addSignature("signature", 40, 50, 340, 140).setAction(PdfAction.javaScript("

var sigY = this.getField('signature').value;

if (sigY == '<>') {
// Requires Config.JS script function below in Acrobat Reader javascripts folder
EPSaveDoc(this,'#NetworkPathToFile#','#PDFFilename#');
}", writer));
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Brilliant!! That's a good one to know. Have you tried it on Reader, and in different versions?

I'll have to check it out.
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

webpointz
Registered: May 21 2009
Posts: 36
Thanks...this is ALL in Acrobat Reader v9.0. Haven't tried older versions yet.
webpointz
Registered: May 21 2009
Posts: 36
Oops...one further question with regard to your "HostContainer" code:

Right now, I have everything (all form elements) being put into ONE field in the PDF. What is the best way to have it so that each form element value gets placed into different PDF fields on the post?

Example:

FORM: PDF
InputText1.value >>>> this.myDoc.getField('name')
InputText2.value >>>> this.myDoc.getField('address')etc.

Thanks
Michael
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well, you've got to place the data individually. No other way around it. If you have known and consistent fields, and they are always in the same order the easiest thing to do is to hard code the field names. As you've shown in your post. But you could always generalize it a bit by passing the field names with the values, and then do a little parsing,

EX: Name and value are separated by a ":"
  OnMessage(aMsg){for(var i=0;i<aMsg.length;i++){var aData = aMsg[i].split(":");this.getField(aData[0]).value = aData[1];}}

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

webpointz
Registered: May 21 2009
Posts: 36
Thanks Thom

I have modified the code so that now everything is running beautifully updating multiple acrofields from multiple form fields.

Two outstanding issues remain and I am not sure why they occur:

1. using iText to create the PDF and following documentation, I set each of the text fields to "name.setOptions(TexField.READ_ONLY)" which allows each of the fields to be updated by the code but NOT by direct user interaction in the PDF and it works great. BUT if I have a MULTILINE text field I can't seem to make IT readonly as well (ie. name.setOptions(TextField.READ_ONLY | TextField.MULTILINE). In Coldfusion it says the space before the "|" character is an invalid token.

2. when signing the digital signature field, a popup for signing shows a checkbox "Lock document after signing". If I leave this blank, the CONFIG.JS file works, the HostedContainer code fires and the document is saved...if however, it is CHECKED, nothing happens after signing??

Do you know of a reason why this occurs and if so how i can disable it? I would rather NOT have to tell users "don't check the box" for obvious reason - lol

Thanks
Michael
webpointz
Registered: May 21 2009
Posts: 36
Worked out the issue with assigning multiple "setOptions" for a TextField.

In ColdFusion code, instead of :

name.setOptions(TextField.MULTILINE | TextField.READ_ONLY);

use

name.setOptions(BitOr(TextField.MULTILINE,TextField.READ_ONLY));

This is courtesy of the folks at CFSEARCHING.COM.

Still can't figure out the "Lock document after signing" issue.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm not sure about the locking issue. Locking fields is pretty much just making them ReadOnly. It shouldn't affect anthing the code is doing. It's an option on the Signature field properties. This property is probably being set by your code that creates the fields. But regardless, the only reason I would think that the following code is not being run is that an exception is being thrown when the fields are locked.

Is there any reason you need the fields to be locked on signing? Can you change how this is done?

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

webpointz
Registered: May 21 2009
Posts: 36
That's the thing...i DON'T want the users to be able to checkbox the "lock after signing". I notice that if you make it so that the signature field is set to "read only" after signing, the "lock" checkbox doesn't appear. This is new to v9.1 apparently.

Bottom line is that I don't want the checkbox to even show to the user during signing.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, I'm not sure about that one, it's beyond my experience. Seems like it's one of those operational details that keeps changing with the version. Like I said before, signing is an "on the edge of security" feature. Which means that it's subject to change as Adobe's ideas about security change.

Sorry, I'm tapped out. I don't know if that dialog can be suppressed or not. My first thought was that if locking is not set in the signature field properties that it wouldn't ask. But I could have it backwards, maybe if you deliberately set the locking in the field properties it won't show the dialog. Locking is setup in the "Signed" tab of the Sigature field properties dialog. From Acrobat JavaScript use the "field.setLock()" function to do the same thing.

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