PDF Portfolios and Backward Compatibility – Part 4

| No Comments

This entry is the second post on ensuring the user sees your PDF Portfolio in all it’s Flashy glory, that is, forcing it to be viewed in Acrobat or Reader 9. Earlier posts on this topic can be read
here Part 1, Part 2, and here Part 3.

In the last article, we used some JavaScript to detect the version of Acrobat or Reader being used and close the document if the viewer version number was lower than 9. Thus, ensuring that the document could only be viewed in a version of ACrobat or Reader that is capable if displaying DF Portfolios correctly. This works fine when the document is being opened from the desktop or otherwise local file. Unfortunately, for security reasons, this.closeDoc() is not permitted to execute while a PDF is being viewed in the browser so the user needs to download the PDF and then open it.

With particularly large PDF Portfolios, this can potentially create a bad user experience when the user spends several minutes downloading a PDF only to find that they then need to go spend more time downloading a new Reader in order to view it. This article will discuss how to redirect the browser based on the version of Acrobat or Reader being used.

Redirecting the Browser Based on Viewer Version

The "right" way to do this is, unfortunately, unreliable. Ideally, you could have a PDF load into a small 1 x 1 pixel <DIV> and have Acrobat or Reader tell the browser what version it is. There’s enough of an API in Acrobat and Reader to make communicating with the host easy but there are too many dependencies on the most popular browsers out there to make this technique reliable. Instead, we’ll load a small, one page PDF into the browser and use it along with a parameter stored in the URL to redirect the browser to the actual destination.

The example code below will detect the parameter string after the "?" in the URL to the redirecting PDF and then launch that URL if the version number if greater than or equal to 9 sending the browser to the Reader download page if not. To use the script, simply add code to the Document JavaScripts outside of any function so that it runs every time the document opens. If the document is not running in a browser, the first "if" statement will return false and the script won’t run.
The code might look like this.

if (this.external)
q = this.URL.lastIndexOf("?")+1
destination = this.URL.substring(q)
if (app.viewerVersion >= 9)
//add a message here to tell the user what’s happening
//add a message here to tell the user what’s happening

Then you place the redirecting PDF on your site somewhere and create a link to it. In the link, add a "?" then the path to the actual destination. A live example URL and reference implementation is below.

  Example File


Note: Depending on the security settings and version of Acrobat or Reader being on the client machine, the end user may see any number of security warning dialogs when the JavaScript tries to redirect the browser. You may want to add something to the link to alert people of that fact.