Copy link to clipboard
Copied
Javascript newbie here,,,and thanks in advance for any help.
I am simply trying to add a couple of spaces when using a javascript to save a file. The file is an employment application which is named "Phoenix Employment Packet.pdf" When an applicant presses the SAVE button, I would like the saved file to go into a specified network folder with a new filename using the "last name" and "first name" fields of the form.
Everything seems to be working fine, except I cannot get it to save WITH spaces. For example: Fred Smith fills it out and saves. The resulting file name is: smithfredapplication.pdf instead of: smith fred application.pdf. or even better yet, smith, fred application.pdf.
Here is my code. Any help is greatly appreciated.
this.saveAs("/c/APPTESTFILE/" + this.getField("lastname").value + "" + this.getField("firstname").value + "" + "application.pdf");
Oh...running Adobe Acrobat Pro DC no Win10 64bit
Every place you want to add a blank space, replace "" with " ". You should also get the field values using the valueAsString property. So the entire line of code should be:
this.saveAs("/c/APPTESTFILE/" + this.getField("lastname").valueAsString + " " + this.getField("firstname").valueAsString + " " + "application.pdf");
Note that this won't work in a button action unless the document has a certification signature and the user chooses to trust it to allow privileged JavaScript. It will work in the
...Copy link to clipboard
Copied
Every place you want to add a blank space, replace "" with " ". You should also get the field values using the valueAsString property. So the entire line of code should be:
this.saveAs("/c/APPTESTFILE/" + this.getField("lastname").valueAsString + " " + this.getField("firstname").valueAsString + " " + "application.pdf");
Note that this won't work in a button action unless the document has a certification signature and the user chooses to trust it to allow privileged JavaScript. It will work in the interactive JavaScript console, which you can use for testing. For more information, see: https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript
Copy link to clipboard
Copied
Thank you SO much!! Works perfectly!
[Edited by Moderator]