PDF to Text in Your Browser: pdf-lib Can't Extract Text, but pdf.js Can
If you want the words out of a PDF without uploading the file anywhere, the answer is one function: page.getTextContent() from Mozilla's pdf.js. And if you already build PDF tools with pdf-lib — the library from my merging post — here is the thing nobody tells you until you waste an afternoon on it: pdf-lib cannot extract text at all. Both "do PDFs in JavaScript", but they do opposite halves of…
Both pdf.js and pdf-lib are JavaScript libraries that handle PDFs in a browser, but they perform opposite functions. pdf-lib, a document builder, cannot extract text from PDFs, while pdf.js, a document reader, can. pdf-lib contains no methods for text extraction, while pdf.js parses the PDF's text fragments stored as positioned strings and returns them in reading order. However, pdf-lib is still the wrong library for text extraction in a browser environment.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to