Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Saving to a predefined path

Not applicable
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?
15 Replies
pguerett
Level 10
Level 10
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.
Not applicable
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?
pguerett
Level 10
Level 10
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");
Not applicable
Same error with that code as well.
pguerett
Level 10
Level 10
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.
_Edgar_van_Waar
Level 2
Level 2
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
Not applicable
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
Not applicable
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)
_Edgar_van_Waar
Level 2
Level 2
When you trust a signature, you need to select the permissions. Make sure options "Execute high privilege JavaScripts..." and "Perform privileged system operations..." are switched ON.



By default these are switched of, but are required to allow access to the local filesystem for saving.
Not applicable
I went to Preferences -> Javascript Enable menu items Javascript execution privileges and checked it. Where is the Perform privileges system operations checkbox?
_Edgar_van_Waar
Level 2
Level 2
Appearently there is some misunderstanding: The mentioned options are part of trusting the applied digital signature on the document. So when a user opens the form a message appears that the signatures wasn't validated yet. ("The validity of the document certification is UNKOWN. The author could not be verified.")



In case of Reader/Acrobat version 8:

When you have a look at "Signature properties", you find a tab "Signer". Here you will find a button called "Show Certificate...". Click this one and another window appears (called "Certificate Viewer"). Select the "Trust" tab here and click the "Add to Trusted Identities...". Some messagebox appears: just click OK. Now another dialog pops up (called "Import Contact Settings"). Here you find checkboxes "Dynamic Content" and "Embedded high priviledge JavaScript", which should be switched on. Now close all opened dialogs by clicking the OK button.
Not applicable
I have enabled all trust settings, but I still get this same error:



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

Doc.saveAs:3:XFA:topmostSubform[0]:Page1[0]:Button1[0]:mouseUp
_Edgar_van_Waar
Level 2
Level 2
Are you testing on Acrobat or Reader? In case of Reader the form will also need to be Reader Extended (or Usage rights needs to be enabled from Acrobat)
Not applicable
I've extended the rights for Reader and also have tried with Acrobat 8. Can't get it to work. Perhaps I could send the file to you?