这是相关的代码。
let Name = moment().unix() + ".pdf";
var html = fs.readFileSync('./test/businesscard.html', 'utf8');
let filename = "C:\\App\\Register\\pdf\\" + Name;
pdf.create(html, options).toFile(filename, function (err, response) {
if (err) {
res.status(403).json({
message: 'error'
})
} else {
res.status(200).json({
message: 'success'
})
}
}
在开发版本上正常工作并创建PDF文件。但是当我创建一个 电子生成包,未生成pdf文件。
如果有任何可用的解决方案,那将是一个很大的帮助
答案 0 :(得分:0)
您应使用app.getAppPath()对打包的应用程序使用绝对路径。
替换此行
var html = fs.readFileSync('./test/businesscard.html', 'utf8');
以此
var html = fs.readFileSync(path.join(app.getAppPath(), '/test/businesscard.html', 'utf8'));
又不忘记添加
const path = require('path')
const app = require('electron').remote.app