Skip to content

Instantly share code, notes, and snippets.

@tagplus5
Created December 18, 2015 18:02
Show Gist options
  • Save tagplus5/07dde5ca61fe8f42045d to your computer and use it in GitHub Desktop.
Save tagplus5/07dde5ca61fe8f42045d to your computer and use it in GitHub Desktop.
google apps script image to text ocr
function doGet(request) {
if (request.parameters.url != undefined && request.parameters.url != "") {
var imageBlob = UrlFetchApp.fetch(request.parameters.url).getBlob();
var resource = {
title: imageBlob.getName(),
mimeType: imageBlob.getContentType()
};
var options = {
ocr: true
};
var docFile = Drive.Files.insert(resource, imageBlob, options);
var doc = DocumentApp.openById(docFile.id);
var text = doc.getBody().getText().replace("\n", "");
Drive.Files.remove(docFile.id);
return ContentService.createTextOutput(text);
}
else {
return ContentService.createTextOutput("request error");
}
}
@glebret
Copy link

glebret commented Sep 21, 2018

The 'Drive' Classe in Drive.Files doesn't exsit anymore (replace by DriveApp Class).

@bot-jonas
Copy link

@askfriends
Copy link

how to use this script?

@amar3219
Copy link

Good its working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment