我正在尝试从 pdf 的 url 中提取 pdf 的文本。按照 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)
})
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到以下错误:
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. …Run Code Online (Sandbox Code Playgroud)