【发布时间】:2018-01-28 14:29:02
【问题描述】:
在 Angular 4.3 中,我想打开一个模式弹出窗口并显示一个嵌入的 pdf 文件,如下所示:https://pdfobject.com/static.html
我使用了弹出很好的modal popup component from this answer。我的模态测试 html 如下所示:
<a class="btn btn-default" (click)="setContent();modal.show()">Show</a>
<app-modal #modal>
<div class="app-modal-header">
Testing pdf embedding
</div>
<div class="app-modal-body">
<div class="embed-responsive" *ngIf="ContentUrl">
<object [attr.data]="ContentUrl"
type="application/pdf"
class="embed-responsive-item">
<embed [attr.src]="ContentUrl"
type="application/pdf" />
</object>
</div>
<p><a [href]="ContentUrl">PDF Download</a></p>
</div>
<div class="app-modal-footer">
<button type="button" class="btn btn-default" (click)="modal.hide()">Close</button>
</div>
</app-modal>
在我的组件中,我这样设置ContentUrl:
public ContentUrl: SafeUrl;
public setContent() {
this.ContentUrl = this._sanitizer.bypassSecurityTrustResourceUrl("/img/test.pdf");
}
弹出窗口可以很好地打开,但它不显示嵌入的 pdf。它甚至不会尝试从服务加载 url。下载链接运行良好,并询问是否应将 pdf 保存到光盘或打开。
我也尝试将 pdf 嵌入弹出窗口之外,但也无济于事。
我试过 Chrome、Edge 和 IE。 None 显示嵌入的 pdf。
那么如何在角度组件中显示/嵌入 pdf?
【问题讨论】: