采用的是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

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐