admin管理员组文章数量:1356957
I have installed pdf including types using
npm install --save pdf @types/pdf
Unfortantly I cannot find any documentation on how to use this. If I do:
import {PDFJS} from 'pdf';
PDFJS.getDocument(fileName)
I get:
TyeError: Cannot read 'getDocument' of undefined
So how should I initialize this?
I have installed pdf including types using
npm install --save pdf @types/pdf
Unfortantly I cannot find any documentation on how to use this. If I do:
import {PDFJS} from 'pdf';
PDFJS.getDocument(fileName)
I get:
TyeError: Cannot read 'getDocument' of undefined
So how should I initialize this?
Share Improve this question asked Jan 6, 2017 at 10:08 NathanNathan 7,75914 gold badges74 silver badges150 bronze badges 2- did you also install the pdf package? or only the types package? – toskv Commented Jan 6, 2017 at 10:10
- I installed it the way I wrote. That installs the pdf package too, right? I can also find the folder "pdf" in my nodes_modules. – Nathan Commented Jan 6, 2017 at 10:12
1 Answer
Reset to default 7Update:
Since writing this answer, the type definitions have been renamed to match the NPM package, and a proper export definition has been added, so you can ignore all of the below and just npm install --save-dev @types/pdf-dist
.
Original Answer:
This is a consequence of bad package naming - the @types/pdf
package provides types for Mozilla's PDF.js (which you can obtain via NPM using the pdfjs-dist
package), not the long since abandoned pdf
.
npm uninstall --save pdf
npm install --save pdfjs-dist
Additionally, it seems like the @types/pdf
definitions only defines PDF.js as a global variable, not as an importable module. This is despite the fact that the library definitely supports being imported... Add the following to your project somewhere, it should fix it.
declare module "pdfjs-dist" {
export = { PDFJS };
}
Then import PDF.js like so:
import { PDFJS } from "pdfjs-dist";
本文标签: javascriptHow am I supposed to use the quotpdfquot package from typescriptStack Overflow
版权声明:本文标题:javascript - How am I supposed to use the "pdf" package from typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064974a2584821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论