Skip to main content
Known Participant
September 26, 2011
Question

Open a PDF file embedded in my app ?

  • September 26, 2011
  • 2 replies
  • 3592 views

Hi,

In the resources of my application, I can easily embed a PDF file just like I would embed a large mp3 file , video or photo's

But.... can I somehow call some code in as3 which then opens that PDF file on the ipad ? So for example I have a book (in PDF) containing +- 20 pages and when I click on a button of my air app, I want to have the ipad open the pdf file and show it onscreen.

Possible ???

Kind regards,

Bart

This topic has been closed for replies.

2 replies

markc888
Inspiring
September 27, 2011

Assuming you have included a folder named 'resources' which includes a pdf file named 'file.pdf'. by adding it in the publish settings, include files:

I believe this will only work when tested on the device.

import flash.filesystem.File;

import flash.media.StageWebView;

public var webView:StageWebView;

 

webView = new StageWebView();

webView.stage = this.stage;

//set the position and size of the web view that will hold the pdf.

webView.viewPort = new Rectangle(20,103,960,640);

var fPath:String = new File(new File("app:/resources/file.pdf").nativePath).url;

webView.loadURL( fPath );

 

}

Inspiring
September 27, 2011

markc: Unless something has changed recently, your code won't work because you can't load a PDF that's inside File.applicationDirectory.

markc888
Inspiring
September 27, 2011

I have a working implementation here. iPad2 AIR2.7 Published as an adHoc app?

September 27, 2011

You can create file object that points to pdf. Get its nativepath property and use it in stagewebview.loadurl. this will show the pdf in stagewebview.

Sent from my mobile

Known Participant
September 27, 2011

Sir,

import flash.media.StageWebView;

   

    public class Main extends MovieClip

    {

        private var swv:StageWebView = new StageWebView();

        public function Main()

        {

            swv.stage = stage;

            swv.viewPort = new Rectangle(0, 0, 1024, 768);

            swv.loadURL('http://www.google.com');

        }

    }

This seems to load up and display google.com website fullscreen on my ipad (have to test tonight),

But you talk about getting the nativepath of my file. Since my file will be included as a resource inside my IPA, I cannot access it over HTTP://

If my file is called "mybook.pdf" and is included in the root folder of my IPA, just besides the Default.png file, then could you please tell me how I can get that nativepath ?

Kind regards,

Bart

PS And Do I have to create this using an external class or can I just as well include the lines below in a flash as3 on the timeline ?

import flash.media.StageWebView;

var swv:StageWebView = new StageWebView();

swv.stage = stage;

swv.viewPort = new Rectangle(0, 0, 1024, 768);

swv.loadURL('http://www.google.com');

Inspiring
September 27, 2011