Required Javascript to run

I would like to have a script run upon opening a pdf and if it cannot run the pdf should not open.

Is it possible to prevent a pdf from opening if the user has disabled javascript?


8 Answers

Voted Best Answer

The most common approach is to create a field that provides a message about the need for JavaScript and make this field large enough to cover the form. By default this field will be visible and printable. You then can create a document level script which will run when the form is opened and it will hide the field. You could start with all form fields hidden and have the script make the fields visible, but this could cause a delay that could become lengthy depending upon the number of fields.

By George Kaiser   

No, you can't prevent someone from opening a PDF file.
What you can do, however, is include a warning message of some kind in the file, and the use JS to hide it. So if JS is disabled, the user will see the warning message. You can also use the same method to hide some (or all) of the contents of the page.

Visit my custom-made PDF scripts website:
Contact me personally:

Gilad D (try67)   

Gilad D - Thanks for the quick reply. What I am trying to accomplish is to hide content of a document unless a javascript runs that connect to our database and retrieves some information. I don't want the user to see any content if the javascript cannot run.


Unless you're using Acrobat 9 or earlier, a JS in an AcroForm can't connect to a database. You'll need to use a LiveCycle form for that.

Gilad D (try67)   

Gilad D - Understood. However, the concept I am trying to achieve is the same.

Do not display content unless a javascript can run. Is this possible?


Like I wrote, you can achieve this by placing form fields over your content, and then set them to invisible using a script when the document is opened.

Edit: fixed a mistake... I meant invisible, of course.

Gilad D (try67)   

I think the best practice is to create those contents dynamically via code. If javascript runs it will create the content otherwise not.

Muhammad Irfan   

Take a look at this example

Is this the kind of "content hiding" that would work for you?

Where is your database in relation to the user? A live cycle form will only help if you can control the users system, because it requires the DB driver to be on the users system. This is particularly difficult if the DB is remote.

There is however, a way to connect any PDF to a remote DB. What you do is put the DB on a server, and then write a server script to transfer info in and out of the DB using one of the PDF data formats. Then all the PDF needs to do is to perform submitForm opertions to the script.

This would work for unlocking your content.

Thom Parker
The source for PDF Scripting Info
All About PDF Stamps in Acrobat and Paperless Workflows - THE BOOK !!

The Acrobat JavaScript Reference, Use it Early and Often

The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)

Having trouble, Why Doesn't my Script Work

Thom Parker   

Please specify a reason: