本文介绍了Node.js ENOENT阅读PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

这是我使用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,但是为什么错误是未处理的错误"事件.

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

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

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

推荐答案

您的服务器没有pdftotext命令,pdf-text-extract模块尝试将其作为子进程生成.该模块的自述文件包括链接,该链接介绍了如何在各种平台上安装该程序.

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.

这篇关于Node.js ENOENT阅读PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:01