1

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?

8
  • I'm not sure that PDF documents ever execute javascript in the first place. I've never heard of it. I would recommend pursuing your proposed solution of executing the alert before the PDF opens. Commented Aug 24, 2017 at 18:45
  • I'll take your suggestion under greater consideration. I also don't think I ever claimed that the document ever runs JavaScript. Commented Aug 24, 2017 at 18:54
  • So then, where is this existing code running? Is the PDF loaded into an iframe or something? I'm not understanding how your system is currently set up. Commented Aug 24, 2017 at 18:55
  • The website the PDF is being served up from opens the PDF document in a new tab. In IE11/Chrome/non-Edge others, the message appears when the PDF loads in the new tab. Commented Aug 24, 2017 at 19:00
  • 1
    @Our_Benefactors: For future reference, the Adobe PDF viewers, as well as a few others, have a built in JavaScript engine just like the browsers. With PDF, you have the JS core plus PDF extensions that operate against the PDF object and event model... just like HTML browsers have the JS core plus HTML extensions that operate against the HTML DOM. Commented Aug 25, 2017 at 2:31

1 Answer 1

4

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.

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.