Skip to main content
Nov 27, 2011 11:14 AM UTC
Answered

How to open a pdf in its native reader in iOS using AIR?

Hi there,

I am wondering if there is any feasability of opening a pdf directly in its native reader in iOS environment. I needed this to happen from an AIR application.

I have found that AIR can be extended using a java program to do the above task for Android.

here is the link: http://www.jamesward.com/2011/05/11/extending-air-for-android/

Thanks in advance,

Sris

This topic is closed to new replies. Start a new post to keep the conversation going.
xperiments.es.frCorrect answer
Inspiring
Nov 27, 2011 7:40 PM UTC

Hi,

When you says native reader , you mean ibooks? or the integrated PDF web viewer?

iBooks:

Use the URL scheme provided from apple to call the app... you can find more information about some known schemes at http://wiki.akosma.com/IPhone_URL_Schemes

I have not tested/used it, but this is thw way you can call other apps from you app.

WebViewer:

Create a StageWebView instance, an then load the pdf with it:

var view:StageWebView = new StageWebView();

view.viewPort = new Rectangle(0,0,320,480);

view.stage = stage;

view.loadURL('yourPDF.pdf');

Note: I have not tested the last code, it can contain errors, but you get the idea....

8 replies

Known Participant
Dec 20, 2011 6:22 PM UTC

With StageWebView I'm able to view the PDF, but how would you print a PDF?

navigateToUrl and openWithDefaultApplication didn't work for me, which is a little annoying as these commands are file on the playbook.

I'm also copying the PDF from the application storage to the documentsDirectory which didn't help at all.

Translate
Nov 30, 2011 6:33 PM UTC

Thanks everyone for the solutions.

After working all the possibilities to open locally saved file on iPad

1. StageWebView 

2. navigateToUrl

3. file.openWithDefaultApplication();

4. Java socket extension for AIR,

I finally found a solution.

StageWebView works on ipad.

the code that works is as suggested by xperiments.es.fr

But the problem I faced was saving the pdf and opening the locally saved file.

Since iOS does not support desktopDirectory & documentDirectory, I tried to save the pdf in applicationDirectory/applicationStorageDirectory, that didnt work when I tried to open the pdf from those locations.

So the only way was to store the generated PDF in a temporary directory and StageWebView could locate and load that

It works!!!

Now the next challenge is, while the desktop (Windows) compilation of the app shows PDF reader with menu options, which does not show on iPad app. IPad app shows just a page index on left-top corner. It would be good if the options are shown as well.

Lets see!!!

Cheers,

Sris

Translate
Inspiring
Nov 30, 2011 7:15 PM UTC

Hi,

Good to see that now is working 4 you...

Only one comment... is really strange that you can't read the file from the applicationStorageDirectory.

I am sure you can, as I am using this directory in my StageWebViewBridge class.

The only thing I was not tested is downloading a file to the applicationStorageDirectory and reading it, but as my StageWebViewBridge uses this directory intensively, I am sure you can write a file and read it later.

On the other hand, don't waste time to see if you can show menus, control scroll, etc within the PDF, sure... imposible... I was try some times without luck... grrr

The only ( workarround ) to do a GotoPage x, is to know the dimensions of the pdf before you load it, and then if you know his height... do a loadURL with a javascript that scrolls to the correct position....

webview.loadURL("javascript:window.scrollTo( 0, pageNum*pageHeight );");

Anyway this method is a bit hackish.... as you must consider margins, zoom, etc...

I hope that this information is useful for someone...

Translate
Nov 30, 2011 7:42 PM UTC

definitely useful

I could read the file from the applicationStorageDirectory on desktop, but somehow could not load that on iPad.

But for now it works using temporary directory. I think the only problem about temporary Storage is that the files created will not be removed automatically when the app is removed. Is that so?

I will try a bit page navigation.

Anyways thanks for suggesting not to waste time on menus.

Translate
xperiments.es.frCorrect answer
Inspiring
Nov 27, 2011 7:40 PM UTC

Hi,

When you says native reader , you mean ibooks? or the integrated PDF web viewer?

iBooks:

Use the URL scheme provided from apple to call the app... you can find more information about some known schemes at http://wiki.akosma.com/IPhone_URL_Schemes

I have not tested/used it, but this is thw way you can call other apps from you app.

WebViewer:

Create a StageWebView instance, an then load the pdf with it:

var view:StageWebView = new StageWebView();

view.viewPort = new Rectangle(0,0,320,480);

view.stage = stage;

view.loadURL('yourPDF.pdf');

Note: I have not tested the last code, it can contain errors, but you get the idea....

Translate
Participating Frequently
Nov 28, 2011 3:51 AM UTC

The StageWebView is a beautifully elegant solution.

I'm now using this to open a PDF full screen. Remember though, that as StageWebView is not on the display list that you won't be able to capture any mouse events over it. In my app all the PDFs are one pagers so I add a button on the PDF to goto page 1, which I can capture and use to dispose of the StageWebView.

myStageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChangingHandler);

Thank you xperiments for your wisdom!

Translate
Participating Frequently
Nov 27, 2011 5:33 PM UTC

I'm currently running a manual conversion from PDF to SWF to display packaged assets, but it would appear that it would be possible to write one of those new fangled Native Extensions to to open the PDF in a native browser, which I'd imagine would be iBooks. I don't, however, know of any such Native Extension existing (yet).

Be sure to post here if you find a solution as I'm sure there are a lot of us here who would benefit greatly from such a feature.

Best, Hoss.

Translate