Rendering PDF content in Adobe AIR application

January 4, 2008

We can render PDF content in Adobe AIR application. You have to use the HTMLLoader to load the PDF and add the HTMLLoader to the window. You cannot add HTMLLoader as a child to the Flex containers as the Flex containers expect the child components to be a UIComponent, so we have to wrap the HTMLLoader into UIComponent and then add it to the Flex containers.

This same code can be used for HTML, TXT, JPG and PNG files. If the file being loaded is not PDF then we need not check for the PDF capability.

PDF content rendered in AIR application

PDF file rendered in mx:Window

JPG file rendered in AIR application

JPG file rendered in mx:Window

Code for rendering content in Adobe AIR

if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)

{

var htmlLoader:HTMLLoader = new HTMLLoader();

var url:URLRequest = new URLRequest(pathUrl); //URL to the file

htmlLoader.width = windowWidth; //width of the content area

htmlLoader.height = windowHeight; //height of the content area

htmlLoader.load(url);

//wrapping into UIComponent

var holder:UIComponent = new UIComponent();

holder.addChild(htmlLoader);

addChild(holder); //add it to any container

}


Follow

Get every new post delivered to your Inbox.

Join 101 other followers