Node.js – How to read the content of a .pdf file using nodejs

node.js, pdf

I have a scenario to automate the PDF contents. How to retrieve the content of the PDF file in nodejs.

I am completely blocked for this. Although there are few posts on pdf2jsona and jsonreader but those are not working for me. Any help will be appreciated for the same.

var pdfParser = new PDFParser();fs.readFile(pdfFilePath, function(err, pdfBuffer) {    pdfParser.parseBuffer(pdfBuffer);}, function(pdfBuffer){    pdfParser.parseBuffer(pdfBuffer);})

Error: Invalid parameter array, need either .data or .url
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)

Best Solution

 var fs = require("fs"); var PdfReader = require('pdfreader').PdfReader;  fs.readFile("E://file streaming in node js//demo//read.pdf", (err, pdfBuffer) => {    // pdfBuffer contains the file content    new PdfReader().parseBuffer(pdfBuffer, function(err, item){       if (err)           callback(err);        else if (!item)            callback();         else if (item.text)            console.log(item.text);          });       });