tab print open new generate data application abrir angularjs pdf blob asp.net-web-api chunked-encoding

angularjs - print - ng-pdf



Error al cargar el documento PDF-Angular JS-BLOB (1)

problema hay en el controlador. {responseType:''arraybuffer''} es muy necesario. Para $http.get - Debe ser el segundo parámetro. Para $http.post : debe ser el tercer parámetro.

En el caso anterior, estoy usando $ http.post y he pasado {responseType:''arraybuffer''} como segundo parámetro.

$http.post(''/api/Sample/GetTestFile'', {responseType:''arraybuffer''})

Código corregido

$http.post(''/api/Sample/GetTestFile'','''', {responseType:''arraybuffer''})

Estoy tratando de obtener un documento PDF de la API web, y quiero mostrarlo en la aplicación Angular. Obteniendo "Error al cargar el error del documento PDF". He seguido la publicación " AngularJS: Display blob (.pdf) en una aplicación angular ". Mientras que, puedo descargar el mismo archivo con éxito siguiendo la publicación " Descargar archivo desde un método API Web ASP.NET usando AngularJS ".

Parece que estoy obteniendo el archivo como "Transferencia fragmentada codificada". De alguna manera esto no se decodifica cuando se intenta mostrar en la aplicación angular. Por favor avise.

Código API web:

HttpResponseMessage result = null; var localFilePath = @"C:/Test.pdf"; if (!File.Exists(localFilePath)) { result = Request.CreateResponse(HttpStatusCode.Gone); } else {// serve the file to the client result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read)); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); result.Content.Headers.ContentDisposition.FileName = "Test.pdf"; result.Content.Headers.Add("x-filename", "Test.pdf"); } return result;

Controlador angular:

myModule.controller("pdfviewerController", function ($scope, $http, $log, $sce) { $http.post(''/api/Sample/GetTestFile'', {responseType:''arraybuffer''}) .success(function (response) { var file = new Blob([response], { type: ''application/pdf'' }); var fileURL = URL.createObjectURL(file); $scope.content = $sce.trustAsResourceUrl(fileURL); }); });

Plantilla HTML:

<embed ng-src="{{content}}" style="width:200px;height:200px;"></embed>