栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何下载我的服务器(springboot)上生成的pdf格式文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何下载我的服务器(springboot)上生成的pdf格式文件?

正如@JBNizet所建议的那样,我实现了以下可观察对象:

零件:

getPDF(){      this.apiService.getPDF(this.invoiceId)      .subscribe(        (data: Blob) => {          var file = new Blob([data], { type: 'application/pdf' })          var fileURL = URL.createObjectURL(file);// if you want to open PDF in new tab          window.open(fileURL);var a         = document.createElement('a');          a.href        = fileURL;a.target      = '_blank';          a.download    = 'bill.pdf';          document.body.appendChild(a);          a.click();        },        (error) => {          console.log('getPDF error: ',error);        }      );    }

服务:

getPDF(invoiceId : number): Observable<Blob>     {         this.url = this.main_url + '/invoices/generatepdf/'+invoiceId;         var authorization = 'Bearer '+sessionStorage.getItem("access_token");         const headers = new HttpHeaders({ 'Content-Type': 'application/json',         "Authorization": authorization, responseType : 'blob'});         return this.httpClient.get<Blob>(this.url, { headers : headers,responseType :          'blob' as 'json'});     }

我引用的网址:

  1. 重载#2:https://angular.io/api/common/http/HttpClient#get
  2. 使用Http Post预览Blob:https: //dzone.com/articles/how-to-preview-blobs-with-http-post-and-angular-5


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/615609.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号