Last active
February 15, 2023 18:51
-
-
Save SpeedZ/90f32625db385220a6e1844699e48ce4 to your computer and use it in GitHub Desktop.
OCR
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
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
เปิดใช้งาน Drive API ใน Resources -> Advance Google Service ด้วย