how to correctly extract text from a pdf using pdf.js
I'm new to ES6 and Promise. I'm trying pdf.js to extract texts from all pages of a pdf file into a string array. And when extraction is done, I want to parse the array somehow. Say pdf file(passed via typedarray correctly) has 4 pages and my code is: let str = []; PDFJS.getDocument(typedarray).then(function(pdf) { for(let i = 1; i <= pdf.numPages; i++) { pdf.getPage(i).then(function(page) { page.getTextContent().then(function(textContent) { for(let j = 0; j < textContent.items.length; j++) { str.push(textContent.items[j].str); } parse(str); }); }); } }); It manages to work, but, of course, the