简体   繁体   English

将 pdfjslib 导入 vuejs 组件

[英]import pdfjslib into vuejs component

I would like to create a viewer PDF files into electron/vuejs application.我想在电子/vuejs 应用程序中创建一个查看器 PDF 文件。

I need to use the pdfjs librarie.我需要使用 pdfjs 库。

For that I installed this package: "pdfjs-dist": "2.6.347"为此,我安装了这个 package: "pdfjs-dist": "2.6.347"

and in my component vuejs I try to used this by doing this:在我的组件 vuejs 中,我尝试通过这样做来使用它:

import pdfjsLib from "pdfjs-dist/webpack";

This import instruction seeems to be running good.这个导入指令似乎运行良好。 But If a start used this like this:但是如果开始这样使用:

created()
{
    pdfjsLib.getDocument()
}

I throw this error:我抛出这个错误:

Cannot read property 'getDocument' of undefined"

I try lot of tricks but I don't find any solution for use this library in my component.我尝试了很多技巧,但我没有找到在我的组件中使用这个库的任何解决方案。

Anyone have a vuejs project with pdfjslib for viewing pdf?任何人都有一个带有pdfjslib的vuejs项目来查看pdf?

This seems to work:这似乎有效:

import("pdfjs-dist").then((pdfjsLib) => {
  pdfjsLib.getDocument();
});

It can be used inside either created() or mounted() .它可以在created()mounted()中使用。 I'd personally use it in mounted .我个人会在mounted中使用它。
Working demo here .工作演示在这里

Also note calling getDocument() with no arguments seems to trigger some lib error (but that's outside the scope of current question):另请注意,在没有 arguments 的情况下调用getDocument()似乎会触发一些 lib 错误(但这不在当前问题的 scope 范围内):

Invalid parameter in getDocument, need either Uint8Array, string or a parameter object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM