我正在电子中使用 html-pdf 从 html 生成 pdf。
当我通过“npm run start”测试时它有效。我可以得到pdf。
但是当我通过电子构建器将电子应用程序打包为.dmg文件时,
调用 pdf.create() 时出现“spawn ENOTDIR”错误
var pdf = require('html-pdf');
var options = { format: 'Letter' };
//resultFilePath = /Users/myname/Documents/result.pdf
pdf.create(htmlContent, options).toFile(resultFilePath, function(err, res)
{
}
我现在不知道。有人有同样的问题吗?
任何帮助将不胜感激。
最佳答案
html-pdf 在打包后可能无法找到虚拟二进制文件。未打包时,可以在 node_modules/phantomjs-prebuilt/bin/phantomjs
尝试通过 html-pdf 选项显式设置 phantomJS 二进制位置。
> var pdf = require('html-pdf');
> var options = { format: 'Letter', phantomPath: '/path/to/phantomJSbinary' };
> //resultFilePath = /Users/myname/Documents/result.pdf
> pdf.create(htmlContent, options).toFile(resultFilePath, function(err,
> res) { }
您可能还需要设置 options.script 以指向 html-pdf 模块中的 pdf_a4_portrait.js
副本。
其他人也遇到过类似的问题。请参阅https://discuss.atom.io/t/asar-limitations-on-node-api-spawn-a-child/28235/2
关于node.js html-pdf 调用 pdfToFile 时出现 "spawn ENOTDIR"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49307188/