Skip to main content
Participant
October 20, 2018
Answered

SAVING A SPACE IN FILE NAME

  • October 20, 2018
  • 1 reply
  • 1321 views

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

This topic has been closed for replies.
Correct answer George_Johnson

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

1 reply

George_JohnsonCorrect answer
Inspiring
October 21, 2018

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

MBMIKE101Author
Participant
October 21, 2018

Thank you SO much!! Works perfectly!

[Edited by Moderator]