16 Replies Latest reply on Aug 12, 2013 12:47 AM by try67

    Submit with new file name

    jay fresno Level 1

      Using Acrobat XI, Is there was a way to script an Acrobat PDF form so the filename could be saved using the information from the form. For example, if the form contains fields for First Name, Last Name, and Student ID number, is there a way to create a SUBMIT button that when clicked creates a pdf file with their name or student ID number as the filename?

        • 1. Re: Submit with new file name
          MichaelN Level 3

          Look at this thread:

           

          http://forums.adobe.com/message/5179303#5179303

           

           

          You can adapt the script that is there.

          • 2. Re: Submit with new file name
            jay fresno Level 1

            Thanks for the link, Michael. The script almost does what I want.

            I have a SUBMIT button. Using the script you suggested, when the Submit button is clicked, a window appears and the user can copy the new file name. That's good. After copying the file name, the email appears (because the submission is by email) and the PDF is automatically attached to the email. BUT, there is no way to change the file name of the attached PDF.

            If anyone has suggestions, I'd greatly appreciate it.

            • 3. Re: Submit with new file name
              MichaelN Level 3

              Hi Jay,

               

              Due to security restrictions, the SaveAs method can only be executed during a batch or console event.

               

              Try the following as part of a Batch command:

               

              //Create the file name from text fields in the form

              //Credit to Gilad D for the first part of this script.

              var myFileName = this.getField("First_Name").valueAsString + "_" + this.getField("Last_Name").valueAsString + "_" + this.getField("Student_ID").valueAsString;

               

              //Save the file

              this.saveAs("/c/name of your destination folder goes here/" + myFileName + ".pdf");

               

              //Attach it to an email

              this.mailDoc({

              cTo: email1@example.com,    //enter the destination email address

              cSubject: "Type subject here",   //enter subject line

              cMsg: "Type message here"    //enter a message

              });

               

               

              This script will save the PDF as something like "John_Smith_123456.pdf" into the destination folder that you specify, then attach it to an email.

               

              You can read about the saveAs method here:

              http://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/JS_API_AcroJS.88.519.html

               

               

              and the mailDoc method here:

              http://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/JS_API_AcroJS.88.500.html

               

              I hope this helps.

               

              Michael

              • 4. Re: Submit with new file name
                jay fresno Level 1

                Michael,

                Thank you. I will give this a try. Do you know if the script will work in Adobe Reader?

                • 5. Re: Submit with new file name
                  jay fresno Level 1

                  Michael,

                   

                  I may not have made myself clear as far as what is needed, and I apologize for that. I'm not an experienced JavaScript programmer, just a regular user trying to implement a feature, so please bear with me.

                   

                  This is the workflow:

                  1. I create the form in Acrobat XI.
                  2. The form is distribute to about 100 people. Most of those people are using Reader, some on Mac and some on PC.
                  3. These people fill out the form, save it and return it to me.

                  When they save the PDF, it is at that point that the PDF needs to be renamed by pulling the information that each person enters into the form for their Name and Student ID.

                   

                  Is this even possible?

                  • 6. Re: Submit with new file name
                    try67 MVP & Adobe Community Professional

                    Only if a script is installed on the local machine of each user. Otherwise,

                    the best you can do is "suggest" to them which file-name to use when saving

                    the file.

                    • 7. Re: Submit with new file name
                      MichaelN Level 3

                      Jay,

                       

                      I would try the following workflow:

                       

                      1. Create a text field in the form that collects the person's information in a format such as "John_Smith_123456.pdf". This field would be populated automatically when they enter their personal information.

                       

                      2. People using Reader save the file normally and email it back to you.

                       

                      3. You place the forms into a folder.

                       

                      4. Using Acrobat, you create a Batch action that looks at that folder, opens their PDF, reads the field containing "John_Smith_123456.pdf" and then uses that as the file name when it saves it to the destination folder using the script posted above.

                       

                      This is just a suggestion, and you may need to experiment a bit.

                      • 8. Re: Submit with new file name
                        jay fresno Level 1

                        Michael,

                        I appreciate your suggestions. Although your suggestions sound promising, without more detailed instructions about how to set up the field that wuld be populated automatically and how to set up the Batch action, I would not be able to pull off the workflow you are suggesting. I'm just not skilled enough at scripting. It would be helpful to have a sample file, but I realize that would be too great an imposition on your time.

                        • 9. Re: Submit with new file name
                          MichaelN Level 3

                          Hi Jay,

                           

                          Let's assume you have 3 text fields already in your form, named as follows:

                           

                               First_Name

                               Last_Name

                               Student_ID

                           

                          Create another text field and call it something like "File_name".

                           

                          Use this script as the custom calculation script for the "File_name" field:

                           

                               var myFileName = this.getField("First_Name").valueAsString + "_" + this.getField("Last_Name").valueAsString + "_" + this.getField("Student_ID").valueAsString;

                              

                               this.getField("File_name").value = myFileName;

                           

                           

                          When the student completes the fields above, their information will automatically appear in the "File_name" field:

                           

                          Student Form.jpg

                           

                          You do not need to know scripting to create a Batch action. The exact method depends on the version of Acrobat you are using, so check the user guide for your version of Acrobat. You can get the Batch action to trigger the script shown in post no. 3 above.

                           

                          Michael

                          1 person found this helpful
                          • 10. Re: Submit with new file name
                            jay fresno Level 1

                            Michael,

                            Your latest post has given me some hope.

                            I followed your instructions to create the 4 form fields, and that works fine.

                            As far as the batch process, I'm using Acrobat XI Pro.

                            I set up the action for 'Currently open file as default', next I added an Execute JavaScript step and for the script, entered the same code that you have for the File_Name field.

                            I deleted the File_Name text field on the form because what I want to happen is that the file gets renamed automatically.

                            Is it possible to automatically rename the file or do I have to leave the File_Name field on the form and copy and paste the name into the Save As dialog box?

                            Untitled-1.gif

                            • 11. Re: Submit with new file name
                              MichaelN Level 3

                              Hi Jay,

                               

                              Yes you can delete the File_Name text field off the form. It will still work. It was there only to illustrate the example I gave you in post no.9.

                               

                              You are almost there, but your screen shot looks like you have pasted in the wrong script.

                               

                              You should paste in the script from post no. 3.

                               

                              Michael

                              • 12. Re: Submit with new file name
                                jay fresno Level 1

                                That's encouraging. When I open the form and click on the script it does run, but it doesn't do  anything. I have Acrobat X Pro installed on my laptop. Is it easier with that version?

                                • 13. Re: Submit with new file name
                                  MichaelN Level 3

                                  No, it should be the same for both versions.

                                   

                                  What email program do you use?

                                  • 14. Re: Submit with new file name
                                    jay fresno Level 1

                                    MS Outlook 2007

                                    • 15. Re: Submit with new file name
                                      MichaelN Level 3

                                      Send me a link to the file using private messages and I will have a look at it for you offline (and include the Batch command's script)

                                      • 16. Re: Submit with new file name
                                        try67 MVP & Adobe Community Professional

                                        This script doesn't do anything except populate the field with the value

                                        you want to use for the file-name.

                                        The user can use it, or they can choose not to use it. You can't enforce it

                                        on them.

                                         

                                        I prefer to use an alert message, actually, instead of a form field. That

                                        way you can present to the user the desired file-name just before they save

                                        the file and ask them to use it. But again, you can't enforce it on them.