Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

load PDF file inside the application (Android and Ipad)

Explorer ,
Aug 18, 2013 Aug 18, 2013

Want to open PDF file inside the application. I try this code, its working in the PC but when I publish this, as an APK file it’s not working in my android device

package {

                import flash.display.SimpleButton;

                import flash.events.MouseEvent;

                import flash.events.Event;

                import flash.html.HTMLLoader;

                import flash.net.URLRequest;

               

                public class bpdf extends SimpleButton {

                               

                                public function bpdf() {

                                                // constructor code

                                                 this.addEventListener(MouseEvent.MOUSE_DOWN,downF) ;

                                }

                               

                                private function downF(e:Event):void {

                                                var htm:HTMLLoader= new HTMLLoader();

                                                htm.load(new URLRequest("test.pdf"));

                                                htm.width=200;

                                                htm.height=300;

                                                htm.x=50;

                                                htm.y=20;

                                                this.parent.addChild(htm);

                                                // create a close button for htm and add it (to this.parent) and its listener here

                                }

                               

                                function onCloseEvent(e:Event) {

                                                if(!HTMLLoader.isSupported){

                                                                this.alpha=.1;

                                                }

                                }

                }

}

01.jpg

02.jpg

TOPICS
ActionScript
6.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 22, 2013 Aug 22, 2013

use:

import flash.media.StageWebView;

import flash.geom.Rectangle;

import flash.desktop.NativeApplication;

import flash.events.MouseEvent;

import flash.filesystem.File;

var swv: StageWebView = new StageWebView();

swv.viewPort = new Rectangle(0, 0, 500, 250); // 500px width, 450px height

swv.stage = this.stage; // set stage of StageWebView to document class

var templateFile:File = File.applicationDirectory.resolvePath("test.pdf" );

var workingFile:File = File.createTempFile();

templateFile.copyTo(workingFil

...
Translate
Community Expert ,
Aug 18, 2013 Aug 18, 2013

use stagewebview instead of htmlloader.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2013 Aug 18, 2013

I try StageWebView

package  {

     import flash.display.SimpleButton;

     import flash.media.StageWebView;

     import flash.geom.Rectangle;

     import flash.events.KeyboardEvent;

     import flash.ui.Keyboard;

     import flash.desktop.NativeApplication;

     import flash.events.MouseEvent;

    public class bpdf extends SimpleButton {

          private var webView:StageWebView = new StageWebView();

          public function bpdf() {

               this.addEventListener(MouseEvent.CLICK,clickF);

           }

          public function clickF(e:MouseEvent):void {

               var swv:StageWebView = new StageWebView();

               swv.viewPort = new Rectangle(0,0,500,250); // 500px width, 450px height

               swv.stage = this.stage; // set stage of StageWebView to document class

               swv.loadURL("test.pdf"); // load any content

               stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );

          }

          private function onKey( event:KeyboardEvent ):void {

               if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled ) {

                     trace("Back.");

                     webView.historyBack();

                     event.preventDefault();

               }

                if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled ) {

                     trace("Forward.");

                     webView.historyForward();

               }

           }

     }

}

03.jpg

but got this error

04.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2013 Aug 19, 2013

your pdf must be added to your include files list in the android publish settings.  your pdf needs to be in the same directory as your published files when you specify no path.

also, add error listeners.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2013 Aug 20, 2013

I already include my pdf file in my android publish setting

05.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2013 Aug 21, 2013

i don't know if this will help, but change your publish settings to publish your apk to the same directory as your swf.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 22, 2013 Aug 22, 2013

i try but when i check in my android device i got this

06.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2013 Aug 22, 2013

use:

import flash.media.StageWebView;

import flash.geom.Rectangle;

import flash.desktop.NativeApplication;

import flash.events.MouseEvent;

import flash.filesystem.File;

var swv: StageWebView = new StageWebView();

swv.viewPort = new Rectangle(0, 0, 500, 250); // 500px width, 450px height

swv.stage = this.stage; // set stage of StageWebView to document class

var templateFile:File = File.applicationDirectory.resolvePath("test.pdf" );

var workingFile:File = File.createTempFile();

templateFile.copyTo(workingFile, true );

try{

    swv.loadURL( workingFile.url );

} catch (e:Error){

    trace( e );

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2013 Aug 24, 2013

Thx for reply boss. In this time no error but when I publish in my PC, on that time I got white screen

09.jpg

10.jpg

but when I open this file in android device, after 1 to 2 mint I got this screen (my pdf file size is only 74 KB)

11.jpg

Here is my publish setting which I use

12.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2013 Aug 24, 2013

that code works for me so i'm not sure what you're doing wrong.  you might check with another pdf to make sure it's not a pdf problem. otherwise, someone will probably need to download and correct your files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2013 Aug 24, 2013

I try to change my PDF file but facing the same problem

Do i have to install any plugin for this?

Can you send me your file which you made? (Which AIR SDK you are using?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2013 Aug 25, 2013

this works with air for android 3.6 and 3.8. i didn't test anything else:  http://www.kglad.com/Files/forums/testPDFload.fla

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 26, 2013 Aug 26, 2013

thx boss. It’s working in the PC but when I check this in the Android device its look like crash.

11.jpg

I try to change my pdf file as wll but facing the same problem. Any idea what is the problem?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2013 Aug 27, 2013

you need a pdf reader on your android device.  check gdocs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2013 Aug 27, 2013
LATEST

I installed this

https://play.google.com/store/apps/details?id=art.wild.gdocs&hl=en

https://play.google.com/store/apps/details?id=com.rcs.mydocs&hl=en

but facing the same problem

In my android device I already have adobe reader

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines