Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript pdf.js在节点应用程序中运行hello world_Javascript_Pdf.js - Fatal编程技术网

Javascript pdf.js在节点应用程序中运行hello world

Javascript pdf.js在节点应用程序中运行hello world,javascript,pdf.js,Javascript,Pdf.js,我正在使用pdf.js尝试一个非常基本的示例。我所要做的就是呈现和显示一个包含来自github的hello world代码的jade模板。我在一个节点应用程序中运行这个。pdf.js文件是~node make generic命令的结果 模板为: body canvas(id='the-canvas') script(type="text/javascript", src="/scripts/dependencies/pdf.js") script(type="text/javascr

我正在使用pdf.js尝试一个非常基本的示例。我所要做的就是呈现和显示一个包含来自github的hello world代码的jade模板。我在一个节点应用程序中运行这个。pdf.js文件是~node make generic命令的结果

模板为:

body
  canvas(id='the-canvas')
  script(type="text/javascript", src="/scripts/dependencies/pdf.js")
  script(type="text/javascript", src="/scripts/dependencies/compatibility.js")
  script(type="text/javascript")
    'use strict';
    PDFJS.disableWorker = true;

    PDFJS.getDocument('/tmp/util_ac.pdf').then(function(data){
      var pdf = new PDFJS.PDFDoc(data);
      var page = pdf.getPage(1);
      var scale = 1.5;
      var canvas = document.getElementById('the-canvas');
      var context = canvas.getContext('2d');
      canvas.height = page.height * scale;
      canvas.width = page.width * scale;

      page.startRendering(context);
    });
我的错误信息是

注意:我设置disableWorker=true,因为否则会出现.workerSrc错误

    Warning: Setting up fake worker. pdf.js:1418
TypeError: undefined is not a function
    at http://localhost:8000/docs/viewer:51:13
    at Object.Promise_resolve [as resolve].transportDoc 

我在没有
disableWorker=true
的情况下尝试了你的代码,因为否则承诺永远不会被调用,并且在项目中包含了pdf.worker.js(由
节点生成的另一个文件make generic
),所以我没有得到.workerSrc错误(具体是什么?)。另外,在我使用的pdf.js版本-0.8.0中,
PDFDoc
构造函数似乎已经过时。进行这些更改后,PDF加载良好