Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Last active February 23, 2016 14:37
Show Gist options
  • Select an option

  • Save aaronksaunders/cc83bb71878149e6fe35 to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/cc83bb71878149e6fe35 to your computer and use it in GitHub Desktop.

This will open the share dialog for the PDF file and allow the user to take action.

I discovered that you cannot open the file directly because it is sandboxed on IOS, see information on the cordova-plugin-file repo regarding directoy structure and R/W access

Needs the following plugins.
  • cordova-plugin-file
  • cordova-plugin-file-opener2
// assuming the path to the file is in the www directory...
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "www/midterm.pdf", function(entry) {
console.log(entry.toURL());
cordova.plugins.fileOpener2.open(
entry.toURL(), // convert to nice URL for opening
'application/pdf', {
error: function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success: function() {
console.log('file opened successfully');
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment