17 Replies Latest reply on May 18, 2017 1:54 AM by Bernd Alheit

    How to protect some input fields of one PDF when sent to a customer?

    owanomono

      Hi,

       

      our company has a rather delicate problem. I think an example would be the best explaination:

       

      • A salesperson and a customer discuss a tender over telephone.

      • The salesperson fills out fields in a tender-PDF such as customer name, company, prices etc.

      • Some fields might not get filled in during this conversation. This is just how it is and can't be changed for several reasons. The PDF thus has to be sent to the customer for completion.

      • Now, when the PDF is received by the customer, we don't want the him/her to be able to change some of the fields, i.e. the agreed price fields. He/she should be "locked out" of those.

       

      So, we have a problem: the PDF will have to be fully accessible to the salesperson, but not to the customer, who receives the PDF with some fields in a "locked" state.

       

      Is this even possible to acheive? Any help would be most welcome.

       

      Johan

        • 1. Re: How to protect some input fields of one PDF when sent to a customer?
          George_Johnson MVP & Adobe Community Professional

          A simple way is to set the fields to read-only before saving and sending. Reader users won't be able to interact with such fields. Since you posted this in the security forum, I have to say that this cannot be considered secure. Someone with Acrobat would be able to populate the read-only fields with new data if they really wanted to. But this will prevent someone with Reader from easily/accidentally changing the field values.

           

          You can set the fields to read-only using a JavaScript, perhaps attached to a bookmark, button on the form, or something external to the form. Same for unlocking the fields if the form will be sent back for further changes. If you need help with this part, post again.

          • 2. Re: How to protect some input fields of one PDF when sent to a customer?
            owanomono Level 1

            Hi, thank you for your kind answer.

             

            Your solution looks very interesting with a javascript "driven button" that locks/unlocks certain fields on click. Since I'm not too experienced when it comes to managing security issues in Acrobat: how would you go about doing this? Is there some tutorial I could follow?

             

            Best Regards

             

            Johan

            • 3. Re: How to protect some input fields of one PDF when sent to a customer?
              George_Johnson MVP & Adobe Community Professional

              The code below is intended to be used for a bookmark, but it can be used in a button as well. The idea is you should rename all of the fields that you want to lock/unlock so that they begin with "PRIV.", though you can use any prefix you want. You'll just have to change the code to match. This allows you to manipulate them as a group, which simplifies the code. If the correct password is entered, the readonly property of the fields in the group will be toggled. Post again of you have any questions.

               

              (function () {

               

                  // Prefix for group field names. Change to match what you want to use.

                  // Rename the fields you want to lock to match this prefix (e.g., "PRIV.NAME")

                  var f_prefix = "PRIV";

               

                  // Your chosen password goes here

                  var pw = "1234";

               

                  // Get a reference to the first field in the group

                  var f = getField(f_prefix).getArray()[0];

               

                  //Determine new readonly state, which is the opposite of the current state

                  var readonly = !f.readonly;

                  var readonly_desc = readonly ? "lock" : "unlock";

               

                  //Prompt user for the password

                  var resp=app.response({

                      cQuestion: "To" + readonly_desc + "the fields, enter the password:",

                      cTitle: "Enter password",

                      bPassword: true,

                      cLabel: "Password"

                  });

               

                  switch (resp) {

                  case pw:

                      getField(f_prefix).readonly = readonly;

                      app.alert("The fields are now " + readonly_desc + "ed.", 3);

                      break;

                  case null:  // User pressed Cancel button

                      break;

                  default:  // Incorrect password

                      app.alert("Incorrect password.", 1);

                      break;

                  }

               

              })();

               

              Again, this can't be considered secure, but it would be unlikely for Reader users to mess with . I like to use a bookmark since it isn't visible on the page like a button is and it won't receive the focus by tabbing through the fields. If you decide to use a button, you can make it small and invisible in an out of the way location, so the user doesn't see it (though it can still be tabbed to) but you'll know where it is. You can set it up so that the Shift key has to be pressed for it to work, which most users wouldn't think to do if they come across it.

              • 4. Re: How to protect some input fields of one PDF when sent to a customer?
                owanomono Level 1

                Wow! Thanks a lot! :-)

                 

                It works just dandy when I added the javascript to a button. How to you add a bookmark and then the javascript to it? It might be a better solution as you propose.

                 

                Johan

                • 5. Re: How to protect some input fields of one PDF when sent to a customer?
                  George_Johnson MVP & Adobe Community Professional

                  Information on adding bookmarks is in the Acrobat help doc. In short, first display the Bookmarks pane on the left of the Acrobat window and add a new one by clicking the icon/button at the top of the pane. It will default to a "Go to a page in this document" action, which you can delete and replace with a JavaScript action that uses the same code.

                  • 6. Re: How to protect some input fields of one PDF when sent to a customer?
                    owanomono Level 1

                    Hello!

                     

                    Never mind assigning the javascript to bookmarks - I figured it out.

                     

                    I have a more serious problem, though. I not only use form fields but also dropdowns in the PDF:

                     

                    • All regular form fields get locked/unlocked with the script. No problem there.

                    • Drop downs does the same - but only in Reader. If I use Apple´s OSX and their default PDF viewer "Preview", I can still choose another option in a drop down list and it will stick when I close and reopen the PDF in Preview or Reader.

                     

                    I've tried to add the "PRIV.name" to the drop down but to no avail.

                     

                    Can the drop downs be locked somehow?

                     

                    Best Regards

                    Johan

                    • 7. Re: How to protect some input fields of one PDF when sent to a customer?
                      George_Johnson MVP & Adobe Community Professional

                      Preview has awful support for PDF forms, and doesn't support JavaScript at all. When it saves PDF forms, it corrupts them in a number of ways. Quite simply, it should not be used for forms. Apple seems unable or unwilling to make it conforming and IMO it would be better if they removed altogether what ability it has to deal with interactive form fields. Mac users should use Adobe Reader to work with forms.

                      • 8. Re: How to protect some input fields of one PDF when sent to a customer?
                        owanomono Level 1

                        Ok, so then we have to live with that pesky Preview. Too bad since it kind of nullifies what I try to accomplish here. Maybe using cerificates is the way to go. But then you have to produce a certificate for each version of the PDF, unique to that customer, I guess. Hopefully there is some sort of automatic way to do this?

                         

                        Regards

                         

                        Johan

                        • 9. Re: How to protect some input fields of one PDF when sent to a customer?
                          ThisThisThis

                          Great script for using a password to lock a form. Can it be easily modified so that from can be locked without a password but then later unlocked by someone who has the password?

                           

                          Example: a user enters data into the form and when finished they simply push a button to lock-in their answers (no password required or asked for). But then later an 'administrator' who has a password can edit and add to the from. This would be handy for some stuff I do.

                           

                          I've had a go at modifying it myself - but scripting is something I do not have a lot of practice with.

                           

                          T.

                          • 10. Re: How to protect some input fields of one PDF when sent to a customer?
                            George_Johnson MVP & Adobe Community Professional

                            To prompt for the password only when unlocking, change that one block of code to:

                             

                                //Prompt user for the password only if unlocking

                               if (readonly) {

                                var resp = app.response({

                                    cQuestion: "To" + readonly_desc + "the fields, enter the password:",

                                    cTitle: "Enter password",

                                    bPassword: true,

                                    cLabel: "Password"

                                });

                               } else {

                                   var resp = pw;

                               }

                            • 11. Re: How to protect some input fields of one PDF when sent to a customer?
                              ThisThisThis Level 1

                              Thanks!

                               

                              I had to change the first line to:

                               

                              if (f.readonly) {

                               

                              But works great!

                               

                              T.

                              • 12. Re: How to protect some input fields of one PDF when sent to a customer?
                                IsakTen Level 4

                                Perhaps you can lock all fields in your form and have a JavaScript that runs when the form PDF is opened which opens either all fields or the fields that you want the user to be able to modify. If this PDF is opened in Preview, this JavaScript is not executed and the user cannot do anything. You'll have to somehow communicate to your users that they need to set Adobe Reader as the PDF Viewer on their Mac systems. You can have this disclaimer as a text on the top of your form.

                                • 13. Re: How to protect some input fields of one PDF when sent to a customer?
                                  mikeb29908952

                                  Hi George,

                                   

                                  This thread has been very helpful as I solve my own problem. Question: Is it possible to get rid of the password prompt? For example, I want my fields to automatically lock when somebody clicks the "Lock" button.

                                   

                                  Thanks so much,

                                   

                                  mike

                                  • 14. Re: How to protect some input fields of one PDF when sent to a customer?
                                    George_Johnson MVP & Adobe Community Professional

                                    You could do something like:

                                     

                                    (function () {

                                     

                                        // Prefix for group field names. Change to match what you want to use.

                                        // Rename the fields you want to lock to match this prefix (e.g., "PRIV.NAME")

                                        var f_prefix = "PRIV";

                                     

                                        // Get a reference to the first field in the group

                                        var f = getField(f_prefix).getArray()[0];

                                     

                                        //Determine new readonly state, which is the opposite of the current state

                                        var readonly = !f.readonly;

                                        var readonly_desc = readonly ? "lock" : "unlock";

                                     

                                        getField(f_prefix).readonly = readonly;

                                     

                                        app.alert("The fields are now " + readonly_desc + "ed.", 3);

                                     

                                    })();

                                    1 person found this helpful
                                    • 16. Re: How to protect some input fields of one PDF when sent to a customer?
                                      davidvralAHT

                                      George_Johnson, you're awesome! This was exactly what I was looking for!

                                       

                                      One question though, the javascript "undoes" the text field's "multi-line" specification and sets the text in the field to a single, non-scrollable line.

                                       

                                      Is there a way to have the script leave the "multi-line" attribute unchanged, or add lines to the javascript so it sets the field to "multi-line"?

                                      • 17. Re: How to protect some input fields of one PDF when sent to a customer?
                                        Bernd Alheit Adobe Community Professional & MVP

                                        davidvralAHT  wrote

                                         

                                        ...

                                         

                                        One question though, the javascript "undoes" the text field's "multi-line" specification and sets the text in the field to a single, non-scrollable line.

                                         

                                        ...

                                        Where does you see this?

                                         

                                        Info: a read-only field is not scrollable.