【问题标题】:Angular 11: I can't display a pdfAngular 11:我无法显示 pdf
【发布时间】:2021-09-29 05:52:32
【问题描述】:

我正在尝试将 Base64 中的字符串显示为 PDF 并在浏览器中下载它,当我发送拥有它的变量时,它不会在浏览器中显示。

app.component.html ->

<div class="modal-header">
  <h3 style="font-size: 1.2em; color: #838181" class="modal-title" id="modal-title">
    {{ terminosCondicionesModalSeguroVidaTitulo }}
  </h3>
  <button type="button" class="close" aria-describedby="modal-title" (click)="close()">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<div class="modal-body">
   
    <iframe width='100%' height='100%' src=''>{{SeguroVida}}</iframe>
   
</div>
<div class="modal-footer">
  <input type="submit" class="btnGenericGreen next" (click)="Aprobar()"
    value="{{ terminosCondicionesModalSeguroVidaBoton }}" />
</div>

app.component.ts ->

llenadoParametros() {
  console.log(this.paramArray.find((x) => x.codigo === DocumentsAcceptation.SeguroVida) ? .valorAlfa || '');
  this.SeguroVida = this.paramArray.find(
    (x) => x.codigo === DocumentsAcceptation.SeguroVida
  ) ? .valorAlfa || '';

  this.SeguroVida = this.sanitizer.bypassSecurityTrustUrl('data:application/pdf;base64,' + this.paramArray.find((x) => x.codigo === DocumentsAcceptation.SeguroVida) ? .valorAlfa || '');
}

我仍然不知道为什么它没有在浏览器中显示。我做错了什么?

【问题讨论】:

    标签: html angular typescript pdf base64


    【解决方案1】:

    您必须将 src 设置为 iframe。

    <iframe width='100%' height='100%' [src]='SeguroVida'></iframe>
    

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 2021-01-21
      • 1970-01-01
      • 2021-12-27
      • 2020-07-10
      • 2020-08-03
      • 2017-10-25
      • 1970-01-01
      • 2016-08-25
      相关资源
      最近更新 更多