Skip to main content
November 27, 2011
Answered

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

  • November 27, 2011
  • 4 replies
  • 7670 views

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 has been closed for replies.
Correct answer xperiments.es.fr

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....

4 replies

Known Participant
December 20, 2011

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.

November 30, 2011

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

Inspiring
November 30, 2011

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...

November 30, 2011

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.

xperiments.es.frCorrect answer
Inspiring
November 27, 2011

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....

Participating Frequently
November 28, 2011

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!

Participating Frequently
November 27, 2011

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.