pdfjs官网
http://mozilla.github.io/pdf.js/
Demo
识别的文本在控制台有输出,可打开控制台查看
主要代码
//用 promise 获取页面
PDFJS.getDocument(fileURL).then(function (pdf) {
});
// 获取i页的页面
pdf.getPage(i).then(function (page) {
// 识别pdf中文本
page.getTextContent().then(function(textContent) {
for(let j = 0; j < textContent.items.length; j++) {
// textContent.items[j].str为识别到的文本字符串
}
});
})