SyntaxError:解析错误 - 使用react-pdf-js lib的Wkhtmltopdf

时间:2016-05-20 16:38:09

标签: qt pdf reactjs wkhtmltopdf pdfjs

我正在使用wkhtmltopdf版本0.12.2.1(带有修补的qt)来渲染我的reactJs应用程序!它工作正常,直到我添加react-pdf-js lib来呈现我的应用程序内生成的pdf。我按照react-pdf-js文档中描述的代码(参见https://www.npmjs.com/package/react-pdf-js)来使其工作。

pdf在我的页面内呈现,看起来确实非常酷。但是当我再次尝试运行wkhtmltopdf时,为了生成我的应用程序的任何页面的pdf,会返回以下错误:

desenv01@desenv01-PC:~$ wkhtmltopdf -O Landscape --print-media-type --debug-javascript  http://localhost:3000/report/1 report.pdfLoading pages (1/6)
Warning: undefined:0 ReferenceError: Can't find variable: Float64Array
Warning: http://localhost:3000/assets/js/app.js:46789 SyntaxError: Parse error
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
Printing pages (6/6)
Done

然后,我去了我的app.js看看46789号线上的内容:

    set href(href) {
      clear.call(this);
      parse.call(this, href);
    },

    get protocol() {
      return this._scheme + ':';
    },
    set protocol(protocol) {
      if (this._isInvalid)
        return;
      parse.call(this, protocol + ':', 'scheme start');
    },

错误发生在parse.call(this, href);pdf.combined.js上,该行是{{1}}脚本的一部分。

我在网上找不到任何解决方案,所以我想知道是否有人可能知道我做错了什么或者解决方法。

谢谢..

1 个答案:

答案 0 :(得分:0)

我使用wkthmltopdf 12.312.4遇到了这个问题,因为我的IDE设置为让我使用var而不是let。问题是较旧的Qt引擎为这些程序版本提供动力并不能识别新式的ES6关键字。不确定你是否可以下转换React。否则,您可以尝试使用较新Qt的最新版本。