在Google Apps脚本上使用Google文档的OCR功能 [英] Use OCR function of google docs on google apps script

查看:125
本文介绍了在Google Apps脚本上使用Google文档的OCR功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Google Apps脚本上使用它?我想从gmail上传附件.另外,由于所有附件都是图像,因此我想使用Google文档的ocr功能.

How can i use this on the google apps script? i want to upload attachments from gmail. Also, i want to use the ocr function of google docs since all of the attatchments will be images.

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);
}

推荐答案

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

Change your file varaible to Drive.Files.insert(file, image, {ocr: true});

请注意,当我使用您提供的图像时,OCR对我不起作用.使用此图像进行测试,它应该可以正常工作.

Please note, OCR didn't work for me when I used the image you supplied. Test it out with this image and should work fine for you.

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);
}

这是有关如何获取电子邮件附件的粗略示例.

Here's a rough example of how to get an email attachment.

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

以及一些有关如何将文件保存到Google云端硬盘的文档

这篇关于在Google Apps脚本上使用Google文档的OCR功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆