节点wkhtmltopdf在节点webkit中创建损坏的PDF

问题描述:

在节点Webkit中将HTML转换为PDF时遇到很多麻烦.
我使用wkhtmltopdf 0.12.1,并且npm安装了wkhtmltopdf.
这是我的节点代码:

Im having a lot of trouble in node webkit to convert html to PDF.
Im using wkhtmltopdf 0.12.1 and did the npm install wkhtmltopdf.
Here is my node code:

    var wkhtmltopdf = require('wkhtmltopdf');
    var fs = require("fs-plus");

   // URL
   wkhtmltopdf('http://google.com/', { pageSize: 'letter' })
      .pipe(fs.createWriteStream('out.pdf'));

它给了我一个错误.后来我发现了这个 https://github.com/devongovett/node-wkhtmltopdf/pull/9
我进行了更正,没有再出现任何错误,但是返回的PDF已损坏.

It gave me an error. Later I found this https://github.com/devongovett/node-wkhtmltopdf/pull/9
I did the correcting and im not getting any error anymore but the PDF that I get in return is corrupted.

有什么主意吗?

因此,我找到了一个解决方案.我改为使用 https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js 和phantomJS一起运行,并通过带有phantomJS的node-webkit运行它,它的工作原理就像一个魅力.

So, I have found a solution. I instead use https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js with phantomJS and run this from node-webkit with phantomJS and it work like a charm.