Click here to Skip to main content
15,498,859 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.

});

%PDF-1.4
%����
3 0 obj
<</Length 1438/Filter/FlateDecode>>stream
x��Y�r�6��+�Ɍ3S�xXڭ�h���IM���STB�n>�_�/p~!�^<H��N�xti���}��T�,��&k��g���xU|*҂�Gk�JPSH#13�װ�).�?�����`�������/��



JavaScript
fs=require('fs');
readline=require('readline');
var filePath="C:/Users/johndoe/Desktop/sample_doc.pdf";
require('fs').readFileSync(filePath,'utf-8').split(/\r?\n).foreach(function(line){
console.log(line);
});
Posted
Updated 2-Sep-21 23:01pm
v3

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.
 
Share this answer
 
Comments
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     CRLF
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     CRLF
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
Hello, my need is to read only locally stored pdf. Where can I find a javascript library to accomplish this ?
Many thanks
 
Share this answer
 
Comments
mareos 3-Sep-21 4:55am    
https://github.com/mozilla/pdf.js
Richard Deeming 3-Sep-21 5:04am    
Your question is not a "solution" to someone else's question.
Member 15345637 3-Sep-21 10:00am    
Sorry, I'm afraid I don't understand.
Richard Deeming 3-Sep-21 10:03am     CRLF
What precisely do you not understand? You have posted a QUESTION in the "Add your SOLUTION here" box, claiming that it is a SOLUTION to this question. Your QUESTION is not a SOLUTION to someone else's question.
Member 15345637 3-Sep-21 10:59am    
I see, sorry for that

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