Loading PDF files in Air with flex
March 25th, 2009 in Air, Flex | 6 CommentsFind how you can render PDF files in Air. This process is very simple and will be done in just a few minutes.

1. First, create a new Air project named PdfReader that will also create an mxml file named PdfReader.mxml.
Open it so we can begin to edit our code.
2. Like for the WebBrowser we will use the HTML component.
3. The only thing that we have to do is to check if the user has a correct version of Adobe Reader installed because if the user doesn’t have Acrobat Reader 8.1 or later that will not work.
4. To do so, we have to detect the PDF capability with the static property pdfCapability of the HTML class.
The pdfCapability property can be one of the 5 values :

In our case we want to check the if the value is STATUS_OK
5. So in our code, add an HTML component to the application and create a function detectPDF that if the PDF capability is OK the nit will set the location of the HTML component to the path of the pdf file else it will call the Alert method to display an error message.
6. The whole code is as follow :
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="detectPDF()" width="825" height="625">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function detectPDF():void{
if(HTML.pdfCapability== HTMLPDFCapability.STATUS_OK)
{
reader.location = "assets/test.pdf";
}
else{
Alert.show("Can't display PDF content","Problem");
}
}
]]>
</mx:Script>
<mx:HTML id="reader" width="100%" height="100%"/>
</mx:WindowedApplication>
7. Run the application to test it.






Apr 14th, 2009
Thanks for sharing !
Good work.
See ya
Aug 28th, 2009
Nice Tutorial. Thanks
Sep 12th, 2009
Simple to understand, nice tutorial.
Thanks
Sep 17th, 2009
Great! How I wish Flash apps could also do this.
Nov 14th, 2009
Great tutorial !! But I have a question.
If I need that the application reads any pdf file inside that assets folder instead a specific name file.
How I could do that ?
I am waiting for a help.
Thanks !!
Jun 3rd, 2010
Hi,
Can you tell me please how to remove the toolbar or control the toolbar using flex.
thanks and regards
Abhishek