node.js html-pdf 调用 pdfToFile 时出现 "spawn ENOTDIR"错误

标签 node.js spawn electron-builder html-pdf

我正在电子中使用 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) 
{
}

javascript debugger with error message

我现在不知道。有人有同样的问题吗?

任何帮助将不胜感激。

最佳答案

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/

相关文章:

javascript - 如何在 NodeJS 中运行无限阻塞进程?

javascript - 使用 casperjs 遇到 TypeError

javascript - 使用node js关闭.exe文件

reactjs - 使用外部应用程序打开 Electron 中打包的 PDF

electron - Electron Builder Appx : The package manifest is not valid

node.js - Windows 上的 Electron Packager 什么都不做

javascript - Yeoman 使用 args 通过代码调用生成器

mysql - 表情符号未插入数据库 Node js mysql

node.js - req.protocol 从不在 nginx 代理后面提供 https

Python:长时间运行的后台进程的生成或线程?