正如标题所说,我正在尝试使用由Mozilla维护的PDF.js从PDF中提取文本。我知道前面关于stackoverflow的问题,但我不知道从哪里开始。
我试着跟着这个
article
这件事我需要帮助。
所以我把下面的所有代码都放在index.html文件中,对吗?
PDF.js
var urlPDF = '/path/to/example.pdf';
PDFJS.workerSrc = '/path/to/pdf.worker.js';
PDFJS.getDocument(urlPDF).then(function (pdf) {
var pdfDocument = pdf;
var pagesPromises = [];
for (var i = 0; i < pdf.pdfInfo.numPages; i++) {
// Required to prevent that i is always the total of pages
(function (pageNumber) {
pagesPromises.push(getPageText(pageNumber, pdfDocument));
})(i + 1);
}
Promise.all(pagesPromises).then(function (pagesText) {
// Display text of all the pages in the console
console.log(pagesText);
});
}, function (reason) {
<