采用的是http://blog.lookpeakfans.xyz/2018/07/22/preview-pdf/这篇文章中的第二种方案:

求解:载入 PDF 时发生错误。  PDF.js v2.3.200 (build: 4ae3f9fc) 信息:Failed to fetch

 

没找到以上的解决方案。。。

换了一种方案,我把核心代码列出来如下:(我的是从上个页面带过来的pdfUrl,在子页面直接预览的)

html文件中:

    <ng-container app-slot-content-box>
        <section class="pdf-content" id="pdf-content">
              <iframe [src]="pdfUrl" width='100%' height='100%' frameborder='1' ></iframe>
        </section>
    </ng-container>

ts文件:


import { DomSanitizer } from '@angular/platform-browser';
。
。
。
pdfUrl;
constructor(
     public sanitizer: DomSanitizer
) {
  activatedRoute.queryParams.subscribe(queryParams => {
      if (queryParams && queryParams.pdfPath) {
           this.pdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(queryParams.pdfPath);
      } else {
           this.pdfUrl = '';
      }
    });
}

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐