Home > OS >  How can I read a pdf file with express and node
How can I read a pdf file with express and node

Time:10-28

I'm trying to read a pdf... and my idea is to convert it to a text. I have read the pdf-parser documentation and I don't understand why it is giving me this error, has anyone ever used pdf-parser? Has anyone had this error? It would be very helpful, I have never worked with it and the videos I watched use it very easily, but it breaks the code for me.

const url = require("./prueba.pdf");
const pdf = require("pdf-parse");
const fs = require("fs");

const pdffile = fs.readFileSync(url);
console.log(pdffile);
pdf(pdffile).then(function (data) {
console.log(data.text);
});

enter image description here

CodePudding user response:

The path ./prueba.pdf is not correct, unless you run the node command from the ..\api\src\routes subdirectory, which I doubt.

Unlike paths in a require command, paths in an fs.readFileSync command are interpreted relative to the directory where you started the node process.

  • Related