Node.JS nodePDF

我有这个NODE服务器。 我使用nodePDF模块根据URL制作pdf文件。

该模块: https : //github.com/TJkrusinski/NodePDF

使文件工作完美。 但是它始终显示在我的根。 我想改变文件结束/公共/账单的path,但我不知道如何做到这一点。 我试图用Googlesearch,但无法find一个体面的答案。

我的代码:

router.get('/summonPhantom', function (req, res, next) { var NodePDF = require('nodepdf'); var pdf = new NodePDF('http://www.google.com',req.session.ticket+'_factuur.pdf', { 'viewportSize': { 'width': 1440, 'height': 900 }, 'args': '--debug=true' }); pdf.on('error', function (msg) { console.log(msg); }); pdf.on('done', function (pathToFile) { console.log("done"); console.log(pathToFile); }); pdf.on('stdout', function (stdout) { // handle }); pdf.on('stderr', function (stderr) { // handle }); res.writeHead(200, {"Content-Type": "application/json"}); var json = JSON.stringify({ bericht: "MAGIC IS NOT FOR EVERYONE, PLEASE CONSULT A WIZARD BEFORE USE.", }); res.end(json); }); 

正如你所看到的.on有一个pathToFile,但是我如何覆盖它?

最好的祝福

您可以传递文件名(path)作为第二个参数

NodePDF(url, fileName, opts...

所以改变你的代码如下:

 var pdf = new NodePDF('http://www.google.com',req.session.ticket+'_factuur.pdf', 'directory/filename.pdf', { 'viewportSize': { 'width': 1440, 'height': 900 }, 'args': '--debug=true' });