Created
January 15, 2018 14:00
-
-
Save njlr/e31909f683ac2a841a39d47ec99c87ee to your computer and use it in GitHub Desktop.
Example showing how to use Node.js, PDF.js and Superagent together
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
import _ from 'lodash'; | |
import superagent from 'superagent'; | |
import pdf from 'pdfjs-dist'; | |
const url = 'http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf'; | |
const main = async () => { | |
const response = await superagent.get(url).buffer(); | |
const data = response.body; | |
const doc = await pdf.getDocument({ data }); | |
for (const i of _.range(doc.numPages)) { | |
const page = await doc.getPage(i + 1); | |
const content = await page.getTextContent(); | |
for (const { str } of content.items) { | |
console.log(str); | |
} | |
} | |
}; | |
main().catch(error => console.error(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment