【问题标题】:Node.js ENOENT Reading PDF fileNode.js ENOENT 读取 PDF 文件
【发布时间】:2016-12-12 12:57:48
【问题描述】:

我需要阅读 pdf 文件,我使用 pdf-text-extract。它在我的本地主机上完美运行。但是当我尝试在服务器上运行程序时,我得到了以下错误

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)

这是我如何使用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);
});

如你所见,我添加了catch,但是为什么错误是Unhandled 'error' 事件。

我还使用fs.readdirSync 检查了该文件是否存在。是什么导致了错误,我该如何解决?

【问题讨论】:

    标签: node.js pdf enoent


    【解决方案1】:

    您的服务器没有pdftotext 命令,pdf-text-extract 模块试图将其作为子进程生成。该模块的自述文件包括a link 以了解如何为各种平台安装程序。

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 2016-06-26
      • 2013-08-25
      • 2012-05-09
      • 2010-11-03
      • 1970-01-01
      相关资源
      最近更新 更多