Highlighted

Saving to a predefined path

Avatar

Guest

06-08-2008

I have been trying to setup a pdf to save to a predefined path upon closing. I tried using Acrobat's Will Close function to no avail, even though the code seems sound. I was just trying to execute the SaveAs menu item. Is there anything wrong with the code:



var aDocs = app.activeDocs;

var myDoc = aDocs[0];

var title = this.getField("Title");

var t = title.value;

myDoc.saveAs("C:\" + t + ".pdf");



I then opened the file in LiveCycle and attached this code to execute on the click of the button, but no file is generated on the C drive. Any ideas?

Replies

Highlighted

pguerett

06-08-2008

This code cannot be executed in an XFA form. There is a different object model that is used. The app object remains the same but the doc object and subsequent field objects are different. To get to the doc object you can use event.target and to get at field object values you can address the field name directly and ask for the rawValue. So your code in LC Designer will look like this:



var aDocs = app.activeDocs;

var myDoc = aDocs[0];

myDoc.saveAs("C:\" + Title.rawValue + ".pdf");



If this does not work have a look at the javascript console (Ctrl-J) to see if there are any errors generated.
Highlighted

Avatar

Guest

06-08-2008

When clicking on the button with that code, I get "unterminated string literal 3:XFA:topmostSubform[0]:Page1[0]:Button1[0]:mouseUp"



No idea what this means. Any suggestions?
Highlighted

pguerett

06-08-2008

It means that there is an error on line 3. Which means that myDoc is not a valid Doc object. I messed you up with my code. Change it to this:



var myDoc = event.target;

myDoc.saveAs("C:\" + Title.rawValue + ".pdf");
Highlighted

pguerett

07-08-2008

Another way to do it would be app.execMenuItem("saveAs")



Can you post your form to livecycle8@gmail.com and I will have a look at it.
Highlighted

_Edgar_van_Waar

07-08-2008

First of all you should be aware of the \-character in your path: because this is a reserved character within script (e.g. to force line-feeds), you need to use it double. So the last line of you script should be:



myDoc.saveAs("C:\\" + t + ".pdf");



Next you need to know that saving a document to a specified (local) path conflicts with the security policies of Acrobat/Reader. To allow such action you need to sign your document (and the certificate should be trusted by your user(s)), otherwise the save action just will be ignored.



I hope this will help!



Regards,



Edgar
Highlighted

Avatar

Guest

07-08-2008

I tried the extra '\' and put a valid, trusted signature on the document, but I still get an error. At least it's a new error now.



Title is not defined

3:XFA:topmostSubform[0]:Page1[0]:Button1[0]:mouseUp
Highlighted

Avatar

Guest

07-08-2008

Almost got it!



NotAllowedError: Security settings prevent access to this property or method.

Doc.saveAs:3:XFA:topmostSubform[0]:Page1[0]:Button1[0]:mouseUp



What exactly do I need to change in the Security Settings? (Don't understand the security settings at all)