如何通过脚本在云打印机上从Google电子表格打印一张表

时间:2017-05-21 22:39:01

标签: google-app-engine google-cloud-print

我正在尝试创建自动系统,该系统将在表单提交时打印。 到目前为止,脚本从表单提交开始,并将所需信息放入单独的工作表中的打印模板,我想将此工作表发送到云打印机。 在这里OAuth2 with Google Cloud Print我找到了如何将作业从脚本发送到云打印机,但我遇到了两个问题:

  1. 它打印所有可用的工作表,但我只需要一个;
  2. 它在Letter / A4纸上打印,我想在A6上打印。
  3. 以下是打印功能的代码:

    function printGoogleDocument(docId) {  
      // For notes on ticket options see https://developers.google.com/cloud-print/docs/cdd?hl=en
      
      var ticket = {
        version: "1.0",
        print: {
          color: {
            type: "STANDARD_COLOR"
          },
          duplex: {
            type: "NO_DUPLEX"
          },
          media_size: {
             option: [
            {
              "name": "ISO_A6",
              "width_microns": 105000,
              "height_microns": 148000
            }
            ]
          },
        }
      };
       
      var payload = {
        "printerid" : "_my_printer_ID",
        "content"   : docId,
        "title"  : "Test",
        "contentType" : "google.spreadsheet", // allows you to print google docs
        "ticket"    : JSON.stringify(ticket),
      };
     
      var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', {
        method: "POST",
        payload: payload,
        headers: {
          Authorization: 'Bearer ' + getCloudPrintService().getAccessToken()
        },
        "muteHttpExceptions": true
      });
     
      // If successful, should show a job here: https://www.google.com/cloudprint/#jobs
    
      response = JSON.parse(response);
      if (response.success) {
        Logger.log("%s", response.message);
      } else {
        Logger.log("Error Code: %s %s", response.errorCode, response.message);
      }
      return response;
    }

0 个答案:

没有答案