首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在iframe中显示标题为“匿名”的PDF

在iframe中显示标题为“匿名”的PDF
EN

Stack Overflow用户
提问于 2017-08-18 23:16:31
回答 2查看 3.2K关注 0票数 18

我正在使用Angular2。我得到的PDF响应作为BLOB从后端API。PDF在iframe中显示正常,但标题显示为“匿名”。有没有人能给我带路?

html代码:

代码语言:javascript
复制
<iframe id="showPDFIframe" allowtransparency="false" title="TestPDF" width="100%" height="800" [attr.src]="dataLocalUrl" type="application/pdf"></iframe>

pdf.component.ts

代码语言:javascript
复制
    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

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

如下图所示:“匿名”

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

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45759980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档