Created
April 16, 2020 00:42
-
-
Save jrmmendes/5e2c00ca165a083b1e4028eda9160e5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { PdfReader } = require('pdfreader'); | |
const reader = new PdfReader(); | |
const makeLines = (rows) => { | |
Object.keys(rows) | |
.sort((y1, y2) => parseFloat(y1) - parseFloat(y2)) | |
.forEach(y => text += `${(rows[y] || []).join('')}\n`); | |
}; | |
const readFromPdf = () => new Promise((resolve, reject) => { | |
let text = ''; | |
reader.parseFileItems('test.pdf', (err, item) => { | |
if (item !== undefined) { | |
if (item.page) { | |
text += '\n'; | |
} else { | |
text += item.text; | |
} | |
} | |
if (err) throw reject(err); | |
}); | |
resolve(text); | |
}); | |
readFromPdf().then((text) => console.log(text)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment