javascript - iframe 中的 PDF 显示标题为 'Anonymous'

标签 javascript angular pdf iframe

我正在使用 Angular2。我从后端 API 获得 BLOB 形式的 PDF 响应。 PDF 在 iframe 中显示正常,但标题显示为“匿名”。有人可以指导吗?

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' })
      });
  }

见下图“Anonymous”正在显示 enter image description here

注意:后端 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' })
  });
}

关于javascript - iframe 中的 PDF 显示标题为 'Anonymous',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45759980/

相关文章:

javascript - jQuery 点击事件不起作用

angular - 如何使用 Angular Material Stepper(Angular 4) 阻止用户移动到下一步,直到完成当前步骤

javascript - Angular 2 如何从路由组件发出数据

python - 从 PDF 文件中提取标题?

c++ - 如何在Qt中打印pdf文件

pdf - powershell - 检查pdf是否加密

javascript - Lodash remove 根据 id 属性从数组中删除一个对象

javascript - 如何删除带有原型(prototype)的对象

javascript - 我想停止提交整个页面并使用 javascript 仅提交我的表单

angular - 应用程序正在生成我的延迟加载模块的一部分,前缀为 default ~ .. 甚至在它被调用之前