【问题标题】:Getting reference to pdfjsLib using the @types/pdfjs-dist in Angular在 Angular 中使用 @types/pdfjs-dist 获取对 pdfjsLib 的引用
【发布时间】:2021-07-04 12:38:31
【问题描述】:

我正在尝试在预编译的 Angular 9 项目中使用 pdf.js 库。

我使用npm i --save pdfjs-distnpm i --save @types/pdfjs-dist 安装

然后根据我在网上看到的情况,我应该可以使用import * as pdfjsLib from 'pdfjs-dist'; 在我的组件中访问它。问题是我在编译器中收到此错误:

我尝试了许多其他方法来获取引用,但它们要么无法获取引用,要么抛出相同的错误消息。

我也尝试过这里的建议:Importing namespace and interface with methods in TypeScript (TSX) in pdfjs-dist (PDFJS) 但是,我收到错误消息,告诉我 PDFJSStatic 不是导出成员。

任何帮助都将不胜感激!

我的目标是能够使用 getDocument() 函数。

【问题讨论】:

    标签: angular compiler-errors angular-material pdfjs pdfjs-dist


    【解决方案1】:

    试试这个,它是目前最新的版本。

    npm i @libusoftcicom/pdfjs-dist

    import * as pdfjsLib from '@libusoftcicom/pdfjs-dist';
    import { PDFPageProxy, PDFJSStatic } from '@libusoftcicom/pdfjs-dist/types/display/api';
    

    把这个放在你的加载函数中。

    const pdfjsWorker = await import('@libusoftcicom/pdfjs-dist/build/pdf.worker.entry');
    pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
    

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 2020-08-09
      • 2021-09-18
      • 2022-01-26
      • 2018-05-25
      • 2020-04-24
      • 2021-05-10
      • 2021-07-10
      • 2020-02-06
      相关资源
      最近更新 更多