HTML to PDF with Node.js and Electron.js



以下是相关代码。

        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 文件。

如果有任何可用的解决方案,那么这将是一个很大的帮助

应使用 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

最新更新