Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Api code here...
----------------------------------------------------------------------------------
C#
[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----
--------------------------------------------------------------------------------------
C#
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--
--------------------------------------------------------------------------------------

C#
){
  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.
Posted
Updated 25-Oct-20 22:44pm
v3
Comments
Sandeep Mewara 23-Oct-20 10:07am    
Your response type seems not blob. See this similar discussion: https://stackoverflow.com/questions/62042843/failed-to-load-pdf-document-angular-8

Working example; https://stackblitz.com/edit/angular-6qwrvh
Member 11567959 11-Nov-20 2:55am    
not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900