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 File with Field data plus append more information

Avatar

Level 3

I am looking to create a button that will save a button and append the data from a field to it when I save it.  So it would be a click event in javascript and inside the "saveFile" information would append TextField1 and "some text I make up" which would create the saved file name.

1 Accepted Solution

Avatar

Correct answer by
Level 3

Hi There

Not sure if you have sorted this.

But I would achieve this using the trusted function

create your form as usual

then create an extra subform and make it in to a save as box (just add a textfield and some text and a button)

have the save button on the form simply call the saveas subform

saveas.presence = "visible";

then the button on the saveas subform have the following code (under click event in javascript)

saveas.presence = "hidden";

event.target.saveasFunc();

to get this function to work you need to create a .js file using notepad with the following code

saveasFunc = app.trustedFunction(function () {
app.beginPriv();


var text1 = event.target.xfa.resolveNode("form1[0].saveform[0].TextField1[0]").rawValue;
var text2 = event.target.xfa.resolveNode("form1[0].saveform[0].saveas[0].TextField2[0]").rawValue;

try {
event.target.saveAs("/c/forms/" + text1 + " " + text2 + ".pdf");
} catch (err) {
app.alert("Error: " + err);
}
app.endPriv();
});

Obvisously setting the targets correctly and the save directory

then save this file as any name you like .js e.g. (saveas.js) then place this file in the c:\program files\adobe\acrobat\javascripts, or similar but with reader if using adobe reader.

If you intend to use this file in reader then you will need to enable extended features in reader on the file using Adobe Acrobat.

OK the above is only availble where you have the ability to load the .js file in to the correct directory.

I used it by creating a simple installation file which placed the .js file in teh correct directory and the form ont eh end users computer.

It may or may not work for you.

If I can be of any further help let me know.

View solution in original post

0 Replies

Avatar

Correct answer by
Level 3

Hi There

Not sure if you have sorted this.

But I would achieve this using the trusted function

create your form as usual

then create an extra subform and make it in to a save as box (just add a textfield and some text and a button)

have the save button on the form simply call the saveas subform

saveas.presence = "visible";

then the button on the saveas subform have the following code (under click event in javascript)

saveas.presence = "hidden";

event.target.saveasFunc();

to get this function to work you need to create a .js file using notepad with the following code

saveasFunc = app.trustedFunction(function () {
app.beginPriv();


var text1 = event.target.xfa.resolveNode("form1[0].saveform[0].TextField1[0]").rawValue;
var text2 = event.target.xfa.resolveNode("form1[0].saveform[0].saveas[0].TextField2[0]").rawValue;

try {
event.target.saveAs("/c/forms/" + text1 + " " + text2 + ".pdf");
} catch (err) {
app.alert("Error: " + err);
}
app.endPriv();
});

Obvisously setting the targets correctly and the save directory

then save this file as any name you like .js e.g. (saveas.js) then place this file in the c:\program files\adobe\acrobat\javascripts, or similar but with reader if using adobe reader.

If you intend to use this file in reader then you will need to enable extended features in reader on the file using Adobe Acrobat.

OK the above is only availble where you have the ability to load the .js file in to the correct directory.

I used it by creating a simple installation file which placed the .js file in teh correct directory and the form ont eh end users computer.

It may or may not work for you.

If I can be of any further help let me know.

Avatar

Level 1

This is an awesome script and can't wait to get it working.  I have a few questions regarding this.  How do you call the subform?  I have livecycle designer and the script editor up.

Avatar

Level 3

Hi Nathan

I would be happy to help, but am unsure what you wish to know.

To call up a subform you first have to create the subform e.g. to look like a dialogue box with a save button and custom text if required.

Then create a button on the main form that displays the above subform

subform.presence = "visible";

Then have the save button on the subform run the saveas script and hide the subform

subform.presence = "hidden";

event.target.saveasFunc();

The above code is written in Javascript not FormCalc.

Hope this helps. If you need any more help let me know.

Regards

Graham

Avatar

Level 1

Thank you so much for responding. I have tried what you have put below

and when I click the buttons I get nothing. Should I be putting

"subform.presence = "visible";" in the "mouse up" javascript area and then

the "subform.presence = "hidden"; event.target.saveasFunc();" in the

initialize section of the javascript? That is where my confusion lies.

When I open livecycle designer what section does the Javascript go in.

Also, should the subform and button be visible when I save the form and

then open it in Adobe Reader?

Nathan Marles

207-317-1589

www.marles.net <http://www.marles.net

Avatar

Level 3

Hi Nathan

put both codes under the click event on the respective buttons, with

javascript selected for the language

Regards

Graham

Avatar

Level 1

Okay. Again, I hate to keep bothering you. I have placed the code in the

perspective area and put the javascript (saveas.js) in the adobe

javascript folder and when I test the file nothing happens when I hit

either button. Can you email me directly? I can give you my phone number

so that maybe we can resolve this faster. My email is sales@marles.net.

Thank you so much for your help,

Nate

Avatar

Level 1

Okay, I have tried to put your code in my form and or edit it to match my situation multiple times.  I have a form that I would like to save to a specified directory with the name of a property and a date inside the form. The form has a property field that is a text box and a date field which is a standard date field.  I am clueless onto where to put the javascript in my form.  I have tried adding the javascript to the button and then adding it to the javascript folder program files/adobe.  No luck!  Any help?  Thanks.

Avatar

Level 10

HI,

I just need more details.

How does your scripts looks like?

Do you get any errors in Acrobats JS Console when you execute the script?

Avatar

Level 3

Hi All

For some reason there must be an update that has come through which has

caused and issue with my script.

I have tried to fix but cannot..... maybe someone from Adobe could look in

to this.

If I create a new form with the script it will not work, you get a console

error telling you the function we are calling is not a function.

Older forms I have created previously still work (and the script has not

been changed) however I have even tried copying an older form and

modifying and it then stops working.

the button script reads event.target.saveForm(); (in Javascript)

The console shows the .js file as being registered. (saved in C:\Program

Files\Adobe\Acrobat 9.0\Acrobat\Javascripts)

The .js file is as follows

saveForm = app.trustedFunction(function () {

app.beginPriv();

var param1 =

event.target.xfa.resolveNode("form1[0].Int[0].Header[0].all[0].param1[0]").rawValue;

var param2 =

event.target.xfa.resolveNode("form1[0].Int[0].Header[0].all[0].param2[0]").rawValue;

var param3 =

event.target.xfa.resolveNode("form1[0].Int[0].Header[0].all[0].param3[0]").rawValue;

var folder =

event.target.xfa.resolveNode("form1[0].Int[0].Header[0].all[0].folder[0]").rawValue;

try {

if (folder == "") {

event.target.saveAs("/C/" + param1 + "-" + param2 + "-" + param3 +

".pdf");

} catch (err) {

app.alert("Error: " + err);

}

app.endPriv();

} else {

event.target.saveAs("/C/" + folder + "/" + param1 + "-" + param2 + "-" +

param3 + ".pdf");

} catch (err) {

app.alert("Error: " + err);

}

app.endPriv();

}

});

Can anyone understand why it works on previous files but not on any

created now????

Thanks

Graham

From: radzmar <forums@adobe.com>

To: Graham Spaull <gspaull@moog.com>

Date: 04/07/2011 19:20

Subject: Save File with Field data plus append

more information

HI,

I nned just more details.

How does your scripts looks like?

Do you get any errors in Acrobats JS Console when you execute the script?

Avatar

Level 10

Ok,

there were several 'bugs' in your script.

I made different changes and tested it. It works for me.

To execute the function use in your form.

Avatar

Level 3

Hi

After reviewing my script again there were some issues most noticeably two

try statements and only one catch.

Many thanks for your help.

I got mine working in the end but not as refined as yours.

Thanks once again

Graham

Avatar

Level 1

Nice! But... I have slightly different problem (wish). Is there a way to alow "distributed form" to be saved with a field data as a new  fille name. Let me explain; I'm making a form in LC and I use a Distribute Form option. Instead of using acrobat.com service I'm using manual e-mail sending/colection. Now, I would like that when a person click, let's say a SendBack button, a form get's renamed with some value from certain field in a form. So when he click a SendBack button, the form "MyJobApplication.pdf" get's renamed into "MyJobApplication-John_Smith.pdf".

As you can see there's no option to modify JS security file since this should be done on client side and probably he just have a Adobe Reader.

Any Idea is greatly appreciated!!!