在谷歌应用脚​​本上使用谷歌文档的OCR功能

时间:2014-08-21 16:54:21

标签: google-apps-script google-apps google-drive-api

我如何在谷歌应用程序脚本中使用它?我想从Gmail上传附件。此外,我想使用谷歌文档的ocr功能,因为所有的附件将是图像。

function uploadFile() {
  var image = UrlFetchApp.fetch('http://goo.gl/nd7zjB').getBlob();
  var file = {
    title: 'google_logo.png',
    mimeType: 'image/png'
  };
  file = Drive.Files.insert(file, image);
  Logger.log('ID: %s, File size (bytes): %s', file.id, file.fileSize);
}

1 个答案:

答案 0 :(得分:0)

将您的文件更改为Drive.Files.insert(file,image,{ocr:true});

请注意,当我使用您提供的图像时,OCR对我不起作用。使用this image进行测试,并且应该可以正常使用。

function uploadFile() {
  var image = UrlFetchApp.fetch('https://i.imgur.com/ahDXEPo.png').getBlob();
  var file = {
    title: 'imagehastext.png',
    mimeType: 'image/png'
  };
  file = Drive.Files.insert(file, image, {ocr: true});
  Logger.log('ID: %s, File size (bytes): %s', file.id, file.fileSize);
}

以下是如何获取电子邮件附件的粗略示例。

GmailApp.getInboxThreads()[0].getMessages()[0].getAttachments();

And some documentation on how to save files to Google Drive

相关问题