Skip to main content
Participating Frequently
June 2, 2022
Answered

using saveAs method with a default name

  • June 2, 2022
  • 1 reply
  • 597 views

Hi,

 

I would like to use some field values to generate a default pdf name when I click on a button with the saveas method.

 

Here is whay I did but does not work:

 

*********************************************************************

var pp = this.getPrintParams();
var printRange = [];
var name = +this.getField("Nom_Prof_T").valueAsString +"_" +this.getField("Assignatura_T").valueAsString +"_" +this.getField("Curs_Trim_T").valueAsString +".pdf";

printRange.push([0,0]); // print page 1
printRange.push([2,3]); // print page 3 and 4

pp.pageHandling = 3;
pp.printRange = printRange;
nUpAutoRotate = true;
nUpNumPagesH = printRange;


this.print(pp);
this.saveAs(name);

 

*********************************************************************

 

I store the pdf name in the name variable dna I want to use it as default "saveas" name. What I'm doing wrong???

 

Thanks

This topic has been closed for replies.
Correct answer try67

You can't specify the file-path of the saved file if you run the script from an unprivileged context, such as a button in the file itself. Doing that requires creating a trusted function in a folder-level script (a .js file installed on the local computer, basically), and then calling that function from your code. Alternatively, you can display the desired file name to the user in an alert window and ask them to copy it and use it in the Save As dialog, but you can't enforce it.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 2, 2022

You can't specify the file-path of the saved file if you run the script from an unprivileged context, such as a button in the file itself. Doing that requires creating a trusted function in a folder-level script (a .js file installed on the local computer, basically), and then calling that function from your code. Alternatively, you can display the desired file name to the user in an alert window and ask them to copy it and use it in the Save As dialog, but you can't enforce it.

Participating Frequently
June 9, 2022

ok, thanks for your response