Api code here...
----------------------------------------------------------------------------------
[HttpGet]
public HttpResponseMessage DownloadProductList( )
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.MethodNotAllowed);
byte[] plist = prepo.GetProductList("ProductListReport", "p");
response.Content = new ByteArrayContent(plist);
response.Content.Headers.Add("x-fileName", "ProductListReport.pdf");
response.StatusCode = HttpStatusCode.OK;
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentDisposition.FileName = "ProductListReport.pdf";
return response;
}
-------------------------------------------------------------------------------------
service is here----
--------------------------------------------------------------------------------------
getPdfDocument(): any {
let headers = new HttpHeaders({ 'Content-Type': 'application/arraybuffer' });
return this.http
.get(this.url+"/api/ProductReport/" ,
{ headers: headers, responseType: 'blob' as 'arraybuffer', observe: 'response' as 'body' }
);
}
---------------------------------------------------------------------------------------
component is here--
--------------------------------------------------------------------------------------
){
this.service.getPdfDocument().subscribe((response)=>{
let file = new Blob([response], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
}
);
What I have tried:
Error
Failed to load PDF document.