9 Replies Latest reply on Jan 23, 2016 9:20 AM by try67

    prevent changing file name and auto populate field

    jay fresno Level 1

      Using Acrobat DC Pro.

      Is it possible to prevent a user from changing the file name of an acroform if they choose Save or Save As?

      If it is not possible to prevent the user from changing the file name, is it possible to automatically populate a form field with the new file name when saving, or when submitting the pdf?

      I hope someone can help.

        • 1. Re: prevent changing file name and auto populate field
          try67 MVP & Adobe Community Professional

          Preventing it is not possible.

           

          However, you can prevent the file from being submitted if it has a

          different name. That would require using a script, though.

           

          It's also possible to set the field to show the file-name, using this code

          at the doc-level:

           

          this.getField("FileName").value = this.documentFileName;

          • 2. Re: prevent changing file name and auto populate field
            jay fresno Level 1

            Thank you. What would the script look like for preventing the file from being submitted with a different name? An example would be very helpful to me as I am not proficient in JavaScript.

            • 3. Re: prevent changing file name and auto populate field
              jay fresno Level 1

              Adding to my last comment, once the form field is populated with the file name upon opening the file, is there a way to prevent the form field's file name from changing, even if the user saves with a different name? In other words, once the PDF is opened, the form field populates with the current file name. Then, the text in the form field never changes, even after repeated opening and saving of the file with a different file name.

              • 4. Re: prevent changing file name and auto populate field
                try67 MVP & Adobe Community Professional

                - You can use something like this as the Submit button's MouseUp script:

                 

                if (this.documentFileName=="DesiredName.pdf") this.submitForm({cURL: "enter the target URL here"});

                else app.alert("Invalid file-name!");

                 

                - Change the code to something like this:

                 

                if (this.getField("FileName").valueAsString=="") {

                     this.getField("FileName").value = this.documentFileName;

                }

                 

                This will cause the field to only update when it's empty, ie after you clear the form.

                • 5. Re: prevent changing file name and auto populate field
                  jay fresno Level 1

                  Thanks for your help.

                  I need a way of keeping track of what the original file name was before the user changed it.

                  Using the suggested script would not be practical because of the time involved in editing the script for each and every PDF file sent to a user.

                  Your idea of populating a form field with the file name is a good start, but once the field is populated with the original file name, I need a way of preventing the that form field from changing -- even if the user changes the original file name.

                  This is the way it would work. The user opens the pdf. The form field gets populated with the original file name. The user saves the pdf with a different file name. The form field does not update to the new file name; instead it still displays the original file name.

                  Is that possible?

                  • 6. Re: prevent changing file name and auto populate field
                    jay fresno Level 1

                    The main thing that needs to be accomplished is that the original file name remains in a form field so that the original file name (along with info from all form fields in the pdf) can be imported to a database.

                    • 7. Re: prevent changing file name and auto populate field
                      try67 MVP & Adobe Community Professional

                      Just change this part:

                       

                      if (this.documentFileName=="DesiredName.pdf")

                       

                      To:

                       

                      if (this.documentFileName==this.getField("FileName").valueAsString)

                      • 8. Re: prevent changing file name and auto populate field
                        jay fresno Level 1

                        This is working great if the user saves the pdf with a new name, and does not close and reopen the pdf. However, if the user saves with new name, closes and reopens the pdf, the "FileName" field updates to the new name upon reopening.

                        Is there a way to do this:

                        The user opens the pdf. The FileName form field is populated with the original file name. The user saves the file with a new file name, and closes the file. The user then reopens the renamed file. The FileName form field does not change to the renamed file name; instead it continues to display the original file name.

                        The main idea is that no matter what the user does, I need a way to keep track of the original file name in one of the form fields.

                         


                        .

                        • 9. Re: prevent changing file name and auto populate field
                          try67 MVP & Adobe Community Professional

                          I don't follow. This should not matter... The first time you open the file FileName will be populated. Save it and it will keep having the same value after that (unless you reset the entire file). You should deliver to your users a file that already has a populated FileName field in it.