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

时间:2018-03-15 18:53:30

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

我在电子中使用html-pdf从html生成pdf。

当我通过“npm run start”进行测试时,它工作正常。我可以获得pdf。

但是当我通过电子建设者将电子应用程序打包到.dmg文件时,

调用pdf.create()

时出现“spawn ENOTDIR”错误
library(ggplot2)

# reverse factor levels
melted$variable <- factor(melted$variable, levels=rev(levels(melted$variable)))

xlabels <- 1:15
ggplot(melted, aes(x=CohortPeriod, y=variable)) +
  ggtitle('Retention by cohort') +
  theme_bw() +
  xlab('CohortPeriod') +
  ylab('% of Cohort Purchasing') +
  geom_tile(aes(fill = value), color='white') + geom_text(aes(label = round(value, 2)), size=2) +
  scale_x_continuous(breaks = xlabels) +
  scale_fill_gradient(low = 'white', high = '#2d1e3e', space = 'Lab', na.value = 'white') +
  theme(axis.text.x=element_text(angle=0),
        axis.ticks=element_blank(),
        axis.line=element_blank(),
        panel.border=element_blank(),
        panel.grid.major=element_line(color='#eeeeee'))

javascript debugger with error message

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

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

对于在电子打印时遇到问题的人。

在可见窗口中打开打印内容是很好的解决方案,我按照zen的回答 在How to print a DIV in ElectronJS

适用于Windows和MacOS。