0 Replies Latest reply on Nov 3, 2009 10:50 AM by richruiz

    PDF in Air not working

    richruiz

      I'm trying to display a PDF in an Air application. Below is a simple sample app I am using for testing. When I run the app in Eclipse nothing appears in the box below the text wich displayed in the Complete event handler. The commented out call to Google displays as expected. I spent a lot of time trying to make this work but finally deployed tha app and the application and ran it from the desktop and it worked!!!

       

      Anybody have any ideas on why it will not work when run from Eclipse?

       

      I have Adobe Reader 9.2.0 open when I run the app.

       

      I use Charles ( http://www.charlesproxy.com/ ) to trace the request and response and can see that the PDF content is returned. It behaves as if it does not recognize the end of the response. If I take focus off the app then return to it the UIComponent becomes transparent.

       

      Here is the request ....

       

      GET /sample.pdf HTTP/1.1
      Referer: app:/test.swf
      Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, image/png, */*;q=0.5
      x-flash-version: 9,0,115,0
      User-Agent: Mozilla/5.0 (Windows; U; en) AppleWebKit/420+ (KHTML, like Gecko) AdobeAIR/1.0
      Pragma: no-cache
      Host: samplepdf.com

       

      Here is the response ( truncated )

       

      HTTP/1.1 200 OK
      Date: Tue, 03 Nov 2009 17:49:11 GMT
      Server: Apache
      Last-Modified: Thu, 27 Nov 2008 15:14:53 GMT
      ETag: "107a7-7ae4-492eb96d"
      Accept-Ranges: bytes
      Content-Length: 31460
      Content-Type: application/pdf

      %PDF-1.4
      %Çì�¢
      5 0 obj
      <</Length 6 0 R/Filter /FlateDecode>>
      stream
      xœu“Mo 1 †Å7 Äw G 3H ì8žÄWÔª 7ª‘8PNE !¶hÛÿ/aÏn»Ù “9<rÞøµ=™5`¢ èë ÎWáãi…‹ë°„áôd W a Zb&#127;–@Ïç+ø4ÛA ž`þ 0©6Z¶ T ‘
      LMRƒy ¾Å;È)·V˜â]gÎR™ã½aÌ)×&ñ¾ 2 � †‘ æ‚->\°4)ñрɎ ÔøØ£ s£^ûÄ‘U©Ä³K÷@áFœãSßPT‘ølë§ä ¶’¤ÕÿxŸ]™#WT«î¦f{ãóE] k|1xãl’øÒ�$—J½_—y¿¦Îç•ÇµHë<iòRržÌ¨|Ÿ?‡*I[)0 NšaþaCí,û™vž¯=›š£ì¹¼ÙMá‡Ii¢Ö×t°Stéú) ìM²ë¬Ó  y±¯ñ�§ ÑZã{Ç ËäCðֈɾƒvÙÆü; MÉRÂh í¢Çsøb  ¡( ¬‚ nùφ³66Î"·| ¿Â× p Ö` ëæ¶:�hqIÞü
      Dpô×\|ý [ › endstream
      endobj
      6 0 obj
      400....

      .

      .

      .

       

      trailer
      << /Size 21 /Root 1 0 R /Info 2 0 R
      /ID [(6Ø+Њ½mùSÝ 9 � Z)(6Ø+Њ½mùSÝ 9 � Z)]
      >>
      startxref
      30918
      %%EOF

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">

       

      <mx:Script>

       

       

      <![CDATA[

       

       

      import

      mx.core.UIComponent;

       

       

       

      private var htmlLoader:HTMLLoader = new

      HTMLLoader();

       

       

      private var pdffile:String = "http://samplepdf.com/sample.pdf"

      ;

       

       

      //private var pdffile:String = "http://www.google.com";

       

       

       

      public function onCreationComplete():void

      {

       

       

      if

      (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)

      {

       

      htmlLoader.addEventListener(Event.COMPLETE,compHandler);

       

       

       

       

      var pdfUrl:URLRequest = new

      URLRequest(pdffile);

      pdfUrl.cacheResponse =

       

      false

      ;

       

       

       

       

      var

      hdrs:Array = pdfUrl.requestHeaders;

       

       

      //hdrs.push( new URLRequestHeader("Pragma: no-cache"));

       

       

      var header:URLRequestHeader = new URLRequestHeader("Pragma", "no-cache"

      );

      hdrs.push(header);

      htmlLoader.width = 1024;

      htmlLoader.height= 768;

      htmlLoader.load(pdfUrl);

      }

      }

       

       

       

      private function compHandler(evt:Event):

      void

      {

      txt.text = pdffile +

       

      " below:"

      ;

       

      pdfComponent.addChild(htmlLoader);

       

      }

       

      ]]>

       

       

      </mx:Script>

       

       

      <mx:VBox>

       

       

      <mx:Label id="txt" />

       

       

      <mx:UIComponent id="pdfComponent" />

       

       

      </mx:VBox>

       

       

      </mx:WindowedApplication>