PDF格式显示标题为 'Anonymous'?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (22)

正在使用Angular 2。从后端API获得PDF响应作为BLOB

HTML代码:

<iframe id="showPDFIframe" allowtransparency="false" title="TestPDF" width="100%" height="800" [attr.src]="dataLocalUrl" type="application/pdf"></iframe>

pdf.Component.ts

    pdfDownload: any;
    protected dataLocalUrl: SafeResourceUrl;

    ngOnInit() {
    this.requestOptions = this.createRequestOptions();
    this.requestOptions.responseType = ResponseContentType.Blob;
    this._pdfModelService.showPDF(this.requestOptions)
    .subscribe( (res) => {
      this.pdfDownload = res;
      this.dataLocalUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(res));
    }, err => {
      console.log(err);
    })
   }

pdfModelService.ts

showPDF(options?: RequestOptions): any {
    return this._http.get(this.endpoints.showPDF.uri, options)
      .map( (res) => {
        return new Blob([res], { type: 'application/pdf' })
      });
  }

见下图“匿名”显示

注意:后端API给出了我们在BLOB中转换的字节。

提问于
用户回答回答于
用户回答回答于

是否尝试在选项中提供标题:

showPDF(options?: RequestOptions): any {
return this._http.get(this.endpoints.showPDF.uri, options)
  .map( (res) => {
    return new Blob([res], { type: 'application/pdf', title: 'testpdf' })
  });
}

扫码关注云+社区