Skip to content

Instantly share code, notes, and snippets.

Last active Dec 26, 2015
What would you like to do?
def downloadPDF(url: String): Result[(File, String)] = {
loadPage(url) andThen
waitForSelector("div.textLayer") andThen
runJS("return extractPdfContent()") andThen {
Thread.sleep(2000) // give browser a chance
val extracted = runJS("return intBuf2hex(extractedPdf)") map (_.toString)
val pdf = extracted flatMap
(_.decodeHex #> File.createTempFile("download", ".pdf"))
val html = runJS("return _$('div.textLayer').innerHTML") map (_.toString)
pdf <*> html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment