As I’ve mentioned in previous posts, the Flash Player that’s embedded in Acrobat and Reader 9 has built in functions that take advantage of features available only in Acrobat and Reader. That’s great, but what if I want to write my RIA once and have it be “aware” of it’s container whether that’s an HTML page or a PDF. How can I tell if my SWF is embedded in a PDF? Quoting from the Flex 3 Language Reference…
Let’s say we want to create a Flex application that can save it’s state information when commented on in Acrobat but we want to use the same SWF in a browser. We’d need to detect the container and then branch our code based on the results.
Basically, if app.viewerType returns null, then we know we’re in the browser. If it returns "Reader", "Exchange", or "Exchange-Pro", then you know you’re in a PDF.
In the examples below, the same SWF file is playing in the browser’s Flash Player and in also in a PDF embedded on this page.
The SWF above is playing in your browser.
The one below is playing inside a PDF document.
The Flex Project for this example is below.