Created
June 5, 2015 17:02
-
-
Save MarkLavrynenko/5b763e36b128170cdb77 to your computer and use it in GitHub Desktop.
Download Pdf file using AJAX (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
angular.module("test-app", []) | |
.controller("PDFDownloadController", ["$scope", "$http", function($scope, $http) { | |
function handleResponse(response){ | |
var pdfFile = new Blob([response.data], { type : 'application/pdf' }) | |
var downloadURL = URL.createObjectURL(pdfFile); | |
var link = document.createElement('a'); | |
link.href = downloadURL; | |
link.download = "preview.pdf" | |
document.body.appendChild(link); | |
link.click(); | |
} | |
$scope.loadPdf = function () { | |
$http.get("file.pdf", { responseType : 'arraybuffer' }).then(handleResponse); | |
}; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment