Node.JS nodePDF

Node.JS nodePDF,node.js,pdf,Node.js,Pdf,我有这个节点服务器。我使用nodePDF模块根据URL生成pdf文件 模块: 使文件工作完美。然而,它总是出现在我的根。我想将文件更改为/public/bills的路径,但我不知道如何执行此操作。我试着在谷歌上搜索,但找不到合适的答案 我的代码: router.get('/summonPhantom', function (req, res, next) { var NodePDF = require('nodepdf'); var pdf = new NodePDF('http://www.

我有这个节点服务器。我使用nodePDF模块根据URL生成pdf文件

模块:

使文件工作完美。然而,它总是出现在我的根。我想将文件更改为/public/bills的路径,但我不知道如何执行此操作。我试着在谷歌上搜索,但找不到合适的答案

我的代码:

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,但如何覆盖它

请注意

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

NodePDF(url、文件名、选项…

因此,请按如下方式更改代码:

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

你有权限吗?或者文件夹是否存在?请尝试在“/directory/filename.pdf”开头添加一个斜杠,谢谢你的帮助。但是我制作了一个单独的PHP发票服务器。它与html2pdf一起工作。我将在这个周末试着看看是否仍然可以找到解决方案。为了未来的读者。