Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading PDF file using javascript

I'm currently developing an application that would Copy/Transfer a sentence/paragraph from a PDF file to my program. I'm using Javascript to develop my program but I have not found any idea how to read a PDF file.

I want to know how to Copy/Transfer a sentence/paragraph from a PDF file to my program?

Thanks.

like image 803
Christian Eric Paran Avatar asked Aug 22 '12 03:08

Christian Eric Paran


People also ask

Can I use JavaScript in PDF?

I have a few questions to whoever has any familiarity with JavaScript inside a PDF document. NitroPDF and Adobe Acrobat definitely support JavaScript in PDF files.

How do I read text in a PDF?

Open Reader and navigate to the document page you want to have read aloud. From the top left menu, click View, then Read Out Loud. You can choose to have the whole document read aloud or just the page you're on. Select either Read to End of Document or Read This Page Only, respectively.

Is PDF JS free to use?

PDF. js is a good free option if you're willing to invest time into implementing a UI for it. The project comes with some examples and API docs.


2 Answers

I know that the question is old, but if you find PDF.js too complex for the job, npm install pdfreader. (I wrote that module)

It would take 5 lines of code to extract text from your PDF file:

var PdfReader = require("pdfreader").PdfReader;
new PdfReader().parseFileItems("sample.pdf", function(err, item){
  if (item && item.text)
    console.log(item.text);
});
like image 176
Adrien Joly Avatar answered Sep 20 '22 12:09

Adrien Joly


Check out PDF.js, it's a commonly used JavaScript library that contains a lot of methods for PDF manipulation.

Check out this answer to see a demonstration of how to extract text using pdf.js.

like image 36
theonlygusti Avatar answered Sep 22 '22 12:09

theonlygusti