Last active
August 29, 2015 14:28
-
-
Save RichardLitt/87ff56363343bd4e745d to your computer and use it in GitHub Desktop.
Array iterators and async
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
| var readPDFText = function (documentObject, options, cb) { | |
| if (!documentObject) throw new Error('No pdf provided') | |
| // For each page | |
| async.map( | |
| pdfjs.getDocument(documentObject).then(function (pdf) { | |
| // Get all of the apges | |
| async.times(pdf.numPages, function (pageNum, callback) { | |
| pdf.getPage(pageNum + 1).then(function (page) { | |
| // Get all of the strings on the page | |
| page.getTextContent().then(function (textContent) { | |
| // Check for DOIS | |
| async.map(textContent.items, function (item, itemcb) { | |
| // TODO match[2] tracks .t001, .g001, etc. Capture these, they may be relevant | |
| // to research. | |
| var match = doiRegex.groups(item.str) | |
| if (match) { | |
| itemcb(null, match) | |
| // console.log('match', match) | |
| // callback(null, match[1]) | |
| // if (options.modules.altmetrics) { | |
| // altmetricsFromDoi(doi, cb) | |
| // } | |
| } else { | |
| itemcb(null) | |
| } | |
| }, function (err, result) { | |
| if (err) { | |
| callback(err) | |
| } | |
| callback(null, result) | |
| }) | |
| // cb('Failed to find a DOI.') | |
| }) | |
| }) | |
| }, function (err, results) { | |
| if (err) { | |
| cb('Error getting DOIs') | |
| } | |
| console.log('results', results) | |
| // cb(null, results) | |
| }) | |
| }) | |
| , function (arrayItem, mapIteratorCallback) { | |
| mapIteratorCallback('Hi mom!') | |
| }, function (err, finalResult) { | |
| if (err) { console.log('err', err)} | |
| console.log('hello') | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment