Copy link to clipboard
Copied
Could someone please tell me how to correct the script below or provide an alternate script that will allow me to pull text from a text field labeled "ID" to use in performing a SAVE AS and RENAME with a form button in a PDF?
Thanks!!!!
I took this script from:
https://acrobatusers.com/forum/javascript/generating-filename-when-saving-acrobat-form/
where the "ID" text field = 19746
but I get an error that says:
Error! Could not save as: /C/Users/Me/underdfined19746.pdf
// get the value of the form field
var text1Value = this.getField("ID").value;
// here you need to make sure that no illegal characters are used, and also that text1Value is not empty
// make a file name from the field value
var newFileName = text1Value + ".pdf";
// get the path where the file is currently located
var filePath = this.path.replace(this.documentFileName);
// create the new full path
var newFullFilePath = filePath + newFileName;
try {
this.saveAs(newFullFilePath); // Only this will not work from a button...
} catch (e) {
app.alert("Error! Could not save as: " + newFullFilePath);
}
Copy link to clipboard
Copied
Your second parameter of replace is not defined:
Copy link to clipboard
Copied
Change this line:
var filePath = this.path.replace(this.documentFileName);
To:
var filePath = this.path.replace(this.documentFileName, "");
However, saving a file in this way requires a privileged context, which means you can't simply do it from a button field. See: https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more