Reputation: 3790
Background:
For an application I support, we show certain documents to the user that they either fill in, and have to give to a certain person, or have to print out, then fill in and give to a specific person.
The way we're showing these messages, is through JavaScript in the PDF document like so:
app.alert('You need to fill in this form, then send it to Person McDude in Accounting.');
While this approach is very well-tested in IE11, Chrome, Firefox, and other modern browsers and their PDF viewers, Edge seems to be the exception. For whatever reason - most likely a difference in the built-in PDF reader in Edge - the message that should be shown above does not get shown.
Our clients require us to show this message to people who download the PDF; we can't get around showing it.
While there are ways to circumvent this - maybe show the message before the PDF downloads - I would prefer to preserve our systems' original behavior. Thus, my question...
Research:
I ran a few Google searches before writing this topic, using the keywords run javascript in PDF file edge.
I found no relevant results from my search, and other permutations of the same. While it's possible I didn't use just the right combination, I've found no results about other cases like mine, of mandated alert text in a PDF that isn't being shown in Edge, or about any potential remedies to such a problem.
Additionally, my own impromptu search for any Edge PDF viewer settings met with...no results. Seriously, I can't figure out how one even configures the Edge PDF viewer at all.
Question:
In what way can I get MS Edge to run PDF document JavaScript?
Upvotes: 1
Views: 5829
Reputation: 4917
In what way can I get MS Edge to run PDF document JavaScript?
You can't. The PDF viewer built into Edge doesn't execute the JavaScript embedded in the PDF. Further, even for the few browser-based PDF viewers that do consume and execute JavaScript, most of them don't do so completely or accurately if you have calculated fields, field validations, or special formatting for phone numbers, dates or SSNs. What I generally recommend in situations like your is the following.
Put your PDF files in a folder where the .htaccess file or equivalent is set to download only. That will prevent any browser from attempting to display the file.
Add a layer to the file that is always visible unless the application can run the JavaScript that can hide it. The layer explains that the form requires the use of a specific set of tested PDF viewers. For basic JavaScript, you can get away with Foxit, Nuance, and Nitro, but if you want your form to always work, go with Adobe Reader.
Upvotes: 4