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

SOLVED

Save As Script with predefined path and file name

Avatar

Level 3

Hello,

Livecycle version: 8.2.1.4029.1.523496

The aim of the script I have is to save the livecycle form to a predefined directory and using the values of a text field in the file name.

The script is placed in an exit event on a field using javascript as follows:

this.saveAs("/c/forms/Template/Leave Application "  + Applicants_Name.rawValue".pdf");

The script does not work.

Can any one please provide some assistance with correcting my script?

Any help will be most appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 2

The only way to so a SaveAs is by Trusted Folder-Level Script.

Create a javascript file (Config.js) in the Javascripts directory (usually C:\Program Files\Adobe\ Acrobat x.0\Acrobat\Javascripts, where x=the version of Acrobat you have installed).  In the .js file, put something like

// SaveAs Function1

var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var myPath = "/c/temp/" + "WhateverNameYouLike" + ".pdf";

// saveAs is the only privileged code that needs to be enclosed

// with beginPriv/endPriv

doc.saveAs({cPath: myPath,

bCopy: true,

bPromptToOverwrite: false});

app.endPriv();

});

Call the function like event.target.mySaveDoc(event.target); using javascript in a mouse up event of a button.

I hope this helps.

View solution in original post

6 Replies

Avatar

Level 6

app.execMenuItem("SaveAs"); is the code to open SaveAs dialog never tried with specified path....you can explore more and happy to share your findings...

Avatar

Level 3

Thank you for your reply.

I have changed the script from this.saveAs to event.target.saveAs as follows:

event.target.saveAs("/c/forms/Template/Leave Application " + Applicants_Name.rawValue + ".pdf");

I now get the error as follows:

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

Can you please offer any advice on if a trusted function would fix this, and how to use trusted function with saveAs?

Thank you.

Avatar

Correct answer by
Level 2

The only way to so a SaveAs is by Trusted Folder-Level Script.

Create a javascript file (Config.js) in the Javascripts directory (usually C:\Program Files\Adobe\ Acrobat x.0\Acrobat\Javascripts, where x=the version of Acrobat you have installed).  In the .js file, put something like

// SaveAs Function1

var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var myPath = "/c/temp/" + "WhateverNameYouLike" + ".pdf";

// saveAs is the only privileged code that needs to be enclosed

// with beginPriv/endPriv

doc.saveAs({cPath: myPath,

bCopy: true,

bPromptToOverwrite: false});

app.endPriv();

});

Call the function like event.target.mySaveDoc(event.target); using javascript in a mouse up event of a button.

I hope this helps.

Avatar

Level 1

Can you use for the file name a value from your pdf form? 

Ex: I have a field call "adress" and I whant the value contain in the field "adress" to appear in the file name.

Thank You

Avatar

Level 3

Thank you very much for your help.

I have created a folder level javascript and referenced the event.target.mySaveDoc(event.target); in the exit event of the field.

The leave form will now save to the users local c drive.

Your kind assistance is most appreciated.

Avatar

Level 6

This solution is misleading....

Of course this works only if you plan to load Trusted script on each machine you plan to use that form. In other words you can not rollout form to entire organization with out loading trusted function in each targeted machine.

Also there are other limitations... like if for some reason user reinstalls Acrobat x or Reader x or upgrade to latest version they need to remember to redeploy the trusted function to the required location.