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

How to use a script to "SaveAs" with specific location and field name?

Helthkare
Registered: May 20 2009
Posts: 9
Answered

I am using Acrobat 9 and have created a form which I would like users to be able to save the form to a specific target location and use a file name generated from the one of the fields in the form. The JavaScript would be executed upon a mouse up event and saved within the form itself.

I have tried the conventional app.execMenuItem("saveAs") function but it seems my request is a bit more demanding.

Can anyone help with achieving this function please?

I've tried the following with no luck:

app.beginPriv();
var myDoc = app.newDoc();
var myPath = app.getPath("user", "documents") + this.getField(“billcompany”) + ".pdf";
myDoc.saveAs(myPath);
return myPath;
myDoc.closeDoc();
app.endPriv();

AND

this.saveAs("/c/customer/invoices/" + this.getField(“billcompany”) + ".pdf");

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Are you getting any errors in the JavaScript debugging console?

Are you getting what you expect to get from the methods your are using?

console.println(' ');// get pathvar myPath = app.getPath("user", "documents");// display pathconsole.println('myPath = ' + myPath);// get field objectvar myField = this.getField("billcompany");console.println('myField: ' + myField);// get field object's valueconsole.println('myField.value: ' + myField.value);// try some computed file namesconsole.println('is this a file name?\n ' + myPath + myField + ".pdf");console.println('is this a file name?\n ' + myPath + "/"  + myField.value + ".pdf");

George Kaiser

Helthkare
Registered: May 20 2009
Posts: 9
I am not getting an error message or prompt that directly relates to it

NotAllowedError: Security settings prevent access to this property or method.
App.getPath:3:Field Submit:Mouse Up

Are you aware of a method that will allow me to implement a saveAs script?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Before you even start to attempt to work out a function, you need to get the basic script working.

Have you tried the code I posted?

It will show you a number of basic errors, even before you get to the save process.

I get the following response in the JavaScript debugging console:

Quote:
myPath = /C/Documents and Settings/loginid/My Documents
myField: [object Field]
myField.value: testBillCo
is this a file name?
/C/Documents and Settings/loginid/My Documents[object Field].pdf
is this a file name?
/C/Documents and Settings/loginid/My Documents/testBillCo.pdf

true

George Kaiser

Helthkare
Registered: May 20 2009
Posts: 9
I believe I may have started out wrong in the first place. I not very experienced with acrobat scripting, as most of what I know is self taught. I'll detail exactly what I would like to accomplish and you can tell me if the possibility exists.

In a mouse up action in my form for the submit button, I would like to run a javascript that would save my document to a specific folder on my drive. For example /c/documents and settings/helthkare/ and before saving adapt a name from one of the fields which is called "billcompany", hence saving as a pdf.

Will the above code you sent do just that?