Monday, October 16, 2017

How to open pdf file on Android.

Following example would be helpful for opening pdf file

////////------////////////

var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "test.pdf"); 
var outFile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'tempFile.pdf'); 
var outPath = outFile.nativePath; 
file.copy(outPath); 

try{ 
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({ 
action: Ti.Android.ACTION_VIEW, 
type: 'application/pdf', 
data: outPath 
})); 
} catch(e) { 
alert('You must install a PDF reader to view this file'); 



OR


try{ 
var intent = Ti.Android.createIntent({ 
action : Ti.Android.ACTION_VIEW, 
type : "application/pdf", 
data: outPath 
}); 


var open = Ti.Android.createIntentChooser(intent, L('open_intent')); 
Ti.Android.currentActivity.startActivity(open); 
} catch(e) { 
alert('You must install a PDF reader to view this file'); 


file = null; 


Thanks

No comments:

Post a Comment