Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new

Learn More

View all

Sign in to view all badges

ESC key cancels or prevents running scripts in Adobe Reader



While developing a custom print dialog, specifically for Adobe Reader, using the Acrobat's API method «app.execDialog».

Having the habit of closing dialogs with the escape key, so I did.

Before opening the dialog the script had affected some state in the document that should be restored to its previous values upon ending the print. Something like this:

function Print()


var oPP;

var oDoc =; // how you obtain oDoc depends on where you are

xfa.form.form1.IndPrint.rawValue = 1; // Some numeric field



oPP = ShowDialogAndBuildPrintParams(); // Declared elsewhere



// User has cancelled the dialog.

// The finally block will run and restores state.

return false;



return true;




xfa.form.form1.IndPrint.rawValue = 0;



What happened next was that the field « IndPrint » retained its « 1 » value.

But how? A JavaScript finally block MUST run (unless something really sever happens, like out of memory or an earthquake).

But no. It's Adobe Reader "we're" running in. And in this software the user seems to have FULL control of what happens,

What I found is that no matter what code is running, be it some event script, like «calculate», «initialize», whatever, if the user presses the ESC key, the script is ABORTED!!

No matter where your code was, or if it had any finally blocks.

This means you cannot be sure that any state you keep is ever consistent. You cannot be sure any script validations did run.

This behaviour is similar to what happens to code if the user answers "No" in a "print confirmation dialog" (the one that appears when you call print on a non-privileged location).

It is the power to break any useful code a programmer may develop.

Is there a way to disable this «feature» of the product? Possibly some hidden flag in the registry? Or under the assumption of being in a «privileged location» (a configuration available in Reader)? Anything?

Intercepting keys at the document level?