open and display a pdf file using actionscript for

2019-04-15 19:15发布

问题:

Currently I am working with Adobe AIR and getting practice with ActionScript. My aim is to display a PDF file in a view (iPad view in specific). To do so, I was using URLRequest to specify the location of the PDF and HTMLLoader for load the PDF. However is not working, I read in the documentation the following:

HTMLLoader class. AIR profile support: This feature is supported on all desktop operating systems, but is not supported on mobile devices or on AIR for TV devices.

For this reason I would like to ask you folks if you have done something similar, or do you know a workaround for it?

Thanks in advance!

回答1:

I think StageWebView is what you need.

I've just done a similar thing like this...

var _file:String = "nameOfPdf.pdf";
var webView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle(20,103,960,640);//specify the clipping mask(x,y,w,h)

//NB I have my pdf file as an included file here (added in the publish panel.
var fPath:String = new File(new File("app:/includes/"+_file).nativePath).url;
webView.loadURL( fPath );

//Alternatively you should be able to navigate to a URL
webView.loadURL("http://www.google.com");


回答2:

There's an external tool called pdf2swf that will transform a pdf into a working swf that you can add just as any other swf. If all you want is a fixed pdf, you can transform it previously and load the transformed swf directly. But if you want any pdf, you would need a external web server to perform the transformation step.