Created
October 27, 2016 13:44
-
-
Save pratheekhegde/a976de3964fd95c7b92eebef86c43ad4 to your computer and use it in GitHub Desktop.
Download PDF in angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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