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

Javascript button with SaveAs prompt and generated filename based on fields

Community Beginner ,
Jan 05, 2023 Jan 05, 2023

Helly everyone,
As the title suggests I would like to place a button inside the pdf file which prompts the SaveAs function with generated filename based on the field values inside the pdf file. Then the user only needs to select the path. In the past I've made a JS function on a button with stores the pdf file automatically in a path but now I want the user to be able to decide where to store. Is that even possible?

I made the following script for auto name and auto save...

// splice supplier (get first word in field)
var supplier = this.getField("3").value;

// always cut after 10
var supplierNew = supplier.slice(0, 9);

// if space found, cut:
if (supplierNew.includes(" ")){
var supplierNewNew = supplierNew.split(" ", 1);
} else {
var supplierNewNew = supplierNew;
};

// make a file name from the field values
var fileName = this.getField("1").value + "_" + this.getField("Group2").value + "_" + this.getField("Dropdown4").value + "_" + supplierNewNew + "_" + this.getField("54").value;

fileName = fileName.replace("\\","");
fileName = fileName.replace("/","");
fileName = fileName.replace(":","");
fileName = fileName.replace("*","");
fileName = fileName.replace("?","");
fileName = fileName.replace("\"","");
fileName = fileName.replace("<","");
fileName = fileName.replace(">","");
fileName = fileName.replace("|","");

// get the path where the file is currently located
var filePath = this.path.replace(this.documentFileName, "");

// create the new full path
var newFullFilePath = filePath + fileName + ".pdf";

if ((this.getField("1").value.length < 1) || (this.getField("Group2").value.length < 1) || (this.getField("Dropdown4").value.length < 1) || (this.getField("3").value.length < 1) || (this.getField("54").value.length < 1)){
app.alert("Es sind nicht alle Pflichtfelder (*) ausgefüllt!");
} else {
try {
this.saveAs(newFullFilePath);
} catch (e) {
app.alert("Error! Could not save as: " + newFileName);
}};

TOPICS
Create PDFs , JavaScript , PDF forms
1.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 06, 2023 Jan 06, 2023
Translate
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
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Not possible.

Translate
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
Community Beginner ,
Jan 06, 2023 Jan 06, 2023

I think you are right. Is it why the Acrobat Reader cannot communicate with the Windows SaveAs prompt?

Translate
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
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Correct

Translate
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
Community Beginner ,
Jan 06, 2023 Jan 06, 2023

Thank you for your response.

Translate
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
Community Beginner ,
Jan 09, 2023 Jan 09, 2023
LATEST

FYI I have found a workaround. With JS I save the file in /c/temp/ with the following function: 
this.saveAs(filePath + fileName + ".pdf"); 
and after that I call 
app.execMenuItem("SaveAs");
so that the user able to select a new path with the filename prefilled to the prompt

Translate
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