Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <a href="https://somedomain.com/api/doc/somefile.pdf" ng-click="openPdf($event)">PDF</a>
  2.  
  3. function openPdf($event) {
  4. // Prevent default behavior when clicking a link
  5. $event.preventDefault();
  6.  
  7. // Get filename from href
  8. var filename = $event.target.href;
  9.  
  10. $http.get(filename, {responseType: 'arraybuffer'})
  11. .success(function (data) {
  12. var file = new Blob([data], {type: 'application/pdf'});
  13. var fileURL = URL.createObjectURL(file);
  14.  
  15. // Open new windows a show PDF
  16. window.open(fileURL);
  17. });
  18. }
Add Comment
Please, Sign In to add comment