Node.js ENOENT Reading PDF file

人走茶凉 提交于 2020-01-05 04:59:07

问题


I need to read pdf file and I use pdf-text-extract. It works perfectly on my localhost. But when I tried to run the program on server, I got the following error

spawn called
{ '0': 'pdftotext',
  '1': 
   [ '-layout',
     '-enc',
     'UTF-8',
     '/tmp/the_file_name.pdf',
     '-' ],
  '2': { encoding: 'UTF-8', layout: 'layout', splitPages: true } }

events.js:72
        throw er; // Unhandled 'error' event

Error: spawn ENOENT
  at errnoException (child_process.js:1011:11)
  at Process.ChildProcess._handle.onexit (child_process.js:802:34)

Here is how I use pdf-text-extract

var extract = require('pdf-text-extract');

.....

.then (function () {
  console.log(fs.readdirSync('/tmp'));
  var extractAsync = Promise.promisify(extract);
  return extractAsync(filePath);
})
.catch (function (err) {
  console.log(err);
});

As you can see, I have added catch, but why the error is Unhandled 'error' event.

I have also checked that the file is exist using fs.readdirSync. What cause the error and how can I fix it?


回答1:


Your server does not have the pdftotext command, which the pdf-text-extract module tries to spawn as a child process. The readme for the module includes a link to how to install the program for various platforms.



来源:https://stackoverflow.com/questions/38800600/node-js-enoent-reading-pdf-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!