1

I am using NodeServices to create PDF in AspNetCore app. App works fine on local machine but when deployed on production, on calling the pdf function, I get the following error:

Error: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT at _errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Error during rendering report: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT

Error: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT at _errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

I verified that all the files are at their right place. node_modules are present in the deployment.

Node Version on Azure: 8.9.4

Code to generate 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);
});
};
Ajay Kumar
  • 1,154
  • 2
  • 10
  • 24
  • How are you importing the node module? – Greg Mar 29 '18 at 17:07
  • I followed exact procedure as mentioned here: https://code.msdn.microsoft.com/How-to-export-HTML-to-PDF-c5afd0ce `var jsreport = require('jsreport-core')(); ` – Ajay Kumar Mar 30 '18 at 05:30

2 Answers2

0

If you use Azure App Service with a free plan, you cannot render pdf on the server. This is because the service runs in a sandbox and thus cannot run third-party executables, like node.exe. You need to upgrade your service's plan to 'Basic' or higher.

0

The issue was with the installation of Node packages. I was using Hosted Linux on Azure to build the solution. Switched to Hosted VS2017 build and everything is working smoothly. https://github.com/pofider/phantom-html-to-pdf/issues/68

Ajay Kumar
  • 1,154
  • 2
  • 10
  • 24
  • there is a permission issue, when installing phantom.js. you could like to try "sudo npm install --unsafe-perm". – KennetsuR Oct 22 '21 at 08:57