我使用NodeServices在AspNetCore应用程序中创建PDF。App在本地机器上运行良好,但在生产中部署时,在调用pdf函数时,我得到以下错误:
错误:在D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ( _errnoException /util.js:1022:11) at Process.ChildProcess._handle.onexit (util.js:1022:11/child_process.js:190:19),onErrorNT ( ENOENT /child_process.js:372:16),_combinedTickCallback (ENOENT/process/next_tick.js:138:11),process._tickCallback (ENOENT/process/next_tick.js:180:9)生成onErrorNT ENOENT 呈现报告中的Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException:错误:生成D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT 错误:在D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ( _errnoException /util.js:1022:11) at Process.ChildProcess._handle.onexit (util.js:1022:11/child_process.js:190:19),onErrorNT ( ENOENT /child_process.js:372:16),_combinedTickCallback (ENOENT/process/next_tick.js:138:11),process._tickCallback (ENOENT/process/next_tick.js:180:9)生成onErrorNT ENOENT
我核实了所有的文件都在正确的地方。node_modules存在于部署中。
Azure节点版本: 8.9.4
生成PDF的代码:
module.exports = function (callback, html) {
var jsreport = require('jsreport-core')();
jsreport.init().then(function () {
return jsreport.render({
template: {
content: html,
engine: 'jsrender',
recipe: 'phantom-pdf'
}
}).then(function (resp) {
callback(/* error */ null, resp.content.toJSON().data);
}).catch(function (e) {
callback(/* error */ e, null);
});
}).catch(function (e) {
callback(/* error */ e, null);
});
};发布于 2018-03-30 12:58:40
问题在于Node软件包的安装。我使用Azure上的托管Linux来构建解决方案。切换到托管的VS2017构建,一切都很顺利。https://github.com/pofider/phantom-html-to-pdf/issues/68
发布于 2018-03-29 21:00:19
如果您使用提供免费计划,则无法在服务器上呈现pdf。这是因为服务在沙箱中运行,因此不能运行第三方可执行文件,比如node.exe。您需要将您的服务计划升级到“基本”或更高级别。
https://stackoverflow.com/questions/49561371
复制相似问题