Open pdf new window from service ajax using angularjs

Posted: January 28, 2015 in web

For some reason using $resource won’t work using responseType: ‘arraybuffer’.
On view:

	<a href="#" ng-click="buildPDF()">{{somescope}}</a>

On controller:

$scope.buildPDF = function() {
				$http.get('http://some rest service/pdf',{headers: {'AccessKeyId': 'accesskey'}, responseType: 'arraybuffer'})
				    .success(function (data) {
					    var file = new Blob([data], {type: 'application/pdf'});
						var fileURL = URL.createObjectURL(file);
						$window.open(fileURL);
					}
				);
			};
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s