18

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.

1

2 Answers 2

18

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);
});
Sign up to request clarification or add additional context in comments.

4 Comments

'It does not work from a web browser.' Guessing this means I couldn't use browserify with it?
I don't know, @static_null. Let us know how it goes if you give it a try!
@AdrienJoly hi do you know where/how I can get the compiled version of pdfreader module? I'm hoping to get one .js file so I could use it as a library. Thank you!
@Daj I am not distributing any bundled version of pdfreader. Feel free to use the bundler of your choice (e.g. webpack or other) to achieve that.
8

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.