1

アップデート:

wkhtmltopdfが正しく終了しない問題のようです


私はノードで次のことをしています:

console.log("before");
fs.writeFile(html_filename, html, function (err) {
  if (err) {res.writeHead(400); res.end("" + err); return;}

  console.log("wrote html fine; now converting");
  exec('wkhtmltopdf ' + html_filename + ' ' + pdf_filename, function (err, stdout, stderr) {
    if (err) {res.writeHead(400); res.end("" + err); return;}

    console.log("converted; now reading");
    fs.readFile(pdf_filename, function (err, data) {
      if (err) {res.writeHead(400); res.end("" + err); return;}

      console.log("read fine; now serving");
      res.writeHead(200, {"content-type" : "application/pdf"});
      res.end(data);
    });
  });
});

これは正常に機能しますが、これが実行されるたびにノードプログラムがハングし、cmd+tabを実行すると「exec」プロセスが表示されます。このプロセスにタブで移動すると、ノードプログラムが続行します。

なぜ何かアイデアはありますか?

4

2 に答える 2

4

wkhtmltopdfの代わりに、Phantom.jsを使用します:http://phantomjs.org/

簡単なラスタライズスクリプトを作成できます。

var page = require('webpage').create(),
address, output, size;

if (phantom.args.length < 2 || phantom.args.length > 3) {
    console.log('Usage: rasterize.js URL filename');
    phantom.exit();
} else {
    address = phantom.args[0];
    output = phantom.args[1];
    page.viewportSize = { width: 600, height: 600 };
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 200);
        }
    });
}

そして、電話してください:

phantomjs rasterize.js http://path/to/webpage output.pdf
于 2012-08-01T01:19:25.270 に答える
0

ええと、これはosxのバグのようです...

于 2012-07-31T23:16:18.680 に答える