Skip to content

Instantly share code, notes, and snippets.

@pratheekhegde
Created October 27, 2016 13:44
Show Gist options
  • Save pratheekhegde/a976de3964fd95c7b92eebef86c43ad4 to your computer and use it in GitHub Desktop.
Save pratheekhegde/a976de3964fd95c7b92eebef86c43ad4 to your computer and use it in GitHub Desktop.
Download PDF in angular
pdf: $resource(ENV.mainUrl + '/filestack/pdf',
null, {
send: {
method: 'POST',
// timeout: POST_TIMEOUT,
responseType: 'arraybuffer',
headers: {
'Content-Type': 'application/pdf',
'Accept': 'application/pdf'
},
transformResponse: function (data) {
return {
response: new Blob([data], {
type: 'application/pdf'
})
};
}
}
})
// In the controller
function generatePDF() {
vm.showLoading = true;
ProfileService.generatePDF().then(function (data) {
vm.showLoading = false;
// $window.open(response.filePath, '_blank');
// var data = new Blob([response], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(data.response);
window.open(fileURL);
// FileSaver.saveAs(data.response, 'My Profile Snapshot.pdf'); // This is from FileSaver.js
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment