How to Display blob (.pdf) in an AngularJS app

后端 未结 8 1382
逝去的感伤
逝去的感伤 2020-11-22 11:01

I have been trying to display pdf file which I am getting as a blob from a $http.post response. The pdf must be displayed within the app using

8条回答
  •  一整个雨季
    2020-11-22 11:44

    Most recent answer (for Angular 8+):

    this.http.post("your-url",params,{responseType:'arraybuffer' as 'json'}).subscribe(
      (res) => {
        this.showpdf(res);
      }
    )};
    
    public Content:SafeResourceUrl;
    showpdf(response:ArrayBuffer) {
      var file = new Blob([response], {type: 'application/pdf'});
      var fileURL = URL.createObjectURL(file);
      this.Content = this.sanitizer.bypassSecurityTrustResourceUrl(fileURL);
    }
    
      HTML :
    
      
    

提交回复
热议问题