pdftotextjs provides access to pdftotext
via shell in nodejs. You'll
need pdftotext
which comes with poppler-utils
.
- Ubuntu/Debian
sudo apt-get install poppler-utils
. - MacOSX
sudo port install poppler
orbrew install xpdf
. - Windows
download and install
Xpdf.
via npm:
$ npm install pdftotextjs
const pdftotext = require('pdftotextjs');
const pdf = new pdftotext('test/pdfs/sample.pdf');
// Convert first page only
// These options will be passed to pdftotext
// You may use any valid option
pdf.add_options(['-f 1', '-l 1']);
pdf.getText()
.then(function(result) {
console.log(result);
})
.catch(function (err) {
console.error(err);
});
const pdftotext = require('pdftotextjs');
const pdf = new pdftotext('test/pdfs/sample.pdf');
const data = pdf.getTextSync(); // returns buffer
console.log(data.toString('utf8'));
$ npm test