Link to home
Start Free TrialLog in
Avatar of d-smith
d-smith

asked on

Adobe Acrobat Form- Create a Javascript "Save As" Button to save with a name in a shared drive.

Hey experts,

I'm having trouble with my fillable PDF Form. Our enviroment is Windows XP, Office XP, Adobe Acrobate 5, and 2003 server. What i'm trying to do is have a form out on a shared drive (K:\Managed Care\Referral Request Form) so users can fill it out and then automatically save in (K:\Managed Care\Referral Request Form\Incoming Forms), with a name pulling from the "LNAME", "FNAME", and "NUMBER" fields, and then clear the form when they push the button. It would make the process go by faster for them because they do a lot a day. That way they can refer back to that form too if they need to print it again, email, etc.

So far, i've tried different code on my own, from EE, Google, etc and still can't get it correctly. I've tried app, functions, and doc objects but i keep getting this error.
                                             uncaught exception:Field SAVE:Mouse Up:1: Global.saveAs
                                             Security settings prevent access to this property or method.

If someone could help me out with the proper coding, I would appreciate it.
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Do you have the AcroJS document from Adobe? If you lookup the Doc.saveAs method, you'll notice that there are security notes in the description: "This method can only be executed during batch, console or menu events. ... Beginning with Acrobat 7.0, execution of JavaScript through a menu event is no longer privileged, ..." and "The parameter cPath is required to have a Safe Path and an extension appropriate to the value of cConvID...."

From your short description, it's not obvious into which security violation your code runs, but the error message is very specifc.

How are you calling saveAs? What are the parameters? Are you using only Acrobat 5?
Avatar of d-smith
d-smith

ASKER

Yes I do have the AcroJS documentation. I wasn't sure how much that security note would limit my goal to do this, so I figured I would post my dilemna up here to find a way to make this work any way.

this.saveAs("K/Managed Care/Referral Request Form/" + LNAME + FNAME + NUMBER ".pdf");

And Yes majority of Acrobat 5, but I think there might be some with 6. No 7 though.

Is this supposed to save a file to drive K:? If so, you need to start the path with a slash: "/K/Managed Care/..."
Avatar of d-smith

ASKER

Yes to the K drive. I added the slash and i'm still getting the same error
Is the save function a button on the form, or a menu item in Acrobat?
Avatar of d-smith

ASKER

button on the top right of the form
That's the problem. If you look back to my first comment, you'll notice that the saveAs() function can only be executed during a menu, batch or console event. A button event is not permitted to perform a Save As.

You need to install a JavaScript program that gets executed at Acrobat startup time, and that installs either a menu item that your user's will use, or a JavaScript function that your document can call.
Avatar of d-smith

ASKER

Ah ok i see the difference now. I thought as long as you were doing a menu action such as saving, you were within a menu event.  Is there anywhere you can point me to the right direction for that or how I can get that done?
Avatar of d-smith

ASKER

I should also add, I've never done any menu additions like this.
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of d-smith

ASKER

I loaded up the SaveAsProc.js into the Javascript folder. I didn't have to change the path or anything too, but I got this error when I opened up the form. Any ideas?

                                ReferenceError: ÿþ is not defined

I got this error when I opened up Acrobat with different pdf's.
Did you create the JS file as a text file? What tool did you use? It looks like there is some binary data in the file, which should not be the case. Try it again with NotePad.
Avatar of d-smith

ASKER

Ah ok that worked better that was my fault, but now i'm getting this error.

TypeError: this.getField is not a function
Avatar of d-smith

ASKER

My fault again. Variables weren't in the function. I also changed the cpath a little bit. Here is the script I put to use and tested it out. It works the way I want it too perfectly. Thanks khkremer. I appreciate the help.  

// get the values for LNAME, FNAME and NUMBER from the file

function SaveAsProc()
{

var LNAME = this.getField("LNAME").value;
var FNAME = this.getField("FNAME").value;
var NUMBER = this.getField("NUMBER").value;

    this.saveAs("/K/Managed Care/Referral Request Form/Incoming Forms/pati"+ LNAME + FNAME + NUMBER +".pdf");
}    


// create a new menu item:

app.addMenuItem({
     cName: "Save to Server",
     cParent: "File",
     cExec: "SaveAsProc();",
     cEnable: "event.rc = (event.target != null);",
     nPos: 7
});

// end of script
Sorry about that. That was my fault.