JavaScript – Print Query

Recently I received a query involving Printing of files and whether there is any way to

detect that the user is about to print. Unfortunately, PDF doesn’t expose a print handler or

any mechanism that I know of that can do what the person wants in this kind of situation.

The query was as follows:

The query

Hi Kas,

I read your article and I had a small query about Javascript commands…   Is it

possible to write a javascript that will detect when a menuitem has been executed? Ie.. what

i am trying to do is to detect if the viewer has printed the page or not .. if they have,

then i set a flag to ‘Yes’ But the trouble I am having is whether this can be detected.

  My other solution was to create a ‘Print’ Button which did all of this, but if the

viewer prints through the menu, then the javascript is not implemented, hence defeating the

original idea.   Thanks for any help you can spare me!!!  

Jeremy Tse

The answer

My answer to this query was as follows:

I don’t believe it is possible to do what you want via JavaScript. It sounds to me like

something that would have to be implemented as a plug-in, with all the ‘down side’ that that

implies.

The only workaround I can think of is something like this. Mark all of the fields in your

form as ‘visible on screen but not when printed’ (using the Field Properties dialog) and

offer a Print button in the form. If the user tries to print from the File menu, none of the

fields will print. You can also save the file with preferences set to hide the menu bar and

hide the toolbar. But this doesn’t prevent a user from using Cmd-P (the keyboard shortcut

still works, at least on my Mac).

In summary, I don’t see any foolproof way out.

If anybody out there knows of a better answer to this problem, please write to Jeremy and

copy me on your response. Thanks!

You May Also Like

About the Author: Kas Thomas

Leave a Reply