Open embedded PDF from AIR
What's the recommended solution, to open an embedded pdf document with Acrobat (or any other reader). I've followed a similiar question openWithDefaultApplication fails on files in application folder, but this seems not to work.
var filename = "John_Doe-tax_return_2011.pdf"; // = my filename
var realFile:File = File.applicationDirectory.resolvePath(filename);
var tempFile:File = File.createTempFile();
realFile.copyTo(tempFile,true);
tempFile.openWithDefaultApplication();
I've tested it all, so it's not a directory issue
trace(tempFile.extension) // > tmp (?? tempFile.extension = "pdf" does开发者_如何学Cn't works)
trace(realFile.exists) // > true (original pdf-document exists!)
solution:
This snippet works for Windows & Apple OSX:
var _myfilename = "John_Doe-tax_return_2011.pdf"; // = my filename
//run:
//grab the original file by name (_myfilename) from your appDir:
var realFile:File = File.applicationDirectory.resolvePath(_myfilename);#
//get user's home directory:
var destination:File = File.documentsDirectory;
//copy the original file temponary to user's home directory:
destination = destination.resolvePath(_myfilename);
realFile.copyTo(destination,true);
//open the temponary copy from user's home directory (acrobat or whatever):
destination.openWithDefaultApplication();
//end;
Don't forget to delete the file again from user's home directory (regarding to your comapnie's policy).
精彩评论