• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScript to Hide Button in Acrobat

Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

5.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 22, 2018 Jan 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 probl

...

Votes

Translate

Translate
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

LATEST

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines