将PDF转换为Google文档

4
我成功地运行了一个脚本,该脚本可以自动将PDF转换为Google Doc格式。但我们遇到的问题是,PDF中也有图片。当我们将PDF转换为Google Doc时,Google Doc没有图片,只有文本。我认为这是由于OCR造成的。是否可能让脚本自动将PDF中的图像转换为Google Docs呢?
以下是相关脚本:
GmailToDrive('0BxwJdbZfrRZQUmhldGQ0b3FDTjA', '"Test Email"');

function GmailToDrive(folderID, gmailSubject){
   var threads = GmailApp.search('subject: ' + gmailSubject + ' -label: Imported'); // performs Gmail query for email threads

   for (var i in threads){
  var messages = threads[i].getMessages(); // finds all messages of threads returned by the query

  for(var j in messages){
     var attachments = messages[j].getAttachments(); // finds all attachments of found messages
     var timestamp = messages[j].getDate(); // receives timestamp of each found message
     var date = Utilities.formatDate(timestamp, "MST", "yyyy-MM-dd"); // rearranges the returned timestamp

     for(var k in attachments){
        var fileType = attachments[k].getContentType();
        Logger.log(fileType);
        if (fileType = 'application/pdf') {     // if the application is a pdf then it will convert to a google doc.
         var fileBlob = attachments[k].copyBlob().setContentType('application/pdf');
         var resource = {
           title: fileBlob.getName(),
           mimeType: fileBlob.getContentType()
         }; 
         var options = {
           ocr: true 
         };
         var docFile = Drive.Files.insert(resource, fileBlob, options);  
        }
      }
    }
  }
}
1个回答

1
< p > ocr 选项旨在从图像和 PDF 文档中读取字符。这不会包括上传结果中的图像。

请查看 convert 选项。

API 文档 提供了一个测试,您可以在右侧快速检查每个参数。


我已经注释掉了 ocr 选项并将 convert 选项设置为 true。转换后,我们仍然可以在 Google 文档中获得文本,但是图像仍然无法找到。 - CoreyG

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接