Skip to content

Instantly share code, notes, and snippets.

@lele85
Created January 31, 2014 09:51
Show Gist options
  • Select an option

  • Save lele85/8729226 to your computer and use it in GitHub Desktop.

Select an option

Save lele85/8729226 to your computer and use it in GitHub Desktop.
OPEN PDF
exports.open = function(f) {
try {
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
action : Ti.Android.ACTION_VIEW,
type : 'application/pdf',
data : f.getNativePath()
}));
f = null;
} catch (err) {
f = null;
var alertDialog = Titanium.UI.createAlertDialog({
title : 'Nessun lettore PDF',
message : 'Nel tuo tablet non ci sono app per leggere i PDF, vuoi cercarne uno su Google Play Store?',
buttonNames : ['Si', 'No'],
cancel : 1
});
alertDialog.show();
alertDialog.addEventListener('click', function(evt) {
if (evt.index == 0) {
Ti.Platform.openURL('http://search?q=pdf');
}
});
}
f = null;
};
var openPDF;
var setPdfPath;
var opened = false;
if (OS_IOS) {
var infoWebView = Ti.UI.createWebView(
{
top:"74dp",
left:"0dp",
width:Ti.UI.FILL,
height:Ti.UI.FILL
}
);
setPdfPath = function(pdfPath){
infoWebView.setData(Titanium.Filesystem.getFile(pdfPath));
};
openPDF = function(parentView, onOpen, onClose){
if (opened===false) {
opened = true;
parentView.add(infoWebView);
onOpen();
} else {
opened = false;
parentView.remove(infoWebView);
onClose();
}
};
} else {
var f;
setPdfPath = function(pdfPath){
f = Ti.Filesystem.getFile(pdfPath);
};
openPDF = function() {
require("AndroidOpenPdf").open(f);
};
}
exports.setPdfPath = setPdfPath;
exports.openPDF = openPDF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment