3 Replies Latest reply on Jan 25, 2013 6:20 AM by try67

    how to use javascript to "save as" using form data in the file name

    BTMURPHEY21

      I want to be able to use a button to "save as" and have it automatically pick up and use certain data from the fields in the file name. without having to manually type in the file name.

       

      Name: john doe

      Date: 1-25-13

       

      file name would be  (john doe 1-25-13)

        • 1. Re: how to use javascript to "save as" using form data in the file name
          try67 MVP & Adobe Community Professional

          This is only possible if you can install a script on the local machine of

          each user that is going to use the form.

          Otherwise, the best you can do is display a window *suggesting *the new

          file name to the user. You can't enforce it.**

          • 2. Re: how to use javascript to "save as" using form data in the file name
            BTMURPHEY21 Level 1

            the form will only be used on one machine/ multiple users. would you be willing to give me a sample script?

            • 3. Re: how to use javascript to "save as" using form data in the file name
              try67 MVP & Adobe Community Professional

              You will need two parts for this. A folder level script (which you place in a .js file under the JavaScripts folder of Acrobat), and a script embedded in the file itself (probably attached to a button).

              The folder-level script will look like this:

               

              var mySaveAs = app.trustedFunction( function(oDoc,cPath) {

                  app.beginPriv();

                  try {

                      oDoc.saveAs(cPath);

                  } catch(e){

                      app.alert("Error During Save");

                  }

                  app.endPriv();

              });

               

              The doc-level script can look something like this (of course, you might need to adjust the names of the fields used):

               

              var filePath = this.path.replace(this.documentFileName, "");

              var newFileName = this.getField("name").valueAsString + " " + this.getField("date").valueAsString + ".pdf";

              mySaveAs(this, filePath+newFileName);

               

              You should be aware that several characters are not allowed in the file name, including comma's, forward- and back-slashes, line-breaks and excalmation marks, so if you try to use them the script would fail. It is possible to create a more advanced version of this script that will automatically remove such characters from the file-name, or alert the user if they used them.