本文介绍了如何在 angular 项目中导入 PDFjs-dist 以了解 pdf 文件的视口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 angular 项目中使用 pdfjs-dist 包.如何导入它的角度项目
I would like to use pdfjs-dist package in angular project. How to import it angular project
我使用
npm install --save pdfjs-dist
但是不知道如何导入到一个特定的组件中并使用它
But don't know how to import into a particular component and work with it
推荐答案
安装后,在 package.json
中看起来像这样
After installing it, in package.json
something look like this
"dependencies": {
...
"pdfjs-dist": "^2.2.228",
...
}
1) 现在在组件中,您可以像
1) Now in component you could be able to import it like
import * as pdfjsLib from 'pdfjs-dist';
2) 现在你可以像下面的例子一样使用它
2) Now you could use it like bellow example
yourMethodName() {
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
const loadingTask = pdfjsLib.getDocument('https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf');
loadingTask.promise.then(function(pdf) {
console.log(pdf);
});
}
这篇关于如何在 angular 项目中导入 PDFjs-dist 以了解 pdf 文件的视口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!