我正在尝试使用https://www.npmjs.com/package/pdfjs-dist-for-node来搜索pdf的文本。Pdf.js(用于节点)不呈现pdf的全部内容
我的代码如下所示:
gettext: function(){
var data = '../static/example.pdf';
return pdfjs.getDocument(data).then(function(pdf) {
var pages = [];
for (var i = 0; i < pdf.numPages; i++) {
pages.push(i);
}
return Promise.all(pages.map(function(pageNumber) {
return pdf.getPage(pageNumber + 1).then(function(page) {
return page.getTextContent().then(function(textContent) {
return textContent.items.map(function(item) {
return item.str;
}).join(' ');
});
});
})).then(function(pages) {
return pages.join("\r\n")
});
}).then(function(pages){
console.log(pages)
});
}
这似乎是工作,但它跳过的文字部分。具体来说,它会跳过我无法用原始pdf文档中的鼠标突出显示的内容。有没有办法让pdf.js获取这些数据?
请参阅https://github.com/mozilla/pdfjs-dist进行官方回购和示例https://github.com/mozilla/pdf.js/blob/master/examples/node/getinfo.js – async5
The找不到pdfjs-dist-for-node的源代码来告知PDF.js分叉有多大,或者它是否是恶意分支。我会建议停止使用它,并开始使用官方叉子。 – async5
@ async5感谢您的支持,我切换到pdfjs-dist。 –