Click here to Skip to main content
14,880,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I'have a pdf document saved in my c:\\ drive, I want to read the content of that pdf using Javascript, but I have not found any idea how to read a PDF file.

Please any direction is greatly appreciated.

What I have tried:

I have tried the following code, but the words are ineligible.

This is what shows up up in my console.


3 0 obj
<</Length 1438/Filter/FlateDecode>>stream

var filePath="C:/Users/johndoe/Desktop/sample_doc.pdf";
Updated 17-Apr-21 2:44am

1 solution

GitHub - mozilla/pdf.js: PDF Reader in JavaScript[^]

NB: If your code is running in a browser, you will not be able to read files from your local drive.
ekonapikin1990 16-Apr-21 7:01am
Sir thank you, but I am able to read the file with my code, but is not just readable, do you know why?
Richard Deeming 16-Apr-21 7:08am
So you can read the file, but you can't read the file. Which is it?

We can't help you if you don't explain the problem.
ekonapikin1990 16-Apr-21 7:13am
I can read the file successfully, but the texts is not readable, if do thesame for text file my code reads everything as is,but for pdf file I get bunch of weird texts and not the same LIKE WHEN i READ A TEXT FILE.
Richard Deeming 16-Apr-21 7:15am
That would be because a PDF file is NOT a text file. You cannot read it as a text file and expect to get any meaningful results from it.

Use the library I linked to, and you should be able to extract the text from a PDF file - so long as it actually is text, and isn't part of an image.
ekonapikin1990 16-Apr-21 7:17am
OK Sir,thank you
Dave Kreskowiak 16-Apr-21 12:23pm
IIRC, you can read a local file if the javascript was loaded from a local location. If the script is loaded from a server, you lose the ability to directly access the local file system.
ekonapikin1990 16-Apr-21 13:33pm
I am using a testing tool ,that has all dependencies and packages to run JS code on the web.(Chrome browser to be exact).
The tool is web based tool so I am trying to go to file location and read a pdf file's content and have it printed on my console-

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900