5 Replies Latest reply: Feb 17, 2013 12:35 PM by 12345abcdefghi RSS

    Load a PDF in StageWebView - iOS

    seriousfretter09

      I am trying to create an iOS app that loads my companies product catalogue into a webview stage. I cannot figure out after a lot of google how to access this local file, although external files load fine. I'm trying to use the "file:" command. I'm doing this in flash builder.

       

      <![CDATA[

       

       

                                    import flash.display.MovieClip;

                                    import flash.media.StageWebView;

                                    import flash.geom.Rectangle;

       

                                    var webView:StageWebView = new StageWebView();

                                    var yOffset = 47

                                    {

                                                   public function FestoKP() {

                                                             webView.stage = this.stage;

             webView.viewPort = new Rectangle( 0, yOffset, stage.stageWidth, stage.stageHeight - yOffset);

             webView.loadURL( "file:///asset/Festo_KP_Catalogue.pdf" );

                                                             closeBtn.visible = true

             }

             public function Close() {

             webView.stage = null;

             closeBtn.visible = false;

             }

                                    }

        • 1. Re: Load a PDF in StageWebView - iOS
          FatboyUrb Community Member

          I am on the same boat.  Did you ever find a good working example? -I'm about to give up.

          • 2. Re: Load a PDF in StageWebView - iOS
            seriousfretter09 Community Member

            Yes, I actually did finally figure it out. I ended up scraping this method though because although it works very well in iOS, it does not work on android. Would you still like me to post the code? I ended up completing this project in Xcode instead, so it'll take a bit to dig up.

            • 3. Re: Load a PDF in StageWebView - iOS
              FatboyUrb Community Member

              These guys at "CultCreative" seem to have the ideal solution for FB (it even checks to see if a newer .pdf is on a server)  but my project was built in Flash Pro CS5.5 so again just want to load a few local .pdf files which would be bundled up with the app. 

               

              http://www.cultcreative.com/tutorials/11/13/2011/local-file-access-editing-for-android-and -ios/

               

              I'm still interested in the method you used for iOS if it works well with Air (3.1) for iOS.   However, I am determined to find a way of using Flash Pro CS5.5 to do so.   Thanks! -if you can find it, and think your AS3 from FB would work for me. 

              • 4. Re: Load a PDF in StageWebView - iOS
                seriousfretter09 Community Member

                In the example below, I included a close button to close the webview. This function is at the bottom. Y-offset is the height of the toolbar at the top.

                 

                <fx:Script>

                          <![CDATA[

                               import flash.display.MovieClip;

                               import flash.media.StageWebView;

                               import flash.geom.Rectangle;

                                

                               var webView:StageWebView = new StageWebView();

                               var yOffset = 45;

                               var yTabs = 54;

                                

                               //var yOffset = 90;

                               //var yTabs = 107;

                                

                               private function loadDSPF():void {

                                    webView.stage = this.stage;

                                    webView.viewPort = new Rectangle( 0, yOffset, stage.stageWidth, stage.stageHeight - yOffset );

                                     

                                    var fileName:String = "foldername/filename";

                                    var sourceFile = File.applicationDirectory.resolvePath( fileName );

                                    var workingFile = File.createTempFile();

                                     

                                    try

                                    {

                                         sourceFile.copyTo( workingFile, true );

                                          

                                         // You have to rename the temp file

                                         var renamedTempFile:File = workingFile.resolvePath(workingFile.nativePath + fileName);

                                         workingFile.moveTo(renamedTempFile, true);

                                          

                                         webView.loadURL( renamedTempFile.url );

                                         closeBtn.visible = true;

                                    }

                                    catch (err:Error) { }

                               }

                                

                               public function Close() {

                                    webView.stage = null;

                                    closeBtn.visible = false;

                                    allBtn.enabled = true;

                               }

                          ]]>

                     </fx:Script>

                 

                hope that helps. I can explain anything else if you need.

                • 5. Re: Load a PDF in StageWebView - iOS
                  12345abcdefghi Community Member

                  This was perfect thanks!