Это мой взгляд
<button ng-click="GetReport(doc.DocumentName ,caseid)">{{doc.DocumentName}}<button>
Это мой контроллер
public FileResult GetReport(string Docment , int caseid)
{
string ReportURL = Server.MapPath("~/UploadedFile/CaseID-" + caseid + @"\Imported\" + Docment);
byte[] FileBytes = System.IO.File.ReadAllBytes(ReportURL);
return File(FileBytes, "application/pdf");
}
Это мой угловой скрипт js
$scope.GetReport = function(doc , caseid)
{
$.ajax({
type: 'POST',
url: '/Case/GetReport',
data: { "Docment": doc, "caseid": parseInt(caseid) },
async: false,
success: function (data) {
var result = data;
if (result != null) {
var decodedImage = dataURItoBlob(data);
var file = new Blob([decodedImage], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
}
else {
alert("Something went wrong!");
}
},
error: function (data) {
}
});
}
function dataURItoBlob(dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to a typed array
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], { type: mimeString });
}
Я получил pdf-данные в виде декодированных данных в ajax success, а также открыл новое окно. но я не могу загрузить PDF в новой вкладке. Ошибка как "не удалось отобразить PDF-документ" может кто-нибудь помочь мне отобразить PDF в новой вкладке окна