我有这个 NODE 服务器。我使用 nodePDF 模块根据 URL 制作 pdf 文件。
模块:https://github.com/TJkrusinski/NodePDF
使文件工作完美。然而它总是出现在我的根中。我想更改为文件最终到/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, 文件名, 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'
});
关于Node.JS Node PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32553791/