Prathako
Prathako

Reputation: 91

how to parse a local copy of pdf files and search keyword occurrence using javascript?

I am working on a window application where I have to look for all pdf files, parse them and search a keyword occurrence in them with the help of javascript. I tried using pdf.js but found no solution for local files. It shows me following error; XMLHttpRequest cannot load file:///Hello.pdf. Cross origin requests are only supported for HTTP. (sample file name is Hello.pdf)

Upvotes: 0

Views: 991

Answers (2)

levi
levi

Reputation: 25121

The PDFJS.getDocument method accepts either a URL to a file, or an ArrayBuffer of the PDF file. So what you can do, is read the file into an ArrayBuffer (perhaps using FileReader.readAsArrayBuffer), and then pass the buffer to getDocument.

See here.

Upvotes: 1

Kwebble
Kwebble

Reputation: 2075

If you want to run it locally and it has to be JavaScript I would look for Node.js modules that can handle PDF's, like pdf2json.

Upvotes: 0

Related Questions