如何在 angular 项目中导入 PDFjs-dist 以了解 pdf 文件的视口 [英] How to import PDFjs-dist in angular project in order to know to view-port of the pdf file

查看:54
本文介绍了如何在 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 文件的视口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆