0

Problem

I'm trying to extract the text out of pdfs, but I can't get pdf.js to work in gas.

Background

I have been using advanced drive services and OCR to upload pdfs to google drive and convert via OCR, and up until now that's been giving acceptable results, but now I'm getting some pdfs that are not OCRing correctly (not even close). However, if I pull these pdfs up in Chrome and select all, copy, all the text is there to be had, if I could only use pdf.js within gas.

Has anyone found a way to make these two work together?

What I've tried

  • I tried pasting pdf.js into a gs file, and it's so big, it breaks all debugging. I can no longer use the gas debugger if that 42 thousand line js file is in my project.

  • I tried using urlfetchapp.fetch with an external url, and I can get the javascript into a variable, but the debugger errors out on the eval statement trying to eval the javascript.

function loadJSFromServer() {
  var url = "https://raw.githubusercontent.com/brendandahl/pdf.js.utils/master/browser/pdf.js";
  var javascript = UrlFetchApp.fetch(url).getContentText();
  eval(javascript); // errors out here
}
  • I looked for a pdf library for gas that reads pdf text, but didn't find one. Maybe one is out there but there's no central library repo and googling was not successful.

  • I looked for a Google api to extract the text but didn't find one.

  • Chrome has a built in add on to display pdf as html (an html pdf viewer), but I don't know how to tap into that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.