7 Replies Latest reply on Jan 22, 2018 3:40 PM by Thom Parker

    JavaScript to Hide Button in Acrobat

    Michael.Henderson

      I'm trying to create a fillable form for users in my organization that use both Acrobat (9 & DC) and Reader (DC). The form is a template that is filled out by users in our organization and then needs to be locked for editing if it is ever distributed outside of the company.

       

      I'm trying to set up a button that locks all the form fields AND disappears after it is clicked (so users outside our organization do not see it). I have the script for the locking finished/working, but I'm having trouble making the button disappear.

       

      I've set up the following script on the click:

      event.target.display = display.hidden;

       

      This seems to make the button disappear for the users with Reader, but not with Acrobat.

       

      I've also used:

      this.getField("Button1").display = display.hidden;

      and I have the same problem.

       

      Any ideas on what I can do differently? I am not a heavy Java user, so I'm not well versed in this code...

        • 1. Re: JavaScript to Hide Button in Acrobat
          Thom Parker Adobe Community Professional

          That code should work all around. What behavior are you seeing with Acrobat?  You know that even if the fields are locked and the button hidden that someone with Acrobat or any other editing tool can still unlock/unhide and edit the PDF.

           

          Another option is to flatten the PDF. This removes the interactive part of the form fields, but leaves the image of the field behind.  So now the form can't be edited. You could also apply security to the form with a certificate, so that it can't be easily edited.

           

          Both these options, security and flattening can't be done from inside the PDF, or in Reader. They require a tool in Acrobat, security is of course built-in, but you could create your own custom tool for this.

          You can download a free flattening tool here:

          Free Acrobat Automation Tools

          • 2. Re: JavaScript to Hide Button in Acrobat
            Michael.Henderson Level 1

            @Thom Parker: You indirectly solved my problem, thanks!

            The behavior I was seeing in Acrobat was once the button was clicked, it was 'locking' the button and it became non-interactive.

             

            My 'locking' function was already a flattening one, and I had the Java coded to make the button disappear after the flattening function was executed. The button was flattened, and was no longer an object that could be set to hidden. Once I switched the code around that the button was hidden first, it fixed the problem in Acrobat. Strangely, the original code did work in Reader DC, so maybe there is a different way JavaScript is executed in Reader?

             

            Thanks again for the response!

            • 3. Re: JavaScript to Hide Button in Acrobat
              try67 MVP & Adobe Community Professional

              Merge all of your code to a single command, so you could control in what

              order it is executed. If you keep it separate there's no way to know for

              sure what the order will be.

               

              On 22 January 2018 at 22:03, Michael.Henderson <forums_noreply@adobe.com>

              • 4. Re: JavaScript to Hide Button in Acrobat
                Thom Parker Adobe Community Professional

                We'll I'm really happy I was able to help, even if it's indirect.  I find that often, all I need is to talk to someone about an issue. They don't even have to answer, just talking makes you think about an issue differently, and then you see a different solution

                 

                Maybe it works in Reader because Reader can't flatten.  Are you sure that it's really working in Reader?

                • 5. Re: JavaScript to Hide Button in Acrobat
                  Michael.Henderson Level 1

                  @try67: Agreed. Merging is the best way to go. I had this code in one command, but the order of the code within the command seemed to make the difference here. Appreciate your input.

                  • 6. Re: JavaScript to Hide Button in Acrobat
                    Michael.Henderson Level 1

                    @Thom Parker: Agreed. That's why I come to these forums from time to time when I get stuck.

                     

                    It's possible that Reader is executing the JavaScript differently than Acrobat (again, not as strong in Java), but it is achieving the same result from an end-user perspective (which is all I care about in this case, haha). Definitely working in Reader though, and I tried it on multiple machines in my office. Just an interesting 'bug(?)' to note between the two versions, I guess.

                     

                    Thanks again!

                    • 7. Re: JavaScript to Hide Button in Acrobat
                      Thom Parker Adobe Community Professional

                      Happy to help, but I sure would appreciate my answer marked as the correct one thanks