【问题标题】:Converting PDF to Google Docs将 PDF 转换为 Google 文档
【发布时间】:2018-01-07 16:14:24
【问题描述】:

我设法让一个脚本运行,该脚本自动将 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);  
        }
      }
    }
  }
}

【问题讨论】:

    标签: pdf google-apps-script google-drive-api gmail google-docs


    【解决方案1】:

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

    请查看convert 选项。

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

    【讨论】:

    • 我已经注释掉了ocr 选项并将convert 选项设置为true。转换后,我们仍然可以在 Google Doc 中获取文本,但是仍然找不到图像。
    猜你喜欢
    • 2019-07-04
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多