I am going to print an Image (embeded as a property into an object), which retrieved from a WebApi.
So far, I could load the image and show it perfectly on my page like the following:
<img ng-src="data:image/jpeg;base64,{{t.Image}}"/>
However the problem is I don't know how can I print this image?
I have tried out the following listing but I am faced with crashed google chrome page.
var img= window.open($scope.t.Image);
img.print();
Question is How can I print the Image?
This is my Object coming from WebApi:
public class TestImage
{
public string Name { get; set; }
public byte[] Image { get; set; }
}
and the following is how I call the Get method:
$scope.getData = function (val) {
return $http.get('http://localhost:2740/GetData', {
params: {
name: val
}
}).then(function (response) {
$scope.t = response.data;
return response.data;
});
};
********UPDATED********
$scope.imgName = "myImage";
$scope.print = function () {
var printContents = document.getElementById($scope.imgName);
var popupWin = window.open('', '_blank', 'width=300,height=300');
popupWin.document.open();
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + printContents + '</html>');
popupWin.document.close();
}
<img id="{{imgName}}" ng-src="data:image/jpeg;base64,{{t.Image}}" />