我想从一个pdf的URL提取出其文本内容。在pdf.js网站上的示例中,我了解到如何在客户端渲染pdf,但在服务器端运行时遇到了问题。
我使用 npm i pdfjs-dist
下载了该包。
我尝试了下面的代码作为一个简单的示例来加载pdf:
var url = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf';
var pdfjsLib = require("pdfjs-dist")
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function (pdf) {
console.log(pdf);
}).catch(function (error){
console.log(error)
})
但是当我运行这个程序时,我收到了以下错误:
message: 'The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. `ReadableStream` and/or `Promise.allSettled`); please use an ES5-compatible build instead.',
name: 'UnknownErrorException',
details: 'Error: The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. `ReadableStream` and/or `Promise.allSettled`); please use an ES5-compatible build instead.'
有没有关于如何做这件事的想法?我只是试图从pdf的URL中提取文本。而且我正在尝试使用nodejs在服务器端进行此操作。感谢任何意见!