簡體   English   中英

Node.js ENOENT閱讀PDF文件

[英]Node.js ENOENT Reading PDF file

我需要閱讀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檢查了該文件是否存在。 是什么導致錯誤,我該如何解決?

您的服務器沒有pdftotext命令, pdf-text-extract模塊嘗試將其生成為子進程。 該模塊的自述文件包含指向如何在各種平台上安裝程序的鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM