Skip to main content
New Participant
January 22, 2018
Answered

JavaScript to Hide Button in Acrobat

  • January 22, 2018
  • 1 reply
  • 6722 views

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...

This topic has been closed for replies.
Correct answer Michael_Henderson

@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!

1 reply

Thom Parker
Community Expert
January 22, 2018

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

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Michael_HendersonAuthorCorrect answer
New Participant
January 22, 2018

@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!

try67
Community Expert
January 22, 2018

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>