gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:55:18 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com