Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Saving to a predefined path

Avatar

Former Community Member
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

Avatar

Former Community Member
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.

Avatar

Former Community Member
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?

Avatar

Former Community Member
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");

Avatar

Former Community Member
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.

Avatar

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

Avatar

Former Community Member
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

Avatar

Former Community Member
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)

Avatar

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.

Avatar

Former Community Member
I went to Preferences -> Javascript Enable menu items Javascript execution privileges and checked it. Where is the Perform privileges system operations checkbox?

Avatar

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.

Avatar

Former Community Member
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

Avatar

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)

Avatar

Former Community Member
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?