【发布时间】:2021-01-19 04:22:19
【问题描述】:
我正在尝试从 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)
})
但是当我运行它时,我得到以下错误:
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.'
关于如何进行此操作的任何想法?我要做的就是从它的 URL 中提取 pdf 的文本。我正在尝试使用 nodejs 来做这个服务器端。感谢您的意见!
【问题讨论】:
标签: javascript node.js pdf.js