首页
学习
活动
专区
工具
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代码:

<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中转换的字节数。

EN

回答 2

Stack Overflow用户

发布于 2017-08-22 12:32:04

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

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

Stack Overflow用户

发布于 2017-08-26 05:03:43

虽然我不确定为什么代码中指定的标题字段"TestPDF“没有出现在页面上,但显示的”(匿名)“值可能只是从PDF文件本身中提取元数据。一种可能的解决方案是检查PDF文档属性中的title字段,以便在那里设置标题。在Adobe Acrobat中,从文件菜单中选择属性>描述以检查/更新标题字段。

参考文章来自W3.org:https://www.w3.org/TR/WCAG20-TECHS/PDF18.html

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

https://stackoverflow.com/questions/45759980

复制
相关文章

相似问题

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