Created
April 17, 2017 15:40
-
-
Save mukulmishra18/6898c7c7c4676c0e6ad6ab139a84665e to your computer and use it in GitHub Desktop.
getTextContent function of PDF.js with sendWithStream
This file contains 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
getTextContent: function PDFPageProxy_getTextContent(params) { | |
var readableStream = this.transport.messageHandler.sendWithStream('GetTextContent', { | |
pageIndex: this.pageNumber - 1, | |
normalizeWhitespace: (params && params.normalizeWhitespace === true ? | |
true : /* Default */ false), | |
combineTextItems: (params && params.disableCombineTextItems === true ? | |
false : /* Default */ true), | |
}); | |
return new Promise(function (resolve, reject) { | |
readAllChunks(readableStream); | |
function readAllChunks (readableStream) { | |
var reader = readableStream.getReader(); | |
var textContent = { | |
items: [], | |
styles: {} | |
}; | |
pump(); | |
function pump () { | |
reader.read().then(function (result) { | |
if (result.done) { | |
resolve(textContent); | |
} | |
if (typeof result.value[0] == 'string') { | |
textContent.styles[result.value[0]] = result.value[1]; | |
} else { | |
textContent.items.push(result.value[0]); | |
if (result.value[1]) { | |
textContent.items.push(result.value[1]); | |
} | |
} | |
pump(); | |
}, function (error) { | |
reject(error); | |
}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment