• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

using saveAs method with a default name

New Here ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , JavaScript , PDF forms , Print and prepress

Views

281

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 02, 2022 Jun 02, 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.

Votes

Translate

Translate
Community Expert ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

LATEST

ok, thanks for your response

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines