将jpg批量转换为Google文档

将jpg批量转换为Google文档

本文介绍了将jpg批量转换为Google文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google云端硬盘中有一个要转换为Google文档的jpg文件夹.现在,我可以手动选择每个选项,并在上下文菜单在Google文档中打开"中进行选择.这将创建一个新文档,其图像位于页面顶部,OCR文本位于下方.我只想用我所有的图像来做.

I have a folder of jpgs in Google Drive that I would like to convert to Google Docs. Now I can select each one manually and in the context menu "Open in Google Docs" This creates a new document with the image at the top of the page and OCR text below. I just want to do this with all my images.

有一个脚本此处,它将gdoc转换为我应该能够适应我的情况的docx,但是我似乎无法使其工作.

There is a script here which converts gdoc to docx which I ought to be able to adapt for my case but I don't seem to be able to get it to work.

这是我改编的剧本:

function convertJPGtoGoogleDocs() {
  var srcfolderId = "~~~~~~~~~Sv4qZuPdJgvEq1A~~~~~~~~~"; // <--- Please input folder ID.
  var dstfolderId = srcfolderId; // <--- If you want to change the destination folder, please modify this.
  var files = DriveApp.getFolderById(srcfolderId).getFilesByType(MimeType.JPG);
  while (files.hasNext()) {
    var file = files.next();
    DriveApp.getFolderById(dstfolderId).createFile(
      UrlFetchApp.fetch(
        "https://docs.google.com/document/d/" + file.getId() + "/export?format=gdoc",
        {
          "headers" : {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()},
          "muteHttpExceptions" : true
        }
      ).getBlob().setName(file.getName() + ".docx")
    );
  }
}

任何人都可以帮忙吗?

谢谢.

推荐答案

  • 您要将文件夹中的Jpeg文件转换为Google文档.
  • 将Jpeg文件转换为Google文档时,您要使用OCR.
  • 如果我的理解是正确的,那么该修改如何?

    If my understanding is correct, how about this modification?

    • 在您修改的脚本中, MimeType.JPG 返回 undefined .因此, while 中的脚本不会运行.
      • 请使用 MimeType.JPEG .
      • In the script you modified, MimeType.JPG returns undefined. So the script in while is not run.
        • Please use MimeType.JPEG.

        如果您要修改此答案的脚本,如何进行如下修改?

        If you want to modify the script of this answer, how about modifying as follows?

        使用此脚本时,请在高级Google上启用Drive API服务.这样,可以在API控制台上自动启用API. Google Apps脚本项目的规范已于2019年4月8日更改.

        When you use this script, please enable Drive API at Advanced Google Services. By this, the API is automatically enabled at API console. The specification of Google Apps Script Project was Changed at April 8, 2019.

        function convertJPGtoGoogleDocs() {
          var srcfolderId = "~~~~~~~~~Sv4qZuPdJgvEq1A~~~~~~~~~"; // <--- Please input folder ID.
          var dstfolderId = srcfolderId; // <--- If you want to change the destination folder, please modify this.
          var files = DriveApp.getFolderById(srcfolderId).getFilesByType(MimeType.JPEG); // Modified
          while (files.hasNext()) {
            var file = files.next();
            Drive.Files.insert({title: file.getName(), parents: [{id: dstfolderId}]}, file.getBlob(), {ocr: true}); // Modified
          }
        }
        

        注意:

08-31 09:46