Skip to content

Instantly share code, notes, and snippets.

@njlr
Created January 15, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njlr/e31909f683ac2a841a39d47ec99c87ee to your computer and use it in GitHub Desktop.
Save njlr/e31909f683ac2a841a39d47ec99c87ee to your computer and use it in GitHub Desktop.
Example showing how to use Node.js, PDF.js and Superagent together
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