如何在Firefox插件中使用pdf.js库? [英] How to use pdf.js library in a firefox addon?

查看:365
本文介绍了如何在Firefox插件中使用pdf.js库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Google翻译页面中的 pdf 文档的insert做Firefox扩展,我想使用pdf.js.不想使用embed或iframe广告代码,我想使用自己的 pdf 查看器. 我正在尝试在Firefox加载项中使用pdj.js库,但是它不起作用. 我已经尝试过将其添加到manifest.json中.

I'm making a Firefox add-on extension to insert a pdf document in the translated page of Google and I want to use pdf.js. Don't want to use embed or iframe tags to do it, I want to do my own pdf viewer. I'm trying to use the pdj.js library in a Firefox add-on, but it not work. I have already tried to do it adding this in manifest.json.

    "content_scripts": [ 
    {
      "matches":["*://translate.google.com/*"],
      "js": ["script.js","pdf.js"]
    }
   [enter image description here][1] ]

但是当我这样做时:

pdfjsLib.getDocument(pdf_url); 

它不起作用,脚本停止工作.

it not working, the script stop working.

我确实尝试将脚本添加到页面顶部

I do try to add the script in the head of the page doing

var pdf_js = document.createElement('script');
pdf_js.src = 'https://mozilla.github.io/pdf.js/build/pdf.js';
document.getElementsByTagName('head')[0].appendChild(pdf_js);

,它也不起作用.但是,当我在Firefox的调试控制台中使用 pdfjsLib 时,它可以工作,但是从我用于插件的脚本中,pdfjsLib.getDocument功能却无法工作.

and it does not work either. But when I use pdfjsLib from debug console in Firefox it works, but from the script that I use for the addon, pdfjsLib.getDocument function it not working.

使用jQuery时,我遇到了类似的问题,该库在脚本中不起作用.

I had a similar problem when I used jQuery, the library does not work in the script.

我尝试按照 Jaromanda X 的建议观看导航控制台,而我明白了

I tried watching the navigation console as suggested by Jaromanda X and I got this

ReferenceError:

ReferenceError:

pdfjsLib未定义

pdfjsLib is not defined

推荐答案

我通过添加以下行来解决它:

I solved it by adding the following line:

pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

这篇关于如何在Firefox插件中使用pdf.js库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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