[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4186
  • Last Modified:

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.
0
d-smith
Asked:
d-smith
  • 8
  • 7
1 Solution
 
Karl Heinz KremerCommented:
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?
0
 
d-smithAuthor Commented:
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.

0
 
Karl Heinz KremerCommented:
Is this supposed to save a file to drive K:? If so, you need to start the path with a slash: "/K/Managed Care/..."
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
d-smithAuthor Commented:
Yes to the K drive. I added the slash and i'm still getting the same error
0
 
Karl Heinz KremerCommented:
Is the save function a button on the form, or a menu item in Acrobat?
0
 
d-smithAuthor Commented:
button on the top right of the form
0
 
Karl Heinz KremerCommented:
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.
0
 
d-smithAuthor Commented:
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?
0
 
d-smithAuthor Commented:
I should also add, I've never done any menu additions like this.
0
 
Karl Heinz KremerCommented:
OK, here is a script that will work. Save this program in Acrobat's JavaScript directory (for Acrobat 7 this is C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Javascripts) as a file with the extension .js (e.g. SaveAsProc.js):


// get the values for LNAME, FNAME and NUMBER from the file
var LNAME = this.getField("LNAME").value;
var FNAME = this.getField("FNAME").value;
var NUMBER = this.getField("NUMBER").value;

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


// create a new menu item:

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

// end of script

You may have to change the path, and you may have to come up with a way to extract the values for your variables from the active document.
This script will add a new menu item to the "Document" menu.

0
 
d-smithAuthor Commented:
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.
0
 
Karl Heinz KremerCommented:
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.
0
 
d-smithAuthor Commented:
Ah ok that worked better that was my fault, but now i'm getting this error.

TypeError: this.getField is not a function
0
 
d-smithAuthor Commented:
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
0
 
Karl Heinz KremerCommented:
Sorry about that. That was my fault.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now